From e2140e26214e1f5285fbd56535323b54fe943870 Mon Sep 17 00:00:00 2001 From: Noel Chalmers Date: Thu, 9 Nov 2023 10:10:07 -0600 Subject: [PATCH] Resize the argument buffer to be able to fit large arguments passed by value (#714) --- src/occa/internal/modes/hip/kernel.cpp | 22 ++++++++++++++++------ src/occa/internal/modes/hip/kernel.hpp | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/occa/internal/modes/hip/kernel.cpp b/src/occa/internal/modes/hip/kernel.cpp index bbf514087..e721a24e0 100644 --- a/src/occa/internal/modes/hip/kernel.cpp +++ b/src/occa/internal/modes/hip/kernel.cpp @@ -72,15 +72,25 @@ namespace occa { void kernel::deviceRun() const { const int args = (int) arguments.size(); - if (!args) { - vArgs.resize(1); - } else if ((int) vArgs.size() < args) { - vArgs.resize(args); + + int offset = 0; + for (int i = 0; i < args; ++i) { + const kernelArgData &arg = arguments[i]; + const udim_t argSize = arg.size(); + + offset += offset % std::min(static_cast(argSize), + sizeof(void*)); //align + offset += argSize; + } + + size_t argBufferSize = std::max(offset,1); + if (vArgs.size() < argBufferSize) { + vArgs.resize(argBufferSize); } // HIP expects kernel arguments to be aligned - char *dataPtr = (char*) &(vArgs[0]); - int offset = 0; + std::byte *dataPtr = vArgs.data(); + offset = 0; for (int i = 0; i < args; ++i) { const kernelArgData &arg = arguments[i]; const udim_t argSize = arg.size(); diff --git a/src/occa/internal/modes/hip/kernel.hpp b/src/occa/internal/modes/hip/kernel.hpp index 95eb49e4c..3a98b9a89 100644 --- a/src/occa/internal/modes/hip/kernel.hpp +++ b/src/occa/internal/modes/hip/kernel.hpp @@ -15,7 +15,7 @@ namespace occa { hipModule_t hipModule; hipFunction_t hipFunction; - mutable std::vector vArgs; + mutable std::vector vArgs; public: kernel(modeDevice_t *modeDevice_,