diff options
Diffstat (limited to 'intern/cycles/device')
-rw-r--r-- | intern/cycles/device/CMakeLists.txt | 10 | ||||
-rw-r--r-- | intern/cycles/device/cpu/device_impl.cpp | 1 | ||||
-rw-r--r-- | intern/cycles/device/cpu/device_impl.h | 1 | ||||
-rw-r--r-- | intern/cycles/device/cpu/kernel_thread_globals.cpp | 7 | ||||
-rw-r--r-- | intern/cycles/device/hip/device_impl.cpp | 1 | ||||
-rw-r--r-- | intern/cycles/device/oneapi/device.cpp | 6 | ||||
-rw-r--r-- | intern/cycles/device/oneapi/device_impl.cpp | 36 | ||||
-rw-r--r-- | intern/cycles/device/oneapi/device_impl.h | 1 | ||||
-rw-r--r-- | intern/cycles/device/optix/device_impl.cpp | 39 |
9 files changed, 63 insertions, 39 deletions
diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt index 6418801c572..24855d795d1 100644 --- a/intern/cycles/device/CMakeLists.txt +++ b/intern/cycles/device/CMakeLists.txt @@ -3,12 +3,9 @@ set(INC .. - ../../glew-mx ) -set(INC_SYS - ${GLEW_INCLUDE_DIR} -) +set(INC_SYS ) if(WITH_CYCLES_DEVICE_OPTIX OR WITH_CYCLES_DEVICE_CUDA) if(WITH_CUDA_DYNLOAD) @@ -22,6 +19,8 @@ if(WITH_CYCLES_DEVICE_OPTIX OR WITH_CYCLES_DEVICE_CUDA) ) add_definitions(-DCYCLES_CUDA_NVCC_EXECUTABLE="${CUDA_NVCC_EXECUTABLE}") endif() + + add_definitions(-DCYCLES_RUNTIME_OPTIX_ROOT_DIR="${CYCLES_RUNTIME_OPTIX_ROOT_DIR}") endif() if(WITH_CYCLES_DEVICE_HIP AND WITH_HIP_DYNLOAD) @@ -150,7 +149,6 @@ set(SRC set(LIB cycles_kernel cycles_util - ${CYCLES_GL_LIBRARIES} ) if(WITH_CYCLES_DEVICE_OPTIX OR WITH_CYCLES_DEVICE_CUDA) @@ -171,8 +169,6 @@ if(WITH_CYCLES_DEVICE_HIP AND WITH_HIP_DYNLOAD) ) endif() -add_definitions(${GL_DEFINITIONS}) - if(WITH_CYCLES_DEVICE_CUDA) add_definitions(-DWITH_CUDA) endif() diff --git a/intern/cycles/device/cpu/device_impl.cpp b/intern/cycles/device/cpu/device_impl.cpp index 1e4b9baa0c0..a2b8d1cbbfa 100644 --- a/intern/cycles/device/cpu/device_impl.cpp +++ b/intern/cycles/device/cpu/device_impl.cpp @@ -28,7 +28,6 @@ #include "kernel/device/cpu/kernel.h" #include "kernel/types.h" -#include "kernel/osl/shader.h" #include "kernel/osl/globals.h" // clang-format on diff --git a/intern/cycles/device/cpu/device_impl.h b/intern/cycles/device/cpu/device_impl.h index 5c1f3cc6ce5..e7e77f18194 100644 --- a/intern/cycles/device/cpu/device_impl.h +++ b/intern/cycles/device/cpu/device_impl.h @@ -23,7 +23,6 @@ #include "kernel/device/cpu/kernel.h" #include "kernel/device/cpu/globals.h" -#include "kernel/osl/shader.h" #include "kernel/osl/globals.h" // clang-format on diff --git a/intern/cycles/device/cpu/kernel_thread_globals.cpp b/intern/cycles/device/cpu/kernel_thread_globals.cpp index 89545399602..99af1525d92 100644 --- a/intern/cycles/device/cpu/kernel_thread_globals.cpp +++ b/intern/cycles/device/cpu/kernel_thread_globals.cpp @@ -3,10 +3,7 @@ #include "device/cpu/kernel_thread_globals.h" -// clang-format off -#include "kernel/osl/shader.h" #include "kernel/osl/globals.h" -// clang-format on #include "util/profiling.h" @@ -20,7 +17,7 @@ CPUKernelThreadGlobals::CPUKernelThreadGlobals(const KernelGlobalsCPU &kernel_gl reset_runtime_memory(); #ifdef WITH_OSL - OSLShader::thread_init(this, reinterpret_cast<OSLGlobals *>(osl_globals_memory)); + OSLGlobals::thread_init(this, static_cast<OSLGlobals *>(osl_globals_memory)); #else (void)osl_globals_memory; #endif @@ -35,7 +32,7 @@ CPUKernelThreadGlobals::CPUKernelThreadGlobals(CPUKernelThreadGlobals &&other) n CPUKernelThreadGlobals::~CPUKernelThreadGlobals() { #ifdef WITH_OSL - OSLShader::thread_free(this); + OSLGlobals::thread_free(this); #endif } diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index 82db55ea715..a84f1edd70e 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -16,7 +16,6 @@ # include "util/log.h" # include "util/map.h" # include "util/md5.h" -# include "util/opengl.h" # include "util/path.h" # include "util/string.h" # include "util/system.h" diff --git a/intern/cycles/device/oneapi/device.cpp b/intern/cycles/device/oneapi/device.cpp index 8056c204188..4aa307e9300 100644 --- a/intern/cycles/device/oneapi/device.cpp +++ b/intern/cycles/device/oneapi/device.cpp @@ -25,10 +25,12 @@ static OneAPIDLLInterface oneapi_dll; #ifdef _WIN32 # define LOAD_ONEAPI_SHARED_LIBRARY(path) (void *)(LoadLibrary(path)) +# define LOAD_ONEAPI_SHARED_LIBRARY_ERROR() GetLastError() # define FREE_SHARED_LIBRARY(handle) FreeLibrary((HMODULE)handle) # define GET_SHARED_LIBRARY_SYMBOL(handle, name) GetProcAddress((HMODULE)handle, name) #elif __linux__ # define LOAD_ONEAPI_SHARED_LIBRARY(path) dlopen(path, RTLD_NOW) +# define LOAD_ONEAPI_SHARED_LIBRARY_ERROR() dlerror() # define FREE_SHARED_LIBRARY(handle) dlclose(handle) # define GET_SHARED_LIBRARY_SYMBOL(handle, name) dlsym(handle, name) #endif @@ -49,8 +51,8 @@ bool device_oneapi_init() /* This shouldn't happen, but it still makes sense to have a branch for this. */ if (lib_handle == NULL) { - LOG(ERROR) << "oneAPI kernel shared library cannot be loaded for some reason. This should not " - "happen, however, it occurs hence oneAPI rendering will be disabled"; + LOG(ERROR) << "oneAPI kernel shared library cannot be loaded: " + << LOAD_ONEAPI_SHARED_LIBRARY_ERROR(); return false; } diff --git a/intern/cycles/device/oneapi/device_impl.cpp b/intern/cycles/device/oneapi/device_impl.cpp index bdcc15bba56..dd0622a5bd5 100644 --- a/intern/cycles/device/oneapi/device_impl.cpp +++ b/intern/cycles/device/oneapi/device_impl.cpp @@ -65,6 +65,8 @@ OneapiDevice::OneapiDevice(const DeviceInfo &info, kg_memory_device_ = oneapi_dll_.oneapi_usm_alloc_device(device_queue_, globals_segment_size); kg_memory_size_ = globals_segment_size; + + max_memory_on_device_ = oneapi_dll_.oneapi_get_memcapacity(device_queue_); } OneapiDevice::~OneapiDevice() @@ -134,17 +136,16 @@ void OneapiDevice::generic_alloc(device_memory &mem) * because Cycles already uses two different pointer for host activity and device activity, and * also has to perform all needed memory transfer operations. So, USM device memory * type has been used for oneAPI device in order to better fit in Cycles architecture. */ - void *device_pointer = oneapi_dll_.oneapi_usm_alloc_device(device_queue_, memory_size); + void *device_pointer = nullptr; + if (mem.memory_size() + stats.mem_used < max_memory_on_device_) + device_pointer = oneapi_dll_.oneapi_usm_alloc_device(device_queue_, memory_size); if (device_pointer == nullptr) { - size_t max_memory_on_device = oneapi_dll_.oneapi_get_memcapacity(device_queue_); set_error("oneAPI kernel - device memory allocation error for " + string_human_readable_size(mem.memory_size()) + ", possibly caused by lack of available memory space on the device: " + string_human_readable_size(stats.mem_used) + " of " + - string_human_readable_size(max_memory_on_device) + " is already allocated"); - return; + string_human_readable_size(max_memory_on_device_) + " is already allocated"); } - assert(device_pointer); mem.device_pointer = reinterpret_cast<ccl::device_ptr>(device_pointer); mem.device_size = memory_size; @@ -154,6 +155,9 @@ void OneapiDevice::generic_alloc(device_memory &mem) void OneapiDevice::generic_copy_to(device_memory &mem) { + if (!mem.device_pointer) { + return; + } size_t memory_size = mem.memory_size(); /* Copy operation from host shouldn't be requested if there is no memory allocated on host. */ @@ -186,7 +190,10 @@ void *OneapiDevice::kernel_globals_device_pointer() void OneapiDevice::generic_free(device_memory &mem) { - assert(mem.device_pointer); + if (!mem.device_pointer) { + return; + } + stats.mem_free(mem.device_size); mem.device_size = 0; @@ -256,14 +263,15 @@ void OneapiDevice::mem_copy_from(device_memory &mem, size_t y, size_t w, size_t assert(device_queue_); assert(size != 0); - assert(mem.device_pointer); - char *shifted_host = reinterpret_cast<char *>(mem.host_pointer) + offset; - char *shifted_device = reinterpret_cast<char *>(mem.device_pointer) + offset; - bool is_finished_ok = oneapi_dll_.oneapi_usm_memcpy( - device_queue_, shifted_host, shifted_device, size); - if (is_finished_ok == false) { - set_error("oneAPI memory operation error: got runtime exception \"" + oneapi_error_string_ + - "\""); + if (mem.device_pointer) { + char *shifted_host = reinterpret_cast<char *>(mem.host_pointer) + offset; + char *shifted_device = reinterpret_cast<char *>(mem.device_pointer) + offset; + bool is_finished_ok = oneapi_dll_.oneapi_usm_memcpy( + device_queue_, shifted_host, shifted_device, size); + if (is_finished_ok == false) { + set_error("oneAPI memory operation error: got runtime exception \"" + + oneapi_error_string_ + "\""); + } } } } diff --git a/intern/cycles/device/oneapi/device_impl.h b/intern/cycles/device/oneapi/device_impl.h index a0a747a3cf2..6abebf98684 100644 --- a/intern/cycles/device/oneapi/device_impl.h +++ b/intern/cycles/device/oneapi/device_impl.h @@ -24,6 +24,7 @@ class OneapiDevice : public Device { void *kg_memory_; void *kg_memory_device_; size_t kg_memory_size_ = (size_t)0; + size_t max_memory_on_device_ = (size_t)0; OneAPIDLLInterface oneapi_dll_; std::string oneapi_error_string_; diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp index 94a46acaf18..6c64e7106d5 100644 --- a/intern/cycles/device/optix/device_impl.cpp +++ b/intern/cycles/device/optix/device_impl.cpp @@ -342,15 +342,29 @@ BVHLayoutMask OptiXDevice::get_bvh_layout_mask() const return BVH_LAYOUT_OPTIX; } +static string get_optix_include_dir() +{ + const char *env_dir = getenv("OPTIX_ROOT_DIR"); + const char *default_dir = CYCLES_RUNTIME_OPTIX_ROOT_DIR; + + if (env_dir && env_dir[0]) { + const string env_include_dir = path_join(env_dir, "include"); + return env_include_dir; + } + else if (default_dir[0]) { + const string default_include_dir = path_join(default_dir, "include"); + return default_include_dir; + } + + return string(); +} + string OptiXDevice::compile_kernel_get_common_cflags(const uint kernel_features) { string common_cflags = CUDADevice::compile_kernel_get_common_cflags(kernel_features); /* Add OptiX SDK include directory to include paths. */ - const char *optix_sdk_path = getenv("OPTIX_ROOT_DIR"); - if (optix_sdk_path) { - common_cflags += string_printf(" -I\"%s/include\"", optix_sdk_path); - } + common_cflags += string_printf(" -I\"%s\"", get_optix_include_dir().c_str()); /* Specialization for shader raytracing. */ if (kernel_features & KERNEL_FEATURE_NODE_RAYTRACE) { @@ -460,10 +474,19 @@ bool OptiXDevice::load_kernels(const uint kernel_features) "lib/kernel_optix_shader_raytrace.ptx" : "lib/kernel_optix.ptx"); if (use_adaptive_compilation() || path_file_size(ptx_filename) == -1) { - if (!getenv("OPTIX_ROOT_DIR")) { + std::string optix_include_dir = get_optix_include_dir(); + if (optix_include_dir.empty()) { set_error( - "Missing OPTIX_ROOT_DIR environment variable (which must be set with the path to " - "the Optix SDK to be able to compile Optix kernels on demand)."); + "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; } ptx_filename = compile_kernel( @@ -1393,7 +1416,7 @@ bool OptiXDevice::build_optix_bvh(BVHOptiX *bvh, options.operation = operation; if (use_fast_trace_bvh || /* The build flags have to match the ones used to query the built-in curve intersection - program (see optixBuiltinISModuleGet above) */ + * program (see optixBuiltinISModuleGet above) */ build_input.type == OPTIX_BUILD_INPUT_TYPE_CURVES) { VLOG_INFO << "Using fast to trace OptiX BVH"; options.buildFlags = OPTIX_BUILD_FLAG_PREFER_FAST_TRACE | OPTIX_BUILD_FLAG_ALLOW_COMPACTION; |