From c42772fc95d62b4cb67e2ca09e5928ef7a6e054d Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 10 Nov 2011 12:52:17 +0000 Subject: Cycles: * Add back option to bundle CUDA kernel binaries with builds. * Disable runtime CUDA kernel compilation on Windows, couldn't get this working, since it seems to depend on visual studio being installed, even though for this particular case it shouldn't be needed. CMake only at the moment. * Runtime compilation on linux/mac should now work if nvcc is not installed in the default location, but available in PATH. --- intern/cycles/CMakeLists.txt | 5 +++++ intern/cycles/cmake/external_libs.cmake | 13 +++++++++++++ intern/cycles/device/device_cuda.cpp | 5 +++++ intern/cycles/kernel/CMakeLists.txt | 26 ++++++++++++++++++++++++++ intern/cycles/util/util_cuda.cpp | 16 +++++++++++++++- 5 files changed, 64 insertions(+), 1 deletion(-) (limited to 'intern/cycles') 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 -- cgit v1.2.3