Cycles: Make CUDA 7.5 officially recommended
[blender-staging.git] / intern / cycles / kernel / CMakeLists.txt
1 remove_extra_strict_flags()
2
3 set(INC
4         .
5         ../util
6         osl
7         svm
8 )
9
10 set(INC_SYS
11
12 )
13
14 set(SRC
15         kernels/cpu/kernel.cpp
16         kernels/opencl/kernel.cl
17         kernels/opencl/kernel_data_init.cl
18         kernels/opencl/kernel_queue_enqueue.cl
19         kernels/opencl/kernel_scene_intersect.cl
20         kernels/opencl/kernel_lamp_emission.cl
21         kernels/opencl/kernel_background_buffer_update.cl
22         kernels/opencl/kernel_shader_eval.cl
23         kernels/opencl/kernel_holdout_emission_blurring_pathtermination_ao.cl
24         kernels/opencl/kernel_direct_lighting.cl
25         kernels/opencl/kernel_shadow_blocked.cl
26         kernels/opencl/kernel_next_iteration_setup.cl
27         kernels/opencl/kernel_sum_all_radiance.cl
28         kernels/cuda/kernel.cu
29 )
30
31 set(SRC_HEADERS
32         kernel_accumulate.h
33         kernel_bake.h
34         kernel_camera.h
35         kernel_compat_cpu.h
36         kernel_compat_cuda.h
37         kernel_compat_opencl.h
38         kernel_debug.h
39         kernel_differential.h
40         kernel_emission.h
41         kernel_film.h
42         kernel_globals.h
43         kernel_jitter.h
44         kernel_light.h
45         kernel_math.h
46         kernel_montecarlo.h
47         kernel_passes.h
48         kernel_path.h
49         kernel_path_branched.h
50         kernel_path_common.h
51         kernel_path_state.h
52         kernel_path_surface.h
53         kernel_path_volume.h
54         kernel_projection.h
55         kernel_queues.h
56         kernel_random.h
57         kernel_shader.h
58         kernel_shadow.h
59         kernel_subsurface.h
60         kernel_textures.h
61         kernel_types.h
62         kernel_volume.h
63         kernel_work_stealing.h
64 )
65
66 set(SRC_KERNELS_CPU_HEADERS
67         kernel.h
68         kernels/cpu/kernel_cpu.h
69         kernels/cpu/kernel_cpu_impl.h
70 )
71
72 set(SRC_CLOSURE_HEADERS
73         closure/bsdf.h
74         closure/bsdf_ashikhmin_velvet.h
75         closure/bsdf_diffuse.h
76         closure/bsdf_diffuse_ramp.h
77         closure/bsdf_microfacet.h
78         closure/bsdf_oren_nayar.h
79         closure/bsdf_phong_ramp.h
80         closure/bsdf_reflection.h
81         closure/bsdf_refraction.h
82         closure/bsdf_toon.h
83         closure/bsdf_transparent.h
84         closure/bsdf_util.h
85         closure/bsdf_ashikhmin_shirley.h
86         closure/bsdf_hair.h
87         closure/bssrdf.h
88         closure/emissive.h
89         closure/volume.h
90 )
91
92 set(SRC_SVM_HEADERS
93         svm/svm.h
94         svm/svm_attribute.h
95         svm/svm_blackbody.h
96         svm/svm_camera.h
97         svm/svm_closure.h
98         svm/svm_convert.h
99         svm/svm_checker.h
100         svm/svm_brick.h
101         svm/svm_displace.h
102         svm/svm_fresnel.h
103         svm/svm_wireframe.h
104         svm/svm_wavelength.h
105         svm/svm_gamma.h
106         svm/svm_brightness.h
107         svm/svm_geometry.h
108         svm/svm_gradient.h
109         svm/svm_hsv.h
110         svm/svm_image.h
111         svm/svm_invert.h
112         svm/svm_light_path.h
113         svm/svm_magic.h
114         svm/svm_mapping.h
115         svm/svm_math.h
116         svm/svm_math_util.h
117         svm/svm_mix.h
118         svm/svm_musgrave.h
119         svm/svm_noise.h
120         svm/svm_noisetex.h
121         svm/svm_normal.h
122         svm/svm_ramp.h
123         svm/svm_sepcomb_hsv.h
124         svm/svm_sepcomb_vector.h
125         svm/svm_sky.h
126         svm/svm_tex_coord.h
127         svm/svm_texture.h
128         svm/svm_types.h
129         svm/svm_value.h
130         svm/svm_vector_transform.h
131         svm/svm_voronoi.h
132         svm/svm_voxel.h
133         svm/svm_wave.h
134 )
135
136 set(SRC_GEOM_HEADERS
137         geom/geom.h
138         geom/geom_attribute.h
139         geom/geom_bvh.h
140         geom/geom_bvh_shadow.h
141         geom/geom_bvh_subsurface.h
142         geom/geom_bvh_traversal.h
143         geom/geom_bvh_volume.h
144         geom/geom_bvh_volume_all.h
145         geom/geom_curve.h
146         geom/geom_motion_curve.h
147         geom/geom_motion_triangle.h
148         geom/geom_object.h
149         geom/geom_primitive.h
150         geom/geom_qbvh.h
151         geom/geom_qbvh_shadow.h
152         geom/geom_qbvh_subsurface.h
153         geom/geom_qbvh_traversal.h
154         geom/geom_qbvh_volume.h
155         geom/geom_qbvh_volume_all.h
156         geom/geom_triangle.h
157         geom/geom_triangle_intersect.h
158         geom/geom_volume.h
159 )
160
161 set(SRC_UTIL_HEADERS
162         ../util/util_atomic.h
163         ../util/util_color.h
164         ../util/util_half.h
165         ../util/util_math.h
166         ../util/util_math_fast.h
167         ../util/util_transform.h
168         ../util/util_types.h
169 )
170
171 set(SRC_SPLIT_HEADERS
172         split/kernel_background_buffer_update.h
173         split/kernel_data_init.h
174         split/kernel_direct_lighting.h
175         split/kernel_holdout_emission_blurring_pathtermination_ao.h
176         split/kernel_lamp_emission.h
177         split/kernel_next_iteration_setup.h
178         split/kernel_scene_intersect.h
179         split/kernel_shader_eval.h
180         split/kernel_shadow_blocked.h
181         split/kernel_split_common.h
182         split/kernel_sum_all_radiance.h
183 )
184
185 # CUDA module
186
187 if(WITH_CYCLES_CUDA_BINARIES)
188         # 32 bit or 64 bit
189         if(CUDA_64_BIT_DEVICE_CODE)
190                 set(CUDA_BITS 64)
191         else()
192                 set(CUDA_BITS 32)
193         endif()
194
195         # CUDA version
196         execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
197         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT})
198         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT})
199         set(CUDA_VERSION "${CUDA_VERSION_MAJOR}${CUDA_VERSION_MINOR}")
200
201         # warn for other versions
202         if(CUDA_VERSION MATCHES "75")
203         else()
204                 message(WARNING
205                         "CUDA version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} detected, "
206                         "build may succeed but only CUDA 7.5 is officially supported")
207         endif()
208
209         # build for each arch
210         set(cuda_sources kernels/cuda/kernel.cu ${SRC_HEADERS} ${SRC_SVM_HEADERS} ${SRC_GEOM_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_UTIL_HEADERS})
211         set(cuda_cubins)
212
213         macro(CYCLES_CUDA_KERNEL_ADD arch experimental)
214                 if(${experimental})
215                         set(cuda_extra_flags "-D__KERNEL_EXPERIMENTAL__")
216                         set(cuda_cubin kernel_experimental_${arch}.cubin)
217                 else()
218                         set(cuda_extra_flags "")
219                         set(cuda_cubin kernel_${arch}.cubin)
220                 endif()
221
222                 if(WITH_CYCLES_DEBUG)
223                         set(cuda_debug_flags "-D__KERNEL_DEBUG__")
224                 else()
225                         set(cuda_debug_flags "")
226                 endif()
227
228                 set(cuda_version_flags "-D__KERNEL_CUDA_VERSION__=${CUDA_VERSION}")
229                 set(cuda_math_flags "--use_fast_math")
230
231                 add_custom_command(
232                         OUTPUT ${cuda_cubin}
233                         COMMAND ${CUDA_NVCC_EXECUTABLE}
234                                         -arch=${arch}
235                                         -m${CUDA_BITS}
236                                         --cubin ${CMAKE_CURRENT_SOURCE_DIR}/kernels/cuda/kernel.cu
237                                         -o ${CMAKE_CURRENT_BINARY_DIR}/${cuda_cubin}
238                                         --ptxas-options="-v"
239                                         ${cuda_arch_flags}
240                                         ${cuda_version_flags}
241                                         ${cuda_math_flags}
242                                         ${cuda_extra_flags}
243                                         ${cuda_debug_flags}
244                                         -I${CMAKE_CURRENT_SOURCE_DIR}/../util
245                                         -I${CMAKE_CURRENT_SOURCE_DIR}/svm
246                                         -DCCL_NAMESPACE_BEGIN=
247                                         -DCCL_NAMESPACE_END=
248                                         -DNVCC
249
250                         DEPENDS ${cuda_sources})
251
252                 delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib)
253                 list(APPEND cuda_cubins ${cuda_cubin})
254
255                 unset(cuda_extra_flags)
256                 unset(cuda_debug_flags)
257         endmacro()
258
259         foreach(arch ${CYCLES_CUDA_BINARIES_ARCH})
260                 # Compile regular kernel
261                 CYCLES_CUDA_KERNEL_ADD(${arch} FALSE)
262         endforeach()
263
264         add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
265 endif()
266
267 # OSL module
268
269 if(WITH_CYCLES_OSL)
270         add_subdirectory(osl)
271         add_subdirectory(shaders)
272 endif()
273
274 # CPU module
275
276 include_directories(${INC})
277 include_directories(SYSTEM ${INC_SYS})
278
279 if(CXX_HAS_SSE)
280         list(APPEND SRC
281                 kernels/cpu/kernel_sse2.cpp
282                 kernels/cpu/kernel_sse3.cpp
283                 kernels/cpu/kernel_sse41.cpp
284         )
285
286         set_source_files_properties(kernels/cpu/kernel_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
287         set_source_files_properties(kernels/cpu/kernel_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
288         set_source_files_properties(kernels/cpu/kernel_sse41.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS}")
289 endif()
290
291 if(CXX_HAS_AVX)
292         list(APPEND SRC
293                 kernels/cpu/kernel_avx.cpp
294         )
295         set_source_files_properties(kernels/cpu/kernel_avx.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX_KERNEL_FLAGS}")
296 endif()
297
298 if(CXX_HAS_AVX2)
299         list(APPEND SRC
300                 kernels/cpu/kernel_avx2.cpp
301         )
302         set_source_files_properties(kernels/cpu/kernel_avx2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX2_KERNEL_FLAGS}")
303 endif()
304
305 add_library(cycles_kernel
306         ${SRC}
307         ${SRC_HEADERS}
308         ${SRC_KERNELS_CPU_HEADERS}
309         ${SRC_CLOSURE_HEADERS}
310         ${SRC_SVM_HEADERS}
311         ${SRC_GEOM_HEADERS}
312         ${SRC_SPLIT_HEADERS}
313 )
314
315 if(WITH_CYCLES_CUDA)
316         add_dependencies(cycles_kernel cycles_kernel_cuda)
317 endif()
318
319 # OpenCL kernel
320
321 #set(KERNEL_PREPROCESSED ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
322 #add_custom_command(
323 #       OUTPUT ${KERNEL_PREPROCESSED}
324 #       COMMAND gcc -x c++ -E ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cl -I ${CMAKE_CURRENT_SOURCE_DIR}/../util/ -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -o ${KERNEL_PREPROCESSED}
325 #       DEPENDS ${SRC_KERNEL} ${SRC_UTIL_HEADERS})
326 #add_custom_target(cycles_kernel_preprocess ALL DEPENDS ${KERNEL_PREPROCESSED})
327 #delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${KERNEL_PREPROCESSED}" ${CYCLES_INSTALL_PATH}/kernel)
328
329 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
330 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_data_init.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
331 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_queue_enqueue.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
332 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_scene_intersect.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
333 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_lamp_emission.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
334 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_background_buffer_update.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
335 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_shader_eval.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
336 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_holdout_emission_blurring_pathtermination_ao.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
337 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_direct_lighting.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
338 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_shadow_blocked.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
339 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_next_iteration_setup.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
340 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_sum_all_radiance.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
341 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/cuda/kernel.cu" ${CYCLES_INSTALL_PATH}/kernel/kernels/cuda)
342 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
343 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_CLOSURE_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/closure)
344 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SVM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/svm)
345 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_GEOM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/geom)
346 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_UTIL_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
347 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SPLIT_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/split)
348