Skip to content

Commit f03c7ee

Browse files
committed
clang - minor tidying for CUDA JiT
1 parent b02756a commit f03c7ee

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

backends/cuda/ceed-cuda-compile.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,18 @@ static int CeedCompileCore_Cuda(Ceed ceed, const char *source, const bool throw_
309309

310310
char *next_dot = strchr((char *)version_substring, '.');
311311

312-
next_dot[0] = '\0';
313-
ceed_data->llvm_version = llvm_version = std::stoi(version_substring);
314-
CeedDebug(ceed, "Rust LLVM version number: %d\n", llvm_version);
315-
316-
command = std::string("clang++-") + std::to_string(llvm_version);
317-
output_stream = popen((command + std::string(" 2>&1")).c_str(), "r");
318-
ceed_data->use_llvm_version = use_llvm_version = pclose(output_stream) == 0;
312+
if (next_dot) {
313+
next_dot[0] = '\0';
314+
ceed_data->llvm_version = llvm_version = std::stoi(version_substring);
315+
CeedDebug(ceed, "Rust LLVM version number: %d\n", llvm_version);
316+
317+
command = std::string("clang++-") + std::to_string(llvm_version);
318+
output_stream = popen((command + std::string(" 2>&1")).c_str(), "r");
319+
ceed_data->use_llvm_version = use_llvm_version = pclose(output_stream) == 0;
320+
} else {
321+
ceed_data->llvm_version = -1;
322+
ceed_data->use_llvm_version = use_llvm_version = false;
323+
}
319324
}
320325

321326
// Compile wrapper kernel
@@ -326,15 +331,16 @@ static int CeedCompileCore_Cuda(Ceed ceed, const char *source, const bool throw_
326331
CeedCallSystem(ceed, command.c_str(), "JiT kernel source");
327332
CeedCallSystem(ceed, ("chmod 0777 temp/kernel_" + std::to_string(build_id) + "_1_wrapped.ll").c_str(), "update JiT file permissions");
328333

329-
// Find Rust's llvm-link tool and runs it
334+
// Find Rust's llvm-link tool and run it
330335
command = "$(find $(rustup run " + std::string(rust_toolchain) + " rustc --print sysroot) -name llvm-link) temp/kernel_" +
331336
std::to_string(build_id) +
332337
"_1_wrapped.ll --ignore-non-bitcode --internalize --only-needed -S -o "
333338
"temp/kernel_" +
334339
std::to_string(build_id) + "_2_linked.ll ";
335340

336-
// Searches for .a files in rust directoy
337-
// Note: this is necessary because Rust crate names may not match the folder they are in
341+
// Searches for .a files in Rust directory
342+
// Note: Rust crate names may not match the folder they are in
343+
// TODO: If libCEED switches to c++17, use std::filesystem here
338344
for (CeedInt i = 0; i < num_rust_source_dirs; i++) {
339345
std::string dir = rust_dirs[i] + "/target/nvptx64-nvidia-cuda/release";
340346
DIR *dp = opendir(dir.c_str());
@@ -351,7 +357,6 @@ static int CeedCompileCore_Cuda(Ceed ceed, const char *source, const bool throw_
351357
}
352358
}
353359
closedir(dp);
354-
// TODO: when libCEED switches to c++17, switch to std::filesystem for the loop above
355360
}
356361

357362
// Link, optimize, and compile final CUDA kernel
@@ -371,6 +376,7 @@ static int CeedCompileCore_Cuda(Ceed ceed, const char *source, const bool throw_
371376
"compile final CUDA kernel");
372377
CeedCallSystem(ceed, ("chmod 0777 temp/kernel_" + std::to_string(build_id) + "_4_final.ptx").c_str(), "update JiT file permissions");
373378

379+
// Load module from final PTX
374380
ifstream ptxfile("temp/kernel_" + std::to_string(build_id) + "_4_final.ptx");
375381
ostringstream sstr;
376382

0 commit comments

Comments
 (0)