diff options
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | intern/cycles/CMakeLists.txt | 5 | ||||
-rw-r--r-- | intern/cycles/cmake/external_libs.cmake | 13 | ||||
-rw-r--r-- | intern/cycles/device/device_cuda.cpp | 5 | ||||
-rw-r--r-- | intern/cycles/kernel/CMakeLists.txt | 26 | ||||
-rw-r--r-- | intern/cycles/util/util_cuda.cpp | 16 |
6 files changed, 68 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bc6cab1dc5..3b328669e48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,8 +214,10 @@ endif() option(WITH_PYTHON_INSTALL "Copy system python into the blender install folder" ON) # Cycles -option(WITH_CYCLES "Enable Cycles Render Engine" ON) -OPTION(WITH_CYCLES_TEST "Build cycles test application" OFF) +option(WITH_CYCLES "Enable cycles Render Engine" ON) +option(WITH_CYCLES_TEST "Build cycles test application" OFF) +option(WITH_CYCLES_CUDA_BINARIES "Build cycles CUDA binaries" OFF) +set(CYCLES_CUDA_BINARIES_ARCH sm_13 sm_20 sm_21 CACHE STRING "CUDA architectures to build binaries for") # disable for now, but plan to support on all platforms eventually option(WITH_MEM_JEMALLOC "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF) diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt index bb876a90a7c..86fb6e49e33 100644 --- a/intern/cycles/CMakeLists.txt +++ b/intern/cycles/CMakeLists.txt @@ -49,6 +49,10 @@ if(WITH_CYCLES_PARTIO) add_definitions(-DWITH_PARTIO) endif() +if(WITH_CYCLES_CUDA_BINARIES) + add_definitions(-DWITH_CUDA_BINARIES) +endif() + add_definitions(-DWITH_OPENCL) add_definitions(-DWITH_CUDA) add_definitions(-DWITH_MULTI) @@ -72,3 +76,4 @@ add_subdirectory(kernel) add_subdirectory(render) add_subdirectory(subd) add_subdirectory(util) + diff --git a/intern/cycles/cmake/external_libs.cmake b/intern/cycles/cmake/external_libs.cmake index b6b8b351e13..9037362f1ab 100644 --- a/intern/cycles/cmake/external_libs.cmake +++ b/intern/cycles/cmake/external_libs.cmake @@ -85,3 +85,16 @@ if(WITH_CYCLES_BLENDER) add_definitions(-DBLENDER_PLUGIN) endif() +########################################################################### +# CUDA + +if(WITH_CYCLES_CUDA_BINARIES) + find_package(CUDA) # Try to auto locate CUDA toolkit + if(CUDA_FOUND) + message(STATUS "CUDA nvcc = ${CUDA_NVCC_EXECUTABLE}") + else() + message(STATUS "CUDA compiler not found, disabling WITH_CYCLES_CUDA_BINARIES") + set(WITH_CYCLES_CUDA_BINARIES OFF) + endif() +endif() + diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp index 14c2a765a8e..1158cc6c77c 100644 --- a/intern/cycles/device/device_cuda.cpp +++ b/intern/cycles/device/device_cuda.cpp @@ -223,6 +223,10 @@ public: if(path_exists(cubin)) return cubin; +#ifdef WITH_CUDA_BINARIES + fprintf(stderr, "CUDA binary kernel for this graphics card not found.\n"); + return ""; +#else /* if not, find CUDA compiler */ string nvcc = cuCompilerPath(); @@ -260,6 +264,7 @@ public: printf("Kernel compilation finished in %.2lfs.\n", time_dt() - starttime); return cubin; +#endif } bool load_kernels() diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index 3a06aecdfcf..614391bd3f2 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -83,6 +83,32 @@ set(SRC_UTIL_HEADERS ../util/util_transform.h ../util/util_types.h ) +# CUDA module + +if(WITH_CYCLES_CUDA_BINARIES) + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + set(CUDA_BITS 64) + else() + set(CUDA_BITS 32) + endif() + + set(cuda_sources kernel.cu ${headers} ${svm_headers}) + set(cuda_cubins) + + foreach(arch ${CYCLES_CUDA_BINARIES_ARCH}) + set(cuda_cubin kernel_${arch}.cubin) + + add_custom_command( + OUTPUT ${cuda_cubin} + COMMAND ${CUDA_NVCC_EXECUTABLE} -arch=${arch} -m${CUDA_BITS} --cubin ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cu --use_fast_math -o ${CMAKE_CURRENT_BINARY_DIR}/${cuda_cubin} --ptxas-options="-v" --maxrregcount=24 --opencc-options -OPT:Olimit=0 -I${CMAKE_CURRENT_SOURCE_DIR}/../util -I${CMAKE_CURRENT_SOURCE_DIR}/svm -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DNVCC + DEPENDS ${cuda_sources}) + + delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib) + list(APPEND cuda_cubins ${cuda_cubin}) + endforeach() + + add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins}) +endif() # OSL module diff --git a/intern/cycles/util/util_cuda.cpp b/intern/cycles/util/util_cuda.cpp index bd5583b9718..fdf3d664a11 100644 --- a/intern/cycles/util/util_cuda.cpp +++ b/intern/cycles/util/util_cuda.cpp @@ -373,8 +373,14 @@ bool cuLibraryInit() /* cuda 4.0 */ CUDA_LIBRARY_FIND(cuCtxSetCurrent); +#ifndef WITH_CUDA_BINARIES +#ifdef _WIN32 + return false; /* runtime build doesn't work at the moment */ +#else if(cuCompilerPath() == "") return false; +#endif +#endif /* success */ result = true; @@ -401,7 +407,15 @@ string cuCompilerPath() else nvcc = path_join(defaultpath, executable); - return (path_exists(nvcc))? nvcc: ""; + if(path_exists(nvcc)) + return nvcc; + +#ifndef _WIN32 + if(system("which nvcc") == 0) + return "nvcc"; +#endif + + return ""; } CCL_NAMESPACE_END |