Skip to content

Commit

Permalink
Resize the argument buffer to be able to fit large arguments passed b…
Browse files Browse the repository at this point in the history
…y value (#714)
  • Loading branch information
noelchalmers authored Nov 9, 2023
1 parent c3162d8 commit e2140e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/occa/internal/modes/hip/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(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();
Expand Down
2 changes: 1 addition & 1 deletion src/occa/internal/modes/hip/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace occa {
hipModule_t hipModule;
hipFunction_t hipFunction;

mutable std::vector<void*> vArgs;
mutable std::vector<std::byte> vArgs;

public:
kernel(modeDevice_t *modeDevice_,
Expand Down

0 comments on commit e2140e2

Please sign in to comment.