Cycles / CUDA Kernel compile:
[blender.git] / intern / cycles / kernel / SConscript
1 #!/usr/bin/python
2 import sys
3 import os
4
5 def normpath(path):
6     return os.path.abspath(os.path.normpath(path))
7
8 Import ('env')
9
10 kernel_binaries = []
11
12 if env['WITH_BF_CYCLES_CUDA_BINARIES']:
13     kernel = env.Clone()
14
15     # cuda info
16     nvcc = env['BF_CYCLES_CUDA_NVCC']
17     cuda_archs = env['BF_CYCLES_CUDA_BINARIES_ARCH']
18
19     # build directory
20     root_build_dir = normpath(env['BF_BUILDDIR'])
21     build_dir = os.path.join(root_build_dir, 'intern/cycles/kernel')
22
23     # source directories and files
24     source_dir = Dir('.').srcnode().path
25     kernel_file = os.path.join(source_dir, "kernel.cu")
26     util_dir = os.path.join(source_dir, "../util")
27     svm_dir = os.path.join(source_dir, "../svm")
28
29     # nvcc flags
30     nvcc_flags = "--cubin -use_fast_math --ptxas-options=\"-v\" --maxrregcount=24"
31     nvcc_flags += " --opencc-options -OPT:Olimit=0"
32     nvcc_flags += " -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DNVCC"
33     nvcc_flags += " -I \"%s\" -I \"%s\"" % (util_dir, svm_dir)
34
35     # dependencies
36     dependencies = ['kernel.cu'] + kernel.Glob('*.h') + kernel.Glob('../util/*.h') + kernel.Glob('svm/*.h')
37     last_cubin_file = None
38
39     # add command for each cuda architecture
40     for arch in cuda_archs:
41         cubin_file = os.path.join(build_dir, "kernel_%s.cubin" % arch)
42
43         command = "\"%s\" -arch=%s %s \"%s\" -o \"%s\"" % (nvcc, arch, nvcc_flags, kernel_file, cubin_file)
44
45         kernel.Command(cubin_file, 'kernel.cu', command)
46         kernel.Depends(cubin_file, dependencies)
47
48         kernel_binaries.append(cubin_file)
49         
50         if not env['WITH_BF_CYCLES_CUDA_THREADED_COMPILE']:
51             # trick to compile one kernel at a time to reduce memory usage
52             if last_cubin_file:
53                 kernel.Depends(cubin_file, last_cubin_file)
54             last_cubin_file = cubin_file
55
56 Return('kernel_binaries')
57