Cycles:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 10 Nov 2011 12:52:17 +0000 (12:52 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 10 Nov 2011 12:52:17 +0000 (12:52 +0000)
* 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.

CMakeLists.txt
intern/cycles/CMakeLists.txt
intern/cycles/cmake/external_libs.cmake
intern/cycles/device/device_cuda.cpp
intern/cycles/kernel/CMakeLists.txt
intern/cycles/util/util_cuda.cpp

index 4bc6cab1dc5e047afb8cfdb2b782331d064262a7..3b328669e48b3059107ae396d86f125fa62a0120 100644 (file)
@@ -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)
index bb876a90a7c8aaa9d606bbad8587b5663de87210..86fb6e49e33411a7bd9902d80433deddc0ca309b 100644 (file)
@@ -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)
+
index b6b8b351e13e0c82e13ef7a85f140bee807b3ac4..9037362f1ab9eef6738a03bdc1280fb38e4e21aa 100644 (file)
@@ -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()
+
index 14c2a765a8eab700b2614cbce5dd498a41751198..1158cc6c77cd864194dae9bd58afbf96266226b8 100644 (file)
@@ -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()
index 3a06aecdfcfd7b5a1cf1fd06df2b9ea63db75b74..614391bd3f2413b1221a96b94648282342af65d2 100644 (file)
@@ -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
 
index bd5583b9718005af47363999add3e49cc89b0479..fdf3d664a11563c1364952816085b41ffb7914b7 100644 (file)
@@ -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