Fix Cycles error with runtime compilation when there is no path to OptiX SDK
If no OPTIX_ROOT is set, nvcc fails to compile because there is a stray "-I" in the arguments. Detect if the include path is empty and act accordingly. Differential Revision: https://developer.blender.org/D16308
This commit is contained in:
committed by
Brecht Van Lommel
parent
5925b1821a
commit
c306ccb67f
@@ -232,7 +232,7 @@ string CUDADevice::compile_kernel_get_common_cflags(const uint kernel_features)
|
||||
return cflags;
|
||||
}
|
||||
|
||||
string CUDADevice::compile_kernel(const uint kernel_features,
|
||||
string CUDADevice::compile_kernel(const string& common_cflags,
|
||||
const char *name,
|
||||
const char *base,
|
||||
bool force_ptx)
|
||||
@@ -281,7 +281,6 @@ string CUDADevice::compile_kernel(const uint kernel_features,
|
||||
/* We include cflags into md5 so changing cuda toolkit or changing other
|
||||
* compiler command line arguments makes sure cubin gets re-built.
|
||||
*/
|
||||
string common_cflags = compile_kernel_get_common_cflags(kernel_features);
|
||||
const string kernel_md5 = util_md5_string(source_md5 + common_cflags);
|
||||
|
||||
const char *const kernel_ext = force_ptx ? "ptx" : "cubin";
|
||||
@@ -417,7 +416,8 @@ bool CUDADevice::load_kernels(const uint kernel_features)
|
||||
|
||||
/* get kernel */
|
||||
const char *kernel_name = "kernel";
|
||||
string cubin = compile_kernel(kernel_features, kernel_name);
|
||||
string cflags = compile_kernel_get_common_cflags(kernel_features);
|
||||
string cubin = compile_kernel(cflags, kernel_name);
|
||||
if (cubin.empty())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -77,9 +77,9 @@ class CUDADevice : public Device {
|
||||
|
||||
bool use_adaptive_compilation();
|
||||
|
||||
virtual string compile_kernel_get_common_cflags(const uint kernel_features);
|
||||
string compile_kernel_get_common_cflags(const uint kernel_features);
|
||||
|
||||
string compile_kernel(const uint kernel_features,
|
||||
string compile_kernel(const string& cflags,
|
||||
const char *name,
|
||||
const char *base = "cuda",
|
||||
bool force_ptx = false);
|
||||
|
||||
@@ -74,7 +74,7 @@ class HIPDevice : public Device {
|
||||
|
||||
bool use_adaptive_compilation();
|
||||
|
||||
virtual string compile_kernel_get_common_cflags(const uint kernel_features);
|
||||
string compile_kernel_get_common_cflags(const uint kernel_features);
|
||||
|
||||
string compile_kernel(const uint kernel_features, const char *name, const char *base = "hip");
|
||||
|
||||
|
||||
@@ -381,13 +381,44 @@ bool OptiXDevice::load_kernels(const uint kernel_features)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Skip creating OptiX module if only doing denoising. */
|
||||
const bool need_optix_kernels = (kernel_features &
|
||||
(KERNEL_FEATURE_PATH_TRACING | KERNEL_FEATURE_BAKING));
|
||||
|
||||
/* Detect existence of OptiX kernel and SDK here early. So we can error out
|
||||
* before compiling the CUDA kernels, to avoid failing right after when
|
||||
* compiling the OptiX kernel. */
|
||||
string ptx_filename;
|
||||
if (need_optix_kernels) {
|
||||
ptx_filename = path_get(
|
||||
(kernel_features & (KERNEL_FEATURE_NODE_RAYTRACE | KERNEL_FEATURE_MNEE)) ?
|
||||
"lib/kernel_optix_shader_raytrace.ptx" :
|
||||
"lib/kernel_optix.ptx");
|
||||
if (use_adaptive_compilation() || path_file_size(ptx_filename) == -1) {
|
||||
std::string optix_include_dir = get_optix_include_dir();
|
||||
if (optix_include_dir.empty()) {
|
||||
set_error(
|
||||
"Unable to compile OptiX kernels at runtime. Set OPTIX_ROOT_DIR environment variable "
|
||||
"to a directory containing the OptiX SDK.");
|
||||
return false;
|
||||
}
|
||||
else if (!path_is_directory(optix_include_dir)) {
|
||||
set_error(string_printf(
|
||||
"OptiX headers not found at %s, unable to compile OptiX kernels at runtime. Install "
|
||||
"OptiX SDK in the specified location, or set OPTIX_ROOT_DIR environment variable to a "
|
||||
"directory containing the OptiX SDK.",
|
||||
optix_include_dir.c_str()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Load CUDA modules because we need some of the utility kernels. */
|
||||
if (!CUDADevice::load_kernels(kernel_features)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Skip creating OptiX module if only doing denoising. */
|
||||
if (!(kernel_features & (KERNEL_FEATURE_PATH_TRACING | KERNEL_FEATURE_BAKING))) {
|
||||
if (!need_optix_kernels) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -469,28 +500,11 @@ bool OptiXDevice::load_kernels(const uint kernel_features)
|
||||
}
|
||||
|
||||
{ /* Load and compile PTX module with OptiX kernels. */
|
||||
string ptx_data, ptx_filename = path_get(
|
||||
(kernel_features & (KERNEL_FEATURE_NODE_RAYTRACE | KERNEL_FEATURE_MNEE)) ?
|
||||
"lib/kernel_optix_shader_raytrace.ptx" :
|
||||
"lib/kernel_optix.ptx");
|
||||
string ptx_data;
|
||||
if (use_adaptive_compilation() || path_file_size(ptx_filename) == -1) {
|
||||
std::string optix_include_dir = get_optix_include_dir();
|
||||
if (optix_include_dir.empty()) {
|
||||
set_error(
|
||||
"Unable to compile OptiX kernels at runtime. Set OPTIX_ROOT_DIR environment variable "
|
||||
"to a directory containing the OptiX SDK.");
|
||||
return false;
|
||||
}
|
||||
else if (!path_is_directory(optix_include_dir)) {
|
||||
set_error(string_printf(
|
||||
"OptiX headers not found at %s, unable to compile OptiX kernels at runtime. Install "
|
||||
"OptiX SDK in the specified location, or set OPTIX_ROOT_DIR environment variable to a "
|
||||
"directory containing the OptiX SDK.",
|
||||
optix_include_dir.c_str()));
|
||||
return false;
|
||||
}
|
||||
string cflags = compile_kernel_get_common_cflags(kernel_features);
|
||||
ptx_filename = compile_kernel(
|
||||
kernel_features,
|
||||
cflags,
|
||||
(kernel_features & (KERNEL_FEATURE_NODE_RAYTRACE | KERNEL_FEATURE_MNEE)) ?
|
||||
"kernel_shader_raytrace" :
|
||||
"kernel",
|
||||
|
||||
@@ -103,7 +103,7 @@ class OptiXDevice : public CUDADevice {
|
||||
private:
|
||||
BVHLayoutMask get_bvh_layout_mask() const override;
|
||||
|
||||
string compile_kernel_get_common_cflags(const uint kernel_features) override;
|
||||
string compile_kernel_get_common_cflags(const uint kernel_features);
|
||||
|
||||
bool load_kernels(const uint kernel_features) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user