From 7bce438596fa7cee2635d659e00202f8500ca9e2 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Wed, 11 Sep 2024 18:54:48 +0200 Subject: wip --- modules/remote-hip/c++/device.tmpl.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'modules/remote-hip') diff --git a/modules/remote-hip/c++/device.tmpl.hpp b/modules/remote-hip/c++/device.tmpl.hpp index 4777660..6edf431 100644 --- a/modules/remote-hip/c++/device.tmpl.hpp +++ b/modules/remote-hip/c++/device.tmpl.hpp @@ -11,6 +11,7 @@ struct hip_copy_to_device { template struct hip_copy_to_device, Encoding> { using Schema = schema::Primitive; + static error_or apply(data& from, data** to){ hipError_t malloc_err = hipMalloc(to, sizeof(data)); // HIP_CHECK(malloc_err); @@ -21,5 +22,31 @@ struct hip_copy_to_device, Encoding> { return make_void(); } }; + +template +struct hip_copy_to_device, Encoding> { + static_assert(Dim == 1u, "Only 1D arrays are supported for now."); + static_assert(is_primitive::value, "Arrays can only handle primitives for now."); + + using Schema = schema::Array; + + static error_or apply(data& from, data** to){ + typename native_data_type::type* dat{}; + hipError_t data_malloc_err = hipMalloc(&dat,sizeof(typename native_data_type::type) * from.size()); + hipError_t data_copy_err = hipMemcpy(&dat, &(from.get_raw_data()),sizeof(typename native_data_type::type) * from.size(), hipMemcpyHostToDevice); + + if(from.size() == 0u){ + // Everything is fine. We just don't want to allocate data which doesn't exist. + return make_void(); + } + + // auto from_dat = &from.at(0); + + hipError_t malloc_err = hipMalloc(to, sizeof(data)); + hipError_t copy_err = hipMemcpy(*to, &from, sizeof(data), hipMemcpyHostToDevice); + + return make_void(); + } +}; } } -- cgit v1.2.3