WIP - [artiq] More test

This commit is contained in:
David Mak 2024-08-15 11:48:44 +08:00
parent 57bf18dffc
commit f09eb1bd98
1 changed files with 64 additions and 31 deletions

View File

@ -34,6 +34,7 @@ use crate::{symbol_resolver::InnerResolver, timeline::TimeFns};
use itertools::Itertools; use itertools::Itertools;
use nac3core::codegen::classes::{ProxyType, ProxyValue, TypedArrayLikeMutator}; use nac3core::codegen::classes::{ProxyType, ProxyValue, TypedArrayLikeMutator};
use nac3core::codegen::llvm_intrinsics::call_memset;
use std::{ use std::{
collections::{hash_map::DefaultHasher, HashMap}, collections::{hash_map::DefaultHasher, HashMap},
hash::{Hash, Hasher}, hash::{Hash, Hasher},
@ -41,7 +42,6 @@ use std::{
mem, mem,
sync::Arc, sync::Arc,
}; };
use nac3core::codegen::llvm_intrinsics::call_memset;
/// The parallelism mode within a block. /// The parallelism mode within a block.
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq)]
@ -603,11 +603,7 @@ fn format_rpc_ret<'ctx>(
.unwrap(); .unwrap();
let llvm_elem_sizeof = ctx let llvm_elem_sizeof = ctx
.builder .builder
.build_int_truncate_or_bit_cast( .build_int_truncate_or_bit_cast(llvm_elem_ty.size_of().unwrap(), llvm_usize, "")
llvm_elem_ty.size_of().unwrap(),
llvm_usize,
"",
)
.unwrap(); .unwrap();
let dims_buf_sz = let dims_buf_sz =
@ -618,8 +614,18 @@ fn format_rpc_ret<'ctx>(
let buffer = let buffer =
ctx.builder.build_array_alloca(llvm_pi8, buffer_size, "rpc.buffer").unwrap(); ctx.builder.build_array_alloca(llvm_pi8, buffer_size, "rpc.buffer").unwrap();
let buffer = ctx.builder.build_bitcast(buffer, llvm_pi8, "").map(BasicValueEnum::into_pointer_value).unwrap(); let buffer = ctx
let buffer = ArraySliceValue::from_ptr_val(buffer, ctx.builder.build_left_shift(buffer_size, llvm_usize.const_int(2, false), "").unwrap(), Some("rpc.buffer.ptr")); .builder
.build_bitcast(buffer, llvm_pi8, "")
.map(BasicValueEnum::into_pointer_value)
.unwrap();
let buffer = ArraySliceValue::from_ptr_val(
buffer,
ctx.builder
.build_left_shift(buffer_size, llvm_usize.const_int(2, false), "")
.unwrap(),
Some("rpc.buffer.ptr"),
);
let i_addr = ctx.builder.build_alloca(llvm_usize, "i.addr").unwrap(); let i_addr = ctx.builder.build_alloca(llvm_usize, "i.addr").unwrap();
ctx.builder.build_store(i_addr, llvm_usize.const_zero()).unwrap(); ctx.builder.build_store(i_addr, llvm_usize.const_zero()).unwrap();
@ -675,7 +681,12 @@ fn format_rpc_ret<'ctx>(
// ndarray.store_data(ctx, data_ptr); // ndarray.store_data(ctx, data_ptr);
let pbuffer_dims_begin = unsafe { let pbuffer_dims_begin = unsafe {
buffer.ptr_offset_unchecked(ctx, generator, &llvm_pdata_sizeof, None) buffer.ptr_offset_unchecked(
ctx,
generator,
&llvm_pdata_sizeof,
None,
)
}; };
call_memcpy_generic( call_memcpy_generic(
ctx, ctx,
@ -685,39 +696,57 @@ fn format_rpc_ret<'ctx>(
llvm_i1.const_zero(), llvm_i1.const_zero(),
); );
ndarray.create_data(ctx, llvm_elem_ty, call_ndarray_calc_size(generator, ctx, &ndarray.dim_sizes(), (None, None))); ndarray.create_data(
ctx,
llvm_elem_ty,
call_ndarray_calc_size(
generator,
ctx,
&ndarray.dim_sizes(),
(None, None),
),
);
Ok(()) Ok(())
}, },
|generator, ctx| { |generator, ctx| {
let cpy_size = ctx.builder.build_int_mul( let cpy_size = ctx
call_ndarray_calc_size(generator, ctx, &ndarray.dim_sizes(), (None, None)), .builder
.build_int_mul(
call_ndarray_calc_size(
generator,
ctx,
&ndarray.dim_sizes(),
(None, None),
),
llvm_elem_sizeof, llvm_elem_sizeof,
"", "",
).unwrap(); )
.unwrap();
call_memset( // call_memset(
ctx,
ctx.builder.build_bitcast(
ndarray.data().base_ptr(ctx, generator),
llvm_pi8,
"",
).map(BasicValueEnum::into_pointer_value).unwrap(),
llvm_i8.const_zero(),
cpy_size,
llvm_i1.const_zero(),
);
// call_memcpy_generic(
// ctx, // ctx,
// ctx.builder.build_bitcast(
// ndarray.data().base_ptr(ctx, generator), // ndarray.data().base_ptr(ctx, generator),
// buffer.base_ptr(ctx, generator), // llvm_pi8,
// "",
// ).map(BasicValueEnum::into_pointer_value).unwrap(),
// llvm_i8.const_zero(),
// cpy_size, // cpy_size,
// llvm_i1.const_zero(), // llvm_i1.const_zero(),
// ); // );
call_memcpy_generic(
ctx,
ndarray.data().base_ptr(ctx, generator),
buffer.base_ptr(ctx, generator),
cpy_size,
llvm_i1.const_zero(),
);
Ok(()) Ok(())
}, },
).unwrap(); )
.unwrap();
Ok(()) Ok(())
}, },
@ -735,7 +764,11 @@ fn format_rpc_ret<'ctx>(
let alloc_ptr = let alloc_ptr =
ctx.builder.build_array_alloca(llvm_pi8, alloc_size, "rpc.alloc").unwrap(); ctx.builder.build_array_alloca(llvm_pi8, alloc_size, "rpc.alloc").unwrap();
let alloc_ptr = ctx.builder.build_bitcast(alloc_ptr, llvm_pi8, "").map(BasicValueEnum::into_pointer_value).unwrap(); let alloc_ptr = ctx
.builder
.build_bitcast(alloc_ptr, llvm_pi8, "")
.map(BasicValueEnum::into_pointer_value)
.unwrap();
phi.add_incoming(&[(&alloc_ptr, alloc_bb)]); phi.add_incoming(&[(&alloc_ptr, alloc_bb)]);
let i = let i =
ctx.builder.build_load(i_addr, "i").map(BasicValueEnum::into_int_value).unwrap(); ctx.builder.build_load(i_addr, "i").map(BasicValueEnum::into_int_value).unwrap();