-
-
Notifications
You must be signed in to change notification settings - Fork 46
Add CUDA wrapper capability. #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fe9c170
3369f07
8ea5070
b8e717b
5b8bdde
359b709
86bca5e
0a5af4f
d1fc805
781f8be
ca2b943
b416b1b
3338af9
aca302b
06627c6
4e8ac19
1426b4c
006c23c
9e0464e
8981aa9
61e3d4e
846e06f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include "Components.h" | ||
#include "FacetIntegrals.h" | ||
#include "HyperElasticity.h" | ||
#include "MathFunctions.h" | ||
#include "StabilisedStokes.h" | ||
#include "VectorPoisson.h" | ||
#include "ufcx.h" | ||
#include "nvrtc.h" | ||
#include <iostream> | ||
#include <stdexcept> | ||
#include <sstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
void check_nvrtc_compilation(ufcx_form* form) | ||
{ | ||
// extract kernel | ||
ufcx_integral* integral = form->form_integrals[0]; | ||
ufcx_tabulate_tensor_cuda_nvrtc* kernel = integral->tabulate_tensor_cuda_nvrtc; | ||
// call kernel to get CUDA-wrapped source code | ||
int num_program_headers; | ||
const char** program_headers; | ||
const char** program_include_names; | ||
const char* program_src; | ||
const char* tabulate_tensor_function_name; | ||
if (!kernel) { | ||
throw std::runtime_error("NVRTC wrapper function is NULL!"); | ||
} | ||
(*kernel)( | ||
&num_program_headers, &program_headers, | ||
&program_include_names, &program_src, | ||
&tabulate_tensor_function_name); | ||
// compile CUDA-wrapped source code with NVRTC | ||
// with proper error checking | ||
|
||
nvrtcResult nvrtc_err; | ||
nvrtcProgram program; | ||
nvrtc_err = nvrtcCreateProgram( | ||
&program, program_src, tabulate_tensor_function_name, | ||
num_program_headers, program_headers, | ||
program_include_names); | ||
|
||
if (nvrtc_err != NVRTC_SUCCESS) { | ||
throw std::runtime_error( | ||
"nvrtcCreateProgram() failed with " + | ||
std::string(nvrtcGetErrorString(nvrtc_err)) + " " | ||
"at " + std::string(__FILE__) + ":" + std::to_string(__LINE__)); | ||
} | ||
|
||
int num_compile_options = 0; | ||
const char** compile_options; | ||
// Compile the CUDA C++ program | ||
nvrtcResult nvrtc_compile_err = nvrtcCompileProgram( | ||
program, num_compile_options, compile_options); | ||
if (nvrtc_compile_err != NVRTC_SUCCESS) { | ||
// If the compiler failed, obtain the compiler log | ||
std::string program_log; | ||
size_t log_size; | ||
nvrtc_err = nvrtcGetProgramLogSize(program, &log_size); | ||
if (nvrtc_err != NVRTC_SUCCESS) { | ||
program_log = std::string( | ||
"nvrtcGetProgramLogSize() failed with " + | ||
std::string(nvrtcGetErrorString(nvrtc_err)) + " " | ||
"at " + std::string(__FILE__) + ":" + std::to_string(__LINE__)); | ||
} else { | ||
program_log.resize(log_size); | ||
nvrtc_err = nvrtcGetProgramLog( | ||
program, const_cast<char*>(program_log.c_str())); | ||
if (nvrtc_err != NVRTC_SUCCESS) { | ||
program_log = std::string( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Std::format? |
||
"nvrtcGetProgramLog() failed with " + | ||
std::string(nvrtcGetErrorString(nvrtc_err))) + " " | ||
"at " + std::string(__FILE__) + ":" + std::to_string(__LINE__); | ||
} | ||
if (log_size > 0) | ||
program_log.resize(log_size-1); | ||
} | ||
nvrtcDestroyProgram(&program); | ||
|
||
std::stringstream ss; | ||
ss << "nvrtcCompileProgram() failed with " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use std::format if you can switch to C++20, removes the need for using C++ terrible string formatting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I tried switching this code to use std::format, however the C++ compiler in Github's CI environment appears to not support c++20 (tests worked locally, but broke during CI on Github). |
||
<< nvrtcGetErrorString(nvrtc_compile_err) << "\n" | ||
<< "CUDA C++ source code:\n" | ||
<< std::string(60, '-') << "\n" | ||
<< program_src | ||
<< std::string(60, '-') << "\n" | ||
<< "NVRTC compiler log:\n" | ||
<< std::string(60, '-') << "\n" | ||
<< program_log << "\n" | ||
<< std::string(60, '-') << "\n"; | ||
throw std::runtime_error(ss.str()); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
std::vector<ufcx_form*> forms = { | ||
form_Components_L, | ||
form_FacetIntegrals_a, | ||
form_HyperElasticity_a_F, form_HyperElasticity_a_J, | ||
form_MathFunctions_a, | ||
form_StabilisedStokes_a, form_StabilisedStokes_L, | ||
form_VectorPoisson_a, form_VectorPoisson_L | ||
}; | ||
|
||
for (ufcx_form* form : forms) check_nvrtc_compilation(form); | ||
|
||
return 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Std::format?