From eaaa194a87082ee5530f724b45c9822466aafe56 Mon Sep 17 00:00:00 2001 From: David Mak Date: Mon, 6 Jan 2025 16:42:53 +0800 Subject: [PATCH] [artiq] symbol_resolver: Cast ndarray.{shape,strides} globals to usize* This is needed as ndarray.{shapes,strides} are ArrayValues, and so a GEP operation is required to convert them into pointers to their first elements. --- nac3artiq/src/symbol_resolver.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 75600cc2..232cd084 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -1248,9 +1248,30 @@ impl InnerResolver { let ndarray_ndims = llvm_usize.const_int(ndims, false); + // calling as_pointer_value on shape and strides returns [i64 x ndims]* + // convert into i64* to conform with expected layout of ndarray + let ndarray_shape = shape_global.as_pointer_value(); + let ndarray_shape = unsafe { + ctx.builder + .build_in_bounds_gep( + ndarray_shape, + &[llvm_usize.const_zero(), llvm_usize.const_zero()], + "", + ) + .unwrap() + }; let ndarray_strides = strides_global.as_pointer_value(); + let ndarray_strides = unsafe { + ctx.builder + .build_in_bounds_gep( + ndarray_strides, + &[llvm_usize.const_zero(), llvm_usize.const_zero()], + "", + ) + .unwrap() + }; let ndarray = llvm_ndarray .as_base_type()