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