Skip to content

Commit 538093a

Browse files
authored
Merge pull request #512 from hvdijk/disable-deferred-compilation
Auto-disable deferred compilation.
2 parents a776d72 + a7bdb4e commit 538093a

8 files changed

Lines changed: 40 additions & 13 deletions

File tree

modules/compiler/cookie/{{cookiecutter.target_name}}/source/info.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ namespace {{cookiecutter.target_name}} {
3636
device_info = mux_device_info;
3737
vectorizable = true;
3838
dma_optimizable = true;
39-
supports_deferred_compilation = false;
4039
scalable_vector_support = {{cookiecutter.scalable_vector}};
4140
kernel_debug = true;
4241

modules/compiler/include/compiler/info.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ struct Info {
5656
/// @brief Mux device info that this compiler will target. Must not be
5757
/// `nullptr`.
5858
mux_device_info_t device_info = nullptr;
59-
/// @brief Is `true` if the compiler supports deferred compilation (i.e.
60-
/// compiler::Module::getKernel() and the compiler::Kernel class are
61-
/// implemented), `false` otherwise.
62-
bool supports_deferred_compilation = false;
6359
/// @brief A semicolon-separated, null-terminated list with static lifetime
6460
/// duration, of this Mux device's custom compile options.
6561
///
@@ -131,6 +127,11 @@ struct Info {
131127

132128
return caps;
133129
}
130+
131+
/// @brief Returns `true` if the compiler supports deferred compilation (i.e.
132+
/// compiler::Module::getKernel() and the compiler::Kernel class are
133+
/// implemented), `false` otherwise.
134+
virtual bool supports_deferred_compilation() const { return false; }
134135
};
135136

136137
/// @brief A functor which is called when a target wants to expose a compiler.

modules/compiler/riscv/source/info.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RiscvInfo::RiscvInfo(mux_device_info_t mux_device_info,
3939

4040
vectorizable = false;
4141
dma_optimizable = true;
42-
supports_deferred_compilation = false;
4342
kernel_debug = true;
4443
}
4544

modules/compiler/targets/host/include/host/info.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ struct HostInfo : compiler::Info {
6666

6767
/// @brief Bitfield of all `host::arch`'s being targeted.
6868
static uint8_t arches;
69+
70+
bool supports_deferred_compilation() const override;
71+
72+
private:
73+
bool deferred_compilation_enabled;
74+
mutable const char *deferred_compilation_warning;
6975
};
7076

7177
} // namespace host

modules/compiler/targets/host/source/info.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,24 @@ HostInfo::HostInfo(host::arch arch, host::os os,
6868
// If we're instantiating a compiler for the current system, then we know it
6969
// supports runtime compilation, otherwise it's a cross compiler.
7070
device_info = host_device_info;
71-
supports_deferred_compilation = host_device_info->native;
71+
deferred_compilation_enabled = host_device_info->native;
72+
deferred_compilation_warning = nullptr;
7273

7374
// JIT compilation is not yet supported on RISC-V
7475
if (arch == host::arch::RISCV32 || arch == host::arch::RISCV64) {
75-
supports_deferred_compilation = false;
76+
deferred_compilation_enabled = false;
7677
}
7778

79+
#if !defined(NDEBUG) || defined(CA_ENABLE_DEBUG_SUPPORT)
80+
if (deferred_compilation_enabled) {
81+
if (std::getenv("CA_HOST_DUMP_ASM")) {
82+
deferred_compilation_warning =
83+
"CA_HOST_DUMP_ASM requires non-deferred compilation";
84+
deferred_compilation_enabled = false;
85+
}
86+
}
87+
#endif
88+
7889
// If the user wants to override, let them. This may be useful for testing the
7990
// non-deferred-compilation support, or may be useful for testing future LLVM
8091
// improvements that may provide RISC-V JIT support.
@@ -83,7 +94,7 @@ HostInfo::HostInfo(host::arch arch, host::os os,
8394
char *end;
8495
const long val = std::strtol(env, &end, 10);
8596
if (*env != '\0' && (val == 0 || val == 1) && *end == '\0') {
86-
supports_deferred_compilation = val;
97+
deferred_compilation_enabled = val;
8798
}
8899
}
89100
#endif
@@ -105,6 +116,17 @@ HostInfo::HostInfo(host::arch arch, host::os os,
105116
#endif
106117
}
107118

119+
bool HostInfo::supports_deferred_compilation() const {
120+
const bool enabled = deferred_compilation_enabled;
121+
if (auto *warning = deferred_compilation_warning) {
122+
(void)fprintf(stderr, "warning: %s. %s\n", warning,
123+
enabled ? "Deferred compilation forced enabled."
124+
: "Deferred compilation disabled.");
125+
deferred_compilation_warning = nullptr;
126+
}
127+
return enabled;
128+
}
129+
108130
std::unique_ptr<compiler::Target> HostInfo::createTarget(
109131
compiler::Context *context, compiler::NotifyCallbackFn callback) const {
110132
if (!context) {

modules/compiler/targets/host/source/target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ compiler::Result HostTarget::initWithBuiltins(
416416
Features = std::move(NativeFeatures);
417417
}
418418

419-
if (compiler_info->supports_deferred_compilation) {
419+
if (compiler_info->supports_deferred_compilation()) {
420420
llvm::orc::JITTargetMachineBuilder TMBuilder(triple);
421421
TMBuilder.setCPU(CPU);
422422
TMBuilder.setCodeGenOptLevel(multi_llvm::CodeGenOptLevel::Aggressive);

modules/compiler/test/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static inline std::string printDeviceName(
319319
static inline std::vector<const compiler::Info *> deferrableCompilers() {
320320
std::vector<const compiler::Info *> deferrable_compilers;
321321
for (const compiler::Info *compiler : compiler::compilers()) {
322-
if (compiler->supports_deferred_compilation) {
322+
if (compiler->supports_deferred_compilation()) {
323323
deferrable_compilers.emplace_back(compiler);
324324
}
325325
}

source/cl/source/program.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool cl::device_program::finalize(cl_device_id device) {
166166

167167
// If the compiler does not support deferred compilation, we get the final
168168
// binary from the module and initialize a mux_kernel_cache.
169-
if (!device->compiler_info->supports_deferred_compilation) {
169+
if (!device->compiler_info->supports_deferred_compilation()) {
170170
// Get the Mux binary.
171171
auto binary_result = compiler_module.getOrCreateMuxBinary();
172172
if (!binary_result) {
@@ -223,7 +223,7 @@ cl::device_program::createKernel(cl_device_id device,
223223
} break;
224224

225225
case cl::device_program_type::COMPILER_MODULE: {
226-
if (device->compiler_info->supports_deferred_compilation) {
226+
if (device->compiler_info->supports_deferred_compilation()) {
227227
compiler::Kernel *deferred_kernel =
228228
compiler_module.module->getKernel(kernel_name);
229229
if (!deferred_kernel) {

0 commit comments

Comments
 (0)