Implementation
set data(List<double> newData) {
if (newData.length != length) {
throw ArgumentError(
"Data length ${newData.length} mismatch with Tensor length $length",
);
}
// Allocate native memory to hold the new data
final ptr = calloc<ffi.Float>(length);
// Fill the native buffer
for (int i = 0; i < length; i++) {
ptr[i] = newData[i];
}
// 1. You need this FFI call in your engine:
// engine.setTensorData(handle, ptr);
// It should perform: cudaMemcpy(t->data_gpu, ptr, size, cudaMemcpyHostToDevice);
engine.setTensorData(_handle, ptr);
// Clean up host memory
calloc.free(ptr);
}