Fix a race condition between the "ephemeral watchpoint disabling" and commands the...
[lldb.git] / parallel-libs / streamexecutor / lib / KernelSpec.cpp
1 //===-- KernelSpec.cpp - General kernel spec implementation ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file contains the implementation details for kernel loader specs.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "streamexecutor/KernelSpec.h"
16
17 #include "llvm/ADT/STLExtras.h"
18
19 namespace streamexecutor {
20
21 KernelLoaderSpec::KernelLoaderSpec(llvm::StringRef KernelName)
22     : KernelName(KernelName) {}
23
24 CUDAPTXInMemorySpec::CUDAPTXInMemorySpec(
25     llvm::StringRef KernelName,
26     const llvm::ArrayRef<CUDAPTXInMemorySpec::PTXSpec> SpecList)
27     : KernelLoaderSpec(KernelName) {
28   for (const auto &Spec : SpecList)
29     PTXByComputeCapability.emplace(Spec.TheComputeCapability, Spec.PTXCode);
30 }
31
32 const char *CUDAPTXInMemorySpec::getCode(int ComputeCapabilityMajor,
33                                          int ComputeCapabilityMinor) const {
34   auto Iterator =
35       PTXByComputeCapability.upper_bound(CUDAPTXInMemorySpec::ComputeCapability{
36           ComputeCapabilityMajor, ComputeCapabilityMinor});
37   if (Iterator == PTXByComputeCapability.begin())
38     return nullptr;
39   --Iterator;
40   return Iterator->second;
41 }
42
43 CUDAFatbinInMemorySpec::CUDAFatbinInMemorySpec(llvm::StringRef KernelName,
44                                                const void *Bytes)
45     : KernelLoaderSpec(KernelName), Bytes(Bytes) {}
46
47 OpenCLTextInMemorySpec::OpenCLTextInMemorySpec(llvm::StringRef KernelName,
48                                                const char *Text)
49     : KernelLoaderSpec(KernelName), Text(Text) {}
50
51 void MultiKernelLoaderSpec::setKernelName(llvm::StringRef KernelName) {
52   if (TheKernelName)
53     assert(KernelName.equals(*TheKernelName) &&
54            "different kernel names in one MultiKernelLoaderSpec");
55   else
56     TheKernelName = llvm::make_unique<std::string>(KernelName);
57 }
58
59 MultiKernelLoaderSpec &MultiKernelLoaderSpec::addCUDAPTXInMemory(
60     llvm::StringRef KernelName,
61     llvm::ArrayRef<CUDAPTXInMemorySpec::PTXSpec> SpecList) {
62   assert((TheCUDAPTXInMemorySpec == nullptr) &&
63          "illegal loader spec overwrite");
64   setKernelName(KernelName);
65   TheCUDAPTXInMemorySpec =
66       llvm::make_unique<CUDAPTXInMemorySpec>(KernelName, SpecList);
67   return *this;
68 }
69
70 MultiKernelLoaderSpec &
71 MultiKernelLoaderSpec::addCUDAFatbinInMemory(llvm::StringRef KernelName,
72                                              const void *Bytes) {
73   assert((TheCUDAFatbinInMemorySpec == nullptr) &&
74          "illegal loader spec overwrite");
75   setKernelName(KernelName);
76   TheCUDAFatbinInMemorySpec =
77       llvm::make_unique<CUDAFatbinInMemorySpec>(KernelName, Bytes);
78   return *this;
79 }
80
81 MultiKernelLoaderSpec &
82 MultiKernelLoaderSpec::addOpenCLTextInMemory(llvm::StringRef KernelName,
83                                              const char *OpenCLText) {
84   assert((TheOpenCLTextInMemorySpec == nullptr) &&
85          "illegal loader spec overwrite");
86   setKernelName(KernelName);
87   TheOpenCLTextInMemorySpec =
88       llvm::make_unique<OpenCLTextInMemorySpec>(KernelName, OpenCLText);
89   return *this;
90 }
91
92 } // namespace streamexecutor