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