diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-08-05 11:57:50 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-08-05 11:57:50 +0400 |
commit | 77b7e1fe9abb882b7bd1d60f5273e03f079d8a54 (patch) | |
tree | 5b23af40e4995e79e584f3ea700f809e7ffbf276 /intern/cycles/device/device_cuda.cpp | |
parent | a3fac84c733f2bf0837dd2719199ee9b76bb7b36 (diff) |
Deduplicate CUDA and OpenCL wranglers
For now it was mainly about OpenCL wrangler being duplicated
between Cycles and Compositor, but with OpenSubdiv work those
wranglers were gonna to be duplicated just once again.
This commit makes it so Cycles and Compositor uses wranglers
from this repositories:
- https://github.com/CudaWrangler/cuew
- https://github.com/OpenCLWrangler/clew
This repositories are based on the wranglers we used before
and they'll be likely continued maintaining by us plus some
more players in the market.
Pretty much straightforward change with some tricks in the
CMake/SCons to make this libs being passed to the linker
after all other libraries in order to make OpenSubdiv linked
against those wranglers in the future.
For those who're worrying about Cycles being less standalone,
it's not truth, it's rather more flexible now and in the future
different wranglers might be used in Cycles. For now it'll
just mean those libs would need to be put into Cycles repository
together with some other libs from Blender such as mikkspace.
This is mainly platform maintenance commit, should not be any
changes to the user space.
Reviewers: juicyfruit, dingto, campbellbarton
Reviewed By: juicyfruit, dingto, campbellbarton
Differential Revision: https://developer.blender.org/D707
Diffstat (limited to 'intern/cycles/device/device_cuda.cpp')
-rw-r--r-- | intern/cycles/device/device_cuda.cpp | 103 |
1 files changed, 35 insertions, 68 deletions
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp index f0f32f87eed..6629069c6c6 100644 --- a/intern/cycles/device/device_cuda.cpp +++ b/intern/cycles/device/device_cuda.cpp @@ -23,7 +23,7 @@ #include "buffers.h" -#include "util_cuda.h" +#include "cuew.h" #include "util_debug.h" #include "util_map.h" #include "util_opengl.h" @@ -61,65 +61,10 @@ public: return (CUdeviceptr)mem; } - static const char *cuda_error_string(CUresult result) + static bool have_precompiled_kernels() { - switch(result) { - case CUDA_SUCCESS: return "No errors"; - case CUDA_ERROR_INVALID_VALUE: return "Invalid value"; - case CUDA_ERROR_OUT_OF_MEMORY: return "Out of memory"; - case CUDA_ERROR_NOT_INITIALIZED: return "Driver not initialized"; - case CUDA_ERROR_DEINITIALIZED: return "Driver deinitialized"; - - case CUDA_ERROR_NO_DEVICE: return "No CUDA-capable device available"; - case CUDA_ERROR_INVALID_DEVICE: return "Invalid device"; - - case CUDA_ERROR_INVALID_IMAGE: return "Invalid kernel image"; - case CUDA_ERROR_INVALID_CONTEXT: return "Invalid context"; - case CUDA_ERROR_MAP_FAILED: return "Map failed"; - case CUDA_ERROR_UNMAP_FAILED: return "Unmap failed"; - case CUDA_ERROR_ARRAY_IS_MAPPED: return "Array is mapped"; - case CUDA_ERROR_ALREADY_MAPPED: return "Already mapped"; - case CUDA_ERROR_NO_BINARY_FOR_GPU: return "No binary for GPU"; - case CUDA_ERROR_ALREADY_ACQUIRED: return "Already acquired"; - case CUDA_ERROR_NOT_MAPPED: return "Not mapped"; - case CUDA_ERROR_NOT_MAPPED_AS_ARRAY: return "Mapped resource not available for access as an array"; - case CUDA_ERROR_NOT_MAPPED_AS_POINTER: return "Mapped resource not available for access as a pointer"; - case CUDA_ERROR_ECC_UNCORRECTABLE: return "Uncorrectable ECC error detected"; - case CUDA_ERROR_UNSUPPORTED_LIMIT: return "CUlimit not supported by device"; - case CUDA_ERROR_CONTEXT_ALREADY_IN_USE: return "Context already in use"; - case CUDA_ERROR_PEER_ACCESS_UNSUPPORTED: return "Peer access unsupported"; - case CUDA_ERROR_INVALID_PTX: return "Invalid PTX code"; - - case CUDA_ERROR_INVALID_SOURCE: return "Invalid source"; - case CUDA_ERROR_FILE_NOT_FOUND: return "File not found"; - case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: return "Link to a shared object failed to resolve"; - case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: return "Shared object initialization failed"; - case CUDA_ERROR_OPERATING_SYSTEM: return "OS call failed"; - - case CUDA_ERROR_INVALID_HANDLE: return "Invalid handle"; - - case CUDA_ERROR_NOT_FOUND: return "Not found"; - - case CUDA_ERROR_NOT_READY: return "CUDA not ready"; - - case CUDA_ERROR_ILLEGAL_ADDRESS: return "Illegal address"; - case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: return "Launch exceeded resources"; - case CUDA_ERROR_LAUNCH_TIMEOUT: return "Launch exceeded time out"; - case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: return "Launch with incompatible texturing"; - case CUDA_ERROR_HARDWARE_STACK_ERROR: return "Stack error"; - case CUDA_ERROR_ILLEGAL_INSTRUCTION: return "Illegal instruction"; - case CUDA_ERROR_MISALIGNED_ADDRESS: return "Misaligned address"; - case CUDA_ERROR_INVALID_ADDRESS_SPACE: return "Invalid address space"; - case CUDA_ERROR_INVALID_PC: return "Invalid program counter"; - case CUDA_ERROR_LAUNCH_FAILED: return "Launch failed"; - - case CUDA_ERROR_NOT_PERMITTED: return "Operation not permitted"; - case CUDA_ERROR_NOT_SUPPORTED: return "Operation not supported"; - - case CUDA_ERROR_UNKNOWN: return "Unknown error"; - - default: return "Unknown CUDA error value"; - } + string cubins_path = path_get("lib"); + return path_exists(cubins_path); } /*#ifdef NDEBUG @@ -141,7 +86,7 @@ public: CUresult result = stmt; \ \ if(result != CUDA_SUCCESS) { \ - string message = string_printf("CUDA error: %s in %s", cuda_error_string(result), #stmt); \ + string message = string_printf("CUDA error: %s in %s", cuewErrorString(result), #stmt); \ if(error_msg == "") \ error_msg = message; \ fprintf(stderr, "%s\n", message.c_str()); \ @@ -155,7 +100,7 @@ public: if(result == CUDA_SUCCESS) return false; - string message = string_printf("CUDA error at %s: %s", stmt.c_str(), cuda_error_string(result)); + string message = string_printf("CUDA error at %s: %s", stmt.c_str(), cuewErrorString(result)); if(error_msg == "") error_msg = message; fprintf(stderr, "%s\n", message.c_str()); @@ -275,7 +220,7 @@ public: return cubin; #ifdef _WIN32 - if(cuHavePrecompiledKernels()) { + if(have_precompiled_kernels()) { if(major < 2) cuda_error_message(string_printf("CUDA device requires compute capability 2.0 or up, found %d.%d. Your GPU is not supported.", major, minor)); else @@ -285,14 +230,14 @@ public: #endif /* if not, find CUDA compiler */ - string nvcc = cuCompilerPath(); + const char *nvcc = cuewCompilerPath(); - if(nvcc == "") { + if(nvcc == NULL) { cuda_error_message("CUDA nvcc compiler not found. Install CUDA toolkit in default location."); return ""; } - int cuda_version = cuCompilerVersion(); + int cuda_version = cuewCompilerVersion(); if(cuda_version == 0) { cuda_error_message("CUDA nvcc compiler version could not be parsed."); @@ -317,7 +262,7 @@ public: string command = string_printf("\"%s\" -arch=sm_%d%d -m%d --cubin \"%s\" " "-o \"%s\" --ptxas-options=\"-v\" -I\"%s\" -DNVCC -D__KERNEL_CUDA_VERSION__=%d", - nvcc.c_str(), major, minor, machine, kernel.c_str(), cubin.c_str(), include.c_str(), cuda_version); + nvcc, major, minor, machine, kernel.c_str(), cubin.c_str(), include.c_str(), cuda_version); printf("%s\n", command.c_str()); @@ -1050,6 +995,28 @@ public: } }; +bool device_cuda_init(void) +{ + static bool initialized = false; + static bool result = false; + + if (initialized) + return result; + + initialized = true; + + if (cuewInit() == CUEW_SUCCESS) { + if(CUDADevice::have_precompiled_kernels()) + result = true; +#ifndef _WIN32 + else if(cuewCompilerPath() != NULL) + result = true; +#endif + } + + return result; +} + Device *device_cuda_create(DeviceInfo& info, Stats &stats, bool background) { return new CUDADevice(info, stats, background); @@ -1063,13 +1030,13 @@ void device_cuda_info(vector<DeviceInfo>& devices) result = cuInit(0); if(result != CUDA_SUCCESS) { if(result != CUDA_ERROR_NO_DEVICE) - fprintf(stderr, "CUDA cuInit: %s\n", CUDADevice::cuda_error_string(result)); + fprintf(stderr, "CUDA cuInit: %s\n", cuewErrorString(result)); return; } result = cuDeviceGetCount(&count); if(result != CUDA_SUCCESS) { - fprintf(stderr, "CUDA cuDeviceGetCount: %s\n", CUDADevice::cuda_error_string(result)); + fprintf(stderr, "CUDA cuDeviceGetCount: %s\n", cuewErrorString(result)); return; } |