2011-12-01 16:33:21 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
|
|
|
import os
|
2011-12-08 19:16:43 +00:00
|
|
|
import Blender as B
|
2011-12-01 16:33:21 +00:00
|
|
|
|
|
|
|
def normpath(path):
|
|
|
|
return os.path.abspath(os.path.normpath(path))
|
|
|
|
|
|
|
|
Import ('env')
|
|
|
|
|
|
|
|
kernel_binaries = []
|
|
|
|
|
2011-12-08 19:16:43 +00:00
|
|
|
#Bitness
|
|
|
|
if B.bitness == 32:
|
|
|
|
bits = 32
|
|
|
|
else:
|
|
|
|
bits = 64
|
|
|
|
|
2011-12-01 16:33:21 +00:00
|
|
|
if env['WITH_BF_CYCLES_CUDA_BINARIES']:
|
|
|
|
kernel = env.Clone()
|
|
|
|
|
|
|
|
# cuda info
|
|
|
|
nvcc = env['BF_CYCLES_CUDA_NVCC']
|
|
|
|
cuda_archs = env['BF_CYCLES_CUDA_BINARIES_ARCH']
|
|
|
|
|
|
|
|
# build directory
|
|
|
|
root_build_dir = normpath(env['BF_BUILDDIR'])
|
|
|
|
build_dir = os.path.join(root_build_dir, 'intern/cycles/kernel')
|
|
|
|
|
|
|
|
# source directories and files
|
|
|
|
source_dir = Dir('.').srcnode().path
|
|
|
|
kernel_file = os.path.join(source_dir, "kernel.cu")
|
|
|
|
util_dir = os.path.join(source_dir, "../util")
|
|
|
|
svm_dir = os.path.join(source_dir, "../svm")
|
|
|
|
|
|
|
|
# nvcc flags
|
2011-12-08 19:16:43 +00:00
|
|
|
nvcc_flags = "-m%s" % (bits)
|
2012-05-28 19:49:26 +00:00
|
|
|
nvcc_flags += " --cubin --ptxas-options=\"-v\" --maxrregcount=24"
|
2011-12-01 16:33:21 +00:00
|
|
|
nvcc_flags += " --opencc-options -OPT:Olimit=0"
|
|
|
|
nvcc_flags += " -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DNVCC"
|
|
|
|
nvcc_flags += " -I \"%s\" -I \"%s\"" % (util_dir, svm_dir)
|
|
|
|
|
|
|
|
# dependencies
|
|
|
|
dependencies = ['kernel.cu'] + kernel.Glob('*.h') + kernel.Glob('../util/*.h') + kernel.Glob('svm/*.h')
|
2011-12-06 12:29:54 +00:00
|
|
|
last_cubin_file = None
|
2011-12-01 16:33:21 +00:00
|
|
|
|
|
|
|
# add command for each cuda architecture
|
|
|
|
for arch in cuda_archs:
|
|
|
|
cubin_file = os.path.join(build_dir, "kernel_%s.cubin" % arch)
|
|
|
|
|
|
|
|
command = "\"%s\" -arch=%s %s \"%s\" -o \"%s\"" % (nvcc, arch, nvcc_flags, kernel_file, cubin_file)
|
|
|
|
|
|
|
|
kernel.Command(cubin_file, 'kernel.cu', command)
|
|
|
|
kernel.Depends(cubin_file, dependencies)
|
|
|
|
|
|
|
|
kernel_binaries.append(cubin_file)
|
2011-12-06 16:00:57 +00:00
|
|
|
|
|
|
|
if not env['WITH_BF_CYCLES_CUDA_THREADED_COMPILE']:
|
|
|
|
# trick to compile one kernel at a time to reduce memory usage
|
|
|
|
if last_cubin_file:
|
|
|
|
kernel.Depends(cubin_file, last_cubin_file)
|
|
|
|
last_cubin_file = cubin_file
|
2011-12-06 12:29:54 +00:00
|
|
|
|
2011-12-01 16:33:21 +00:00
|
|
|
Return('kernel_binaries')
|
|
|
|
|