Skip to content

Commit

Permalink
fix issue with GraphNodeKernel constructors
Browse files Browse the repository at this point in the history
the constructors were copying the value of Args pointer,
instead of making an actual copy of the arguments. This
can lead to a crash if the Args pointer lives on the stack,
later goes out of scope, and setupAllArgs() is called.
  • Loading branch information
franz authored and PaulAlbon committed Nov 13, 2024
1 parent 611799f commit c56ea38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/CHIPGraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ GraphNodeKernel::GraphNodeKernel(const hipKernelNodeParams *TheParams)
if (!Kernel_)
CHIPERR_LOG_AND_THROW("Could not find requested kernel",
hipErrorInvalidDeviceFunction);
unsigned NumArgs = Kernel_->getFuncInfo()->getNumClientArgs();
KernelArgs_.resize(NumArgs);
std::memcpy(KernelArgs_.data(), TheParams->kernelParams, sizeof(void*) * NumArgs);
Params_.kernelParams = KernelArgs_.data();

ExecItem_ = ::Backend->createExecItem(Params_.gridDim, Params_.blockDim,
Params_.sharedMemBytes, nullptr);
ExecItem_->setKernel(Kernel_);
Expand All @@ -176,9 +181,16 @@ GraphNodeKernel::GraphNodeKernel(const void *HostFunction, dim3 GridDim,
auto Dev = ::Backend->getActiveDevice();

Kernel_ = Dev->findKernel(HostPtr(Params_.func));

if (!Kernel_)

Check warning on line 185 in src/CHIPGraph.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

src/CHIPGraph.cc:185:8 [readability-implicit-bool-conversion]

implicit conversion 'chipstar::Kernel *' -> bool

Check warning on line 185 in src/CHIPGraph.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

src/CHIPGraph.cc:185:16 [readability-braces-around-statements]

statement should be inside braces
CHIPERR_LOG_AND_THROW("Could not find requested kernel",
hipErrorInvalidDeviceFunction);

unsigned NumArgs = Kernel_->getFuncInfo()->getNumClientArgs();
KernelArgs_.resize(NumArgs);
std::memcpy(KernelArgs_.data(), Args, sizeof(void*) * NumArgs);
Params_.kernelParams = KernelArgs_.data();

ExecItem_ = ::Backend->createExecItem(GridDim, BlockDim, SharedMem, nullptr);
ExecItem_->setKernel(Kernel_);
}
Expand Down
1 change: 1 addition & 0 deletions src/CHIPGraph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ private:
std::vector<void *> ArgList_;

hipKernelNodeParams Params_;
std::vector<void*> KernelArgs_;
chipstar::ExecItem *ExecItem_;
chipstar::Kernel *Kernel_;

Expand Down

0 comments on commit c56ea38

Please sign in to comment.