Skip to content

Commit

Permalink
[CUDA][HIP][DPC++] Fix an issue with double frees when OKL has multip…
Browse files Browse the repository at this point in the history
…le kernels (#624)
  • Loading branch information
noelchalmers authored and kris-rowe committed Dec 16, 2022
1 parent 799d9ad commit c019f4d
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/occa/internal/modes/cuda/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ namespace occa {
kernel &k = *(new kernel(this,
kernelName,
sourceFilename,
cuModule,
kernelProps));

k.launcherKernel = buildLauncherKernel(kernelHash,
Expand Down Expand Up @@ -377,7 +378,6 @@ namespace occa {
kernel *cuKernel = new kernel(this,
metadata.name,
sourceFilename,
cuModule,
cuFunction,
kernelProps);
cuKernel->metadata = metadata;
Expand Down
12 changes: 11 additions & 1 deletion src/occa/internal/modes/cuda/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ namespace occa {
kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
CUmodule cuModule_,
const occa::json &properties_) :
occa::launchedModeKernel_t(modeDevice_, name_, sourceFilename_, properties_),
cuModule(NULL),
cuModule(cuModule_),
cuFunction(NULL) {}

kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
CUfunction cuFunction_,
const occa::json &properties_) :
occa::launchedModeKernel_t(modeDevice_, name_, sourceFilename_, properties_),
cuModule(NULL),
cuFunction(cuFunction_) {}

kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
Expand Down
7 changes: 7 additions & 0 deletions src/occa/internal/modes/cuda/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ namespace occa {
kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
CUmodule cuModule_,
const occa::json &properties_);

kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
CUfunction cuFunction_,
const occa::json &properties_);

kernel(modeDevice_t *modeDevice_,
Expand Down
6 changes: 3 additions & 3 deletions src/occa/internal/modes/dpcpp/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,12 @@ namespace occa
lang::sourceMetadata_t &deviceMetadata,
const occa::json &kernelProps)
{
void *dl_handle = sys::dlopen(binaryFilename);

dpcpp::kernel &k = *(new dpcpp::kernel(this,
kernelName,
sourceFilename,
dl_handle,
kernelProps));

k.launcherKernel = buildLauncherKernel(kernelHash,
Expand All @@ -260,8 +263,6 @@ namespace occa
kernelName,
deviceMetadata);

void *dl_handle = sys::dlopen(binaryFilename);

const int launchedKernelsCount = (int)launchedKernelsMetadata.size();
for (int i = 0; i < launchedKernelsCount; ++i)
{
Expand All @@ -279,7 +280,6 @@ namespace occa
kernel *dpcppKernel = new dpcpp::kernel(this,
metadata.name,
sourceFilename,
dl_handle,
kernel_function,
kernelProps);

Expand Down
14 changes: 13 additions & 1 deletion src/occa/internal/modes/dpcpp/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ namespace occa
kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
void *dlHandle_,
const occa::json &properties_)
: occa::launchedModeKernel_t(modeDevice_, name_, sourceFilename_, properties_),
dlHandle{nullptr},
dlHandle{dlHandle_},
function{nullptr}
{
}

kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
functionPtr_t function_,
const occa::json &properties_)
: occa::launchedModeKernel_t(modeDevice_, name_, sourceFilename_, properties_),
dlHandle(nullptr),
function(function_)
{
}

kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
Expand Down
7 changes: 7 additions & 0 deletions src/occa/internal/modes/dpcpp/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ namespace occa
kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
void* dlHandle_,
const occa::json &properties_);

kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
functionPtr_t function_,
const occa::json &properties_);

kernel(modeDevice_t *modeDevice_,
Expand Down
2 changes: 1 addition & 1 deletion src/occa/internal/modes/hip/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ namespace occa {
kernel &k = *(new kernel(this,
kernelName,
sourceFilename,
hipModule,
kernelProps));

k.launcherKernel = buildLauncherKernel(kernelHash,
Expand Down Expand Up @@ -360,7 +361,6 @@ namespace occa {
kernel *hipKernel = new kernel(this,
metadata.name,
sourceFilename,
hipModule,
hipFunction,
kernelProps);
hipKernel->metadata = metadata;
Expand Down
12 changes: 11 additions & 1 deletion src/occa/internal/modes/hip/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ namespace occa {
kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
hipModule_t hipModule_,
const occa::json &properties_) :
occa::launchedModeKernel_t(modeDevice_, name_, sourceFilename_, properties_),
hipModule(NULL),
hipModule(hipModule_),
hipFunction(NULL) {}

kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
hipFunction_t hipFunction_,
const occa::json &properties_) :
occa::launchedModeKernel_t(modeDevice_, name_, sourceFilename_, properties_),
hipModule(NULL),
hipFunction(hipFunction_) {}

kernel::kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
Expand Down
7 changes: 7 additions & 0 deletions src/occa/internal/modes/hip/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ namespace occa {
kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
hipModule_t hipModule_,
const occa::json &properties_);

kernel(modeDevice_t *modeDevice_,
const std::string &name_,
const std::string &sourceFilename_,
hipFunction_t hipFunction_,
const occa::json &properties_);

kernel(modeDevice_t *modeDevice_,
Expand Down

0 comments on commit c019f4d

Please sign in to comment.