WIP - [artiq] Test

This commit is contained in:
David Mak 2024-08-15 05:28:12 +08:00
parent 043f8869d5
commit 160f5a6c58
1 changed files with 45 additions and 44 deletions

View File

@ -587,6 +587,7 @@ fn format_rpc_ret<'ctx>(
ndarray.store_ndims(ctx, generator, llvm_usize.const_int(ndims, false));
ndarray.create_dim_sizes(ctx, llvm_usize, ndarray.load_ndims(ctx));
// TODO: Add alignment
let llvm_usize_sizeof = ctx
.builder
.build_int_truncate_or_bit_cast(llvm_ret_ty.size_type().size_of(), llvm_usize, "")
@ -609,7 +610,7 @@ fn format_rpc_ret<'ctx>(
let buffer =
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 = ArraySliceValue::from_ptr_val(buffer, buffer_size, Some("rpc.buffer.ptr"));
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();
ctx.builder.build_unconditional_branch(head_bb).unwrap();
@ -639,34 +640,34 @@ fn format_rpc_ret<'ctx>(
.unwrap())
},
|generator, ctx| {
// call_memcpy_generic(
// ctx,
// ndarray.ptr_to_data(ctx),
// buffer.base_ptr(ctx, generator),
// llvm_pdata_sizeof,
// llvm_i1.const_zero(),
// );
// let pbuffer_dims_begin = unsafe {
// buffer.ptr_offset_unchecked(ctx, generator, &llvm_pdata_sizeof, None)
// };
// call_memcpy_generic(
// ctx,
// ndarray.dim_sizes().base_ptr(ctx, generator),
// pbuffer_dims_begin,
// dims_buf_sz,
// llvm_i1.const_zero(),
// );
// This works (with uninitialized data)
unsafe {
ndarray.dim_sizes().set_typed_unchecked(
call_memcpy_generic(
ctx,
generator,
&llvm_usize.const_zero(),
llvm_usize.const_int(2, false),
ndarray.ptr_to_data(ctx),
buffer.base_ptr(ctx, generator),
llvm_pdata_sizeof,
llvm_i1.const_zero(),
);
}
let pbuffer_dims_begin = unsafe {
buffer.ptr_offset_unchecked(ctx, generator, &llvm_pdata_sizeof, None)
};
call_memcpy_generic(
ctx,
ndarray.dim_sizes().base_ptr(ctx, generator),
pbuffer_dims_begin,
dims_buf_sz,
llvm_i1.const_zero(),
);
// // This works (with uninitialized data)
// unsafe {
// ndarray.dim_sizes().set_typed_unchecked(
// ctx,
// generator,
// &llvm_usize.const_zero(),
// llvm_usize.const_int(2, false),
// );
// }
// let pbuffer_dims_begin = unsafe {
// buffer.ptr_offset_unchecked(ctx, generator, &llvm_usize.const_int(4, false), None)
@ -681,13 +682,13 @@ fn format_rpc_ret<'ctx>(
// dims=(10): bufsize = 32
let sz = call_ndarray_calc_size(generator, ctx, &ndarray.dim_sizes(), (None, None));
ndarray.create_data(
ctx,
llvm_elem_ty,
sz,
);
// let sz = call_ndarray_calc_size(generator, ctx, &ndarray.dim_sizes(), (None, None));
//
// ndarray.create_data(
// ctx,
// llvm_elem_ty,
// sz,
// );
// let ndims_addr = ndarray.ptr_to_ndims(ctx);
// let ndarray_pdata = ndarray.data().base_ptr(ctx, generator);
@ -737,16 +738,16 @@ fn format_rpc_ret<'ctx>(
// llvm_i1.const_zero(),
// );
let ndarray_pdata = unsafe {
ndarray.data().ptr_offset_unchecked(ctx, generator, &llvm_usize.const_int(0, false), None)
};
call_memcpy_generic(
ctx,
ndarray_pdata,
buffer.base_ptr(ctx, generator),
buffer_size,
llvm_i1.const_zero()
);
// let ndarray_pdata = unsafe {
// ndarray.data().ptr_offset_unchecked(ctx, generator, &llvm_usize.const_int(0, false), None)
// };
// call_memcpy_generic(
// ctx,
// ndarray_pdata,
// buffer.base_ptr(ctx, generator),
// buffer_size,
// llvm_i1.const_zero()
// );
Ok(())
},