diff --git a/projects/clr/rocclr/runtime/platform/kernel.cpp b/projects/clr/rocclr/runtime/platform/kernel.cpp index a4e3ef270c..3a6fd1ab49 100644 --- a/projects/clr/rocclr/runtime/platform/kernel.cpp +++ b/projects/clr/rocclr/runtime/platform/kernel.cpp @@ -13,13 +13,17 @@ namespace amd { Kernel::Kernel(Program& program, const Symbol& symbol, const std::string& name) : program_(program), symbol_(symbol), name_(name) { - const KernelSignature& s = signature(); - size_t stackSize = s.paramsSize(); - parameters_ = new (s) KernelParameters(s); + parameters_ = new (signature()) KernelParameters(signature()); fixme_guarantee(parameters_ != NULL && "out of memory"); name_ += '\0'; } +Kernel::Kernel(const Kernel& rhs) + : program_(rhs.program_()), symbol_(rhs.symbol_), name_(rhs.name_) { + parameters_ = new(signature()) KernelParameters(*rhs.parameters_); + fixme_guarantee(parameters_ != NULL && "out of memory"); +} + Kernel::~Kernel() { // Release kernel object itself delete parameters_; diff --git a/projects/clr/rocclr/runtime/platform/kernel.hpp b/projects/clr/rocclr/runtime/platform/kernel.hpp index a1e75f89f6..7e401fed11 100644 --- a/projects/clr/rocclr/runtime/platform/kernel.hpp +++ b/projects/clr/rocclr/runtime/platform/kernel.hpp @@ -93,13 +93,29 @@ class KernelParameters : protected HeapObject { execNewVcop_(0), execPfpaVcop_(0) { values_ = (address) this + alignUp(sizeof(KernelParameters), 16); - defined_ = (bool*)(values_ + signature.paramsSize()); - svmBound_ = (bool*)((address)defined_ + signature.numParameters() * sizeof(bool)); + defined_ = (bool*)(values_ + signature_.paramsSize()); + svmBound_ = (bool*)((address)defined_ + signature_.numParameters() * sizeof(bool)); - address limit = (address)&svmBound_[signature.numParameters()]; + address limit = (address)&svmBound_[signature_.numParameters()]; ::memset(values_, '\0', limit - values_); } + explicit KernelParameters(const KernelParameters& rhs) + : signature_(rhs.signature_), + execInfoOffset_(rhs.execInfoOffset_), + execSvmPtr_(rhs.execSvmPtr_), + svmSystemPointersSupport_(rhs.svmSystemPointersSupport_), + validated_(rhs.validated_), + execNewVcop_(rhs.execNewVcop_), + execPfpaVcop_(rhs.execPfpaVcop_) { + values_ = (address) this + alignUp(sizeof(KernelParameters), 16); + defined_ = (bool*)(values_ + signature_.paramsSize()); + svmBound_ = (bool*)((address)defined_ + signature_.numParameters() * sizeof(bool)); + + address limit = (address)&svmBound_[signature_.numParameters()]; + ::memcpy(values_, rhs.values_, limit - values_); + } + //! Reset the parameter at the given \a index (becomes undefined). void reset(size_t index) { defined_[index] = false; @@ -202,6 +218,9 @@ class Kernel : public RuntimeObject { */ Kernel(Program& program, const Symbol& symbol, const std::string& name); + //! Construct a new kernel object from an existing one. Used by CloneKernel. + explicit Kernel(const Kernel& rhs); + //! Return the program containing this kernel. Program& program() const { return program_(); }