Skip to content

Commit 6465518

Browse files
authored
[SYCL][Fusion][NoSTL] Hide JITContext behind interface (intel#12189)
Do not allocate the `JITContext` in the `jit_compiler` class; instead make it an independent singleton inside the kernel fusion library. *This PR is the start of a series of changes to remove uses of STL classes in the kernel fusion interface to prevent ABI issues in the future.* Signed-off-by: Julian Oppermann <julian.oppermann@codeplay.com>
1 parent d85f338 commit 6465518

File tree

10 files changed

+33
-36
lines changed

10 files changed

+33
-36
lines changed

sycl-fusion/jit-compiler/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
add_llvm_library(sycl-fusion
33
lib/KernelFusion.cpp
4-
lib/JITContext.cpp
54
lib/translation/KernelTranslation.cpp
65
lib/translation/SPIRVLLVMTranslation.cpp
76
lib/fusion/FusionPipeline.cpp
87
lib/fusion/FusionHelper.cpp
8+
lib/fusion/JITContext.cpp
99
lib/fusion/ModuleHelper.cpp
1010
lib/helper/ConfigHelper.cpp
1111

sycl-fusion/jit-compiler/include/KernelFusion.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef SYCL_FUSION_JIT_COMPILER_KERNELFUSION_H
1010
#define SYCL_FUSION_JIT_COMPILER_KERNELFUSION_H
1111

12-
#include "JITContext.h"
1312
#include "Kernel.h"
1413
#include "Options.h"
1514
#include "Parameter.h"
@@ -55,16 +54,14 @@ class FusionResult {
5554
class KernelFusion {
5655

5756
public:
58-
static FusionResult
59-
fuseKernels(JITContext &JITCtx, Config &&JITConfig,
60-
const std::vector<SYCLKernelInfo> &KernelInformation,
61-
const std::vector<std::string> &KernelsToFuse,
62-
const std::string &FusedKernelName,
63-
jit_compiler::ParamIdentList &Identities,
64-
BarrierFlags BarriersFlags,
65-
const std::vector<jit_compiler::ParameterInternalization>
66-
&Internalization,
67-
const std::vector<jit_compiler::JITConstant> &JITConstants);
57+
static FusionResult fuseKernels(
58+
Config &&JITConfig, const std::vector<SYCLKernelInfo> &KernelInformation,
59+
const std::vector<std::string> &KernelsToFuse,
60+
const std::string &FusedKernelName,
61+
jit_compiler::ParamIdentList &Identities, BarrierFlags BarriersFlags,
62+
const std::vector<jit_compiler::ParameterInternalization>
63+
&Internalization,
64+
const std::vector<jit_compiler::JITConstant> &JITConstants);
6865
};
6966

7067
} // namespace jit_compiler

sycl-fusion/jit-compiler/lib/KernelFusion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ static bool isTargetFormatSupported(BinaryFormat TargetFormat) {
7272
}
7373

7474
FusionResult KernelFusion::fuseKernels(
75-
JITContext &JITCtx, Config &&JITConfig,
76-
const std::vector<SYCLKernelInfo> &KernelInformation,
75+
Config &&JITConfig, const std::vector<SYCLKernelInfo> &KernelInformation,
7776
const std::vector<std::string> &KernelsToFuse,
7877
const std::string &FusedKernelName, ParamIdentList &Identities,
7978
BarrierFlags BarriersFlags,
@@ -103,6 +102,7 @@ FusionResult KernelFusion::fuseKernels(
103102
"Fusion output target format not supported by this build");
104103
}
105104

105+
auto &JITCtx = JITContext::getInstance();
106106
bool CachingEnabled = ConfigHelper::get<option::JITEnableCaching>();
107107
CacheKeyT CacheKey{TargetArch,
108108
KernelsToFuse,

sycl-fusion/jit-compiler/include/Hashing.h renamed to sycl-fusion/jit-compiler/lib/fusion/Hashing.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef SYCL_FUSION_JIT_COMPILER_HASHING_H
10-
#define SYCL_FUSION_JIT_COMPILER_HASHING_H
9+
#ifndef SYCL_FUSION_JIT_COMPILER_FUSION_HASHING_H
10+
#define SYCL_FUSION_JIT_COMPILER_FUSION_HASHING_H
1111

1212
#include "Kernel.h"
1313
#include "Parameter.h"
@@ -57,4 +57,4 @@ template <typename... T> struct hash<tuple<T...>> {
5757
};
5858
} // namespace std
5959

60-
#endif // SYCL_FUSION_JIT_COMPILER_HASHING_H
60+
#endif // SYCL_FUSION_JIT_COMPILER_FUSION_HASHING_H

sycl-fusion/jit-compiler/lib/JITContext.cpp renamed to sycl-fusion/jit-compiler/lib/fusion/JITContext.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ BinaryFormat KernelBinary::format() const { return Format; }
2525

2626
JITContext::JITContext() : LLVMCtx{new llvm::LLVMContext}, Binaries{} {}
2727

28-
JITContext::~JITContext() = default;
29-
3028
llvm::LLVMContext *JITContext::getLLVMContext() { return LLVMCtx.get(); }
3129

3230
std::optional<SYCLKernelInfo>

sycl-fusion/jit-compiler/include/JITContext.h renamed to sycl-fusion/jit-compiler/lib/fusion/JITContext.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef SYCL_FUSION_JIT_COMPILER_JITCONTEXT_H
10-
#define SYCL_FUSION_JIT_COMPILER_JITCONTEXT_H
9+
#ifndef SYCL_FUSION_JIT_COMPILER_FUSION_JITCONTEXT_H
10+
#define SYCL_FUSION_JIT_COMPILER_FUSION_JITCONTEXT_H
1111

1212
#include <memory>
1313
#include <mutex>
@@ -61,9 +61,10 @@ class KernelBinary {
6161
class JITContext {
6262

6363
public:
64-
JITContext();
65-
66-
~JITContext();
64+
static JITContext &getInstance() {
65+
static JITContext Instance{};
66+
return Instance;
67+
}
6768

6869
llvm::LLVMContext *getLLVMContext();
6970

@@ -77,6 +78,13 @@ class JITContext {
7778
void addCacheEntry(CacheKeyT &Identifier, SYCLKernelInfo &Kernel);
7879

7980
private:
81+
JITContext();
82+
~JITContext() = default;
83+
JITContext(const JITContext &) = delete;
84+
JITContext(JITContext &&) = delete;
85+
JITContext &operator=(const JITContext &) = delete;
86+
JITContext &operator=(const JITContext &&) = delete;
87+
8088
// FIXME: Change this to std::shared_mutex after switching to C++17.
8189
using MutexT = std::shared_timed_mutex;
8290

@@ -96,4 +104,4 @@ class JITContext {
96104
};
97105
} // namespace jit_compiler
98106

99-
#endif // SYCL_FUSION_JIT_COMPILER_JITCONTEXT_H
107+
#endif // SYCL_FUSION_JIT_COMPILER_FUSION_JITCONTEXT_H

sycl-fusion/jit-compiler/lib/translation/KernelTranslation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#ifndef SYCL_FUSION_JIT_COMPILER_TRANSLATION_KERNELTRANSLATION_H
99
#define SYCL_FUSION_JIT_COMPILER_TRANSLATION_KERNELTRANSLATION_H
1010

11-
#include "JITContext.h"
1211
#include "Kernel.h"
12+
#include "fusion/JITContext.h"
1313
#include "llvm/IR/LLVMContext.h"
1414
#include "llvm/IR/Module.h"
1515
#include "llvm/Support/Error.h"

sycl-fusion/jit-compiler/lib/translation/SPIRVLLVMTranslation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#ifndef SYCL_FUSION_JIT_COMPILER_TRANSLATION_SPIRVLLVMTRANSLATION_H
1010
#define SYCL_FUSION_JIT_COMPILER_TRANSLATION_SPIRVLLVMTRANSLATION_H
1111

12-
#include "JITContext.h"
1312
#include "Kernel.h"
1413
#include "LLVMSPIRVOpts.h"
14+
#include "fusion/JITContext.h"
1515
#include "llvm/IR/LLVMContext.h"
1616
#include "llvm/IR/Module.h"
1717
#include <llvm/Support/Error.h>

sycl/source/detail/jit_compiler.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ namespace sycl {
2222
inline namespace _V1 {
2323
namespace detail {
2424

25-
jit_compiler::jit_compiler() : MJITContext{new ::jit_compiler::JITContext{}} {}
26-
27-
jit_compiler::~jit_compiler() = default;
28-
2925
static ::jit_compiler::BinaryFormat
3026
translateBinaryImageFormat(pi::PiDeviceBinaryType Type) {
3127
switch (Type) {
@@ -836,7 +832,7 @@ jit_compiler::fuseKernels(QueueImplPtr Queue,
836832
JITConfig.set<::jit_compiler::option::JITTargetInfo>(TargetInfo);
837833

838834
auto FusionResult = ::jit_compiler::KernelFusion::fuseKernels(
839-
*MJITContext, std::move(JITConfig), InputKernelInfo, InputKernelNames,
835+
std::move(JITConfig), InputKernelInfo, InputKernelNames,
840836
FusedKernelName.str(), ParamIdentities, BarrierFlags, InternalizeParams,
841837
JITConstants);
842838

sycl/source/detail/jit_compiler.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class jit_compiler {
4242
}
4343

4444
private:
45-
jit_compiler();
46-
~jit_compiler();
45+
jit_compiler() = default;
46+
~jit_compiler() = default;
4747
jit_compiler(const jit_compiler &) = delete;
4848
jit_compiler(jit_compiler &&) = delete;
4949
jit_compiler &operator=(const jit_compiler &) = delete;
@@ -61,8 +61,6 @@ class jit_compiler {
6161

6262
// Manages the lifetime of the PI structs for device binaries.
6363
std::vector<DeviceBinariesCollection> JITDeviceBinaries;
64-
65-
std::unique_ptr<::jit_compiler::JITContext> MJITContext;
6664
};
6765

6866
} // namespace detail

0 commit comments

Comments
 (0)