From 5739cea4ed2b5a68266db6f3a766e98c655497ae Mon Sep 17 00:00:00 2001 From: Rafael Ravedutti <rafaelravedutti@gmail.com> Date: Fri, 5 May 2023 18:30:26 +0200 Subject: [PATCH] Generate copies of feature properties to GPU Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com> --- add-types.sh => data/add_types.sh | 0 runtime/pairs.cpp | 5 +++++ runtime/pairs.hpp | 3 +++ src/pairs/code_gen/cgen.py | 5 ++++- 4 files changed, 12 insertions(+), 1 deletion(-) rename add-types.sh => data/add_types.sh (100%) diff --git a/add-types.sh b/data/add_types.sh similarity index 100% rename from add-types.sh rename to data/add_types.sh diff --git a/runtime/pairs.cpp b/runtime/pairs.cpp index 1fda232..6bae049 100644 --- a/runtime/pairs.cpp +++ b/runtime/pairs.cpp @@ -130,6 +130,11 @@ void PairsSimulation::copyPropertyToHost(Property &prop) { } } +void PairsSimulation::copyFeaturePropertyToDevice(FeatureProperty &feature_prop) { + PAIRS_DEBUG("Copying static array %s to device\n", feature_prop.getName().c_str()); + pairs::copy_static_symbol_to_device(feature_prop.getHostPointer(), feature_prop.getDevicePointer(), feature_prop.getArraySize()); +} + void PairsSimulation::communicateSizes(int dim, const int *send_sizes, int *recv_sizes) { auto nsend_id = getArrayByHostPointer(send_sizes).getId(); auto nrecv_id = getArrayByHostPointer(recv_sizes).getId(); diff --git a/runtime/pairs.hpp b/runtime/pairs.hpp index 6c82e67..8c8be73 100644 --- a/runtime/pairs.hpp +++ b/runtime/pairs.hpp @@ -115,6 +115,9 @@ public: void copyPropertyToHost(property_t id) { copyPropertyToHost(getProperty(id)); } void copyPropertyToHost(Property &prop); + void copyFeaturePropertyToDevice(property_t id) { copyFeaturePropertyToDevice(getFeatureProperty(id)); } + void copyFeaturePropertyToDevice(FeatureProperty &feature_prop); + void communicateSizes(int dim, const int *send_sizes, int *recv_sizes); void communicateData( int dim, int elem_size, diff --git a/src/pairs/code_gen/cgen.py b/src/pairs/code_gen/cgen.py index cd93221..4e7c431 100644 --- a/src/pairs/code_gen/cgen.py +++ b/src/pairs/code_gen/cgen.py @@ -539,11 +539,14 @@ class CGen: assert fptype != "Prop_Invalid", "Invalid feature property type!" self.print(f"{tkw} {ptr}[{array_size}];") - self.print(f"pairs->addFeatureProperty({fp.id()}, \"{fp.name()}\", &{ptr}, {d_ptr}, {fptype}, {nkinds}, {array_size});") + self.print(f"pairs->addFeatureProperty({fp.id()}, \"{fp.name()}\", &{ptr}, {d_ptr}, {fptype}, {nkinds}, {array_size} * sizeof({tkw}));") for i in range(array_size): self.print(f"{ptr}[{i}] = {fp.data()[i]};") + if self.target.is_gpu() and fp.device_flag: + self.print(f"pairs->copyFeaturePropertyToDevice({fp.id()}); // {fp.name()}") + if isinstance(ast_node, Timestep): self.generate_statement(ast_node.block) -- GitLab