summaryrefslogtreecommitdiff
path: root/parallel-libs/streamexecutor/lib/Kernel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'parallel-libs/streamexecutor/lib/Kernel.cpp')
-rw-r--r--parallel-libs/streamexecutor/lib/Kernel.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/parallel-libs/streamexecutor/lib/Kernel.cpp b/parallel-libs/streamexecutor/lib/Kernel.cpp
index 1f4218c4df3..61305372f18 100644
--- a/parallel-libs/streamexecutor/lib/Kernel.cpp
+++ b/parallel-libs/streamexecutor/lib/Kernel.cpp
@@ -12,16 +12,49 @@
///
//===----------------------------------------------------------------------===//
-#include "streamexecutor/Kernel.h"
+#include <cassert>
+
#include "streamexecutor/Device.h"
+#include "streamexecutor/Kernel.h"
#include "streamexecutor/PlatformInterfaces.h"
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
namespace streamexecutor {
-KernelBase::KernelBase(llvm::StringRef Name)
- : Name(Name), DemangledName(llvm::symbolize::LLVMSymbolizer::DemangleName(
- Name, nullptr)) {}
+KernelBase::KernelBase(PlatformDevice *D, const void *PlatformKernelHandle,
+ llvm::StringRef Name)
+ : PDevice(D), PlatformKernelHandle(PlatformKernelHandle), Name(Name),
+ DemangledName(
+ llvm::symbolize::LLVMSymbolizer::DemangleName(Name, nullptr)) {
+ assert(D != nullptr &&
+ "cannot construct a kernel object with a null platform device");
+ assert(PlatformKernelHandle != nullptr &&
+ "cannot construct a kernel object with a null platform kernel handle");
+}
+
+KernelBase::KernelBase(KernelBase &&Other)
+ : PDevice(Other.PDevice), PlatformKernelHandle(Other.PlatformKernelHandle),
+ Name(std::move(Other.Name)),
+ DemangledName(std::move(Other.DemangledName)) {
+ Other.PDevice = nullptr;
+ Other.PlatformKernelHandle = nullptr;
+}
+
+KernelBase &KernelBase::operator=(KernelBase &&Other) {
+ PDevice = Other.PDevice;
+ PlatformKernelHandle = Other.PlatformKernelHandle;
+ Name = std::move(Other.Name);
+ DemangledName = std::move(Other.DemangledName);
+ Other.PDevice = nullptr;
+ Other.PlatformKernelHandle = nullptr;
+ return *this;
+}
+
+KernelBase::~KernelBase() {
+ if (PlatformKernelHandle)
+ // TODO(jhen): Handle the error here.
+ consumeError(PDevice->destroyKernel(PlatformKernelHandle));
+}
} // namespace streamexecutor