summaryrefslogtreecommitdiff
path: root/parallel-libs/streamexecutor/lib/Kernel.cpp
blob: 61305372f184d7c74f755d3c4ae8c1e802e4196d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//===-- Kernel.cpp - General kernel implementation ------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains the implementation details for kernel types.
///
//===----------------------------------------------------------------------===//

#include <cassert>

#include "streamexecutor/Device.h"
#include "streamexecutor/Kernel.h"
#include "streamexecutor/PlatformInterfaces.h"

#include "llvm/DebugInfo/Symbolize/Symbolize.h"

namespace streamexecutor {

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