2012-12-17 08:01:43 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# The Original Code is Copyright (C) 2011, Blender Foundation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# The Original Code is: all of this file.
|
|
|
|
#
|
|
|
|
# Contributor(s): Nathan Letwory.
|
|
|
|
#
|
|
|
|
# ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
2013-06-19 17:54:23 +00:00
|
|
|
import re
|
|
|
|
import subprocess
|
2011-12-01 16:33:21 +00:00
|
|
|
import sys
|
|
|
|
import os
|
2011-12-08 19:16:43 +00:00
|
|
|
import Blender as B
|
2014-06-26 10:03:52 +00:00
|
|
|
import btools
|
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")
|
2014-03-29 12:03:45 +00:00
|
|
|
geom_dir = os.path.join(source_dir, "../geom")
|
2012-12-03 16:51:05 +00:00
|
|
|
closure_dir = os.path.join(source_dir, "../closure")
|
2011-12-01 16:33:21 +00:00
|
|
|
|
2013-06-19 17:54:23 +00:00
|
|
|
# get CUDA version
|
2014-06-26 10:03:52 +00:00
|
|
|
output = btools.get_command_output([nvcc, "--version"])
|
2013-06-19 17:54:23 +00:00
|
|
|
cuda_major_minor = re.findall(r'release (\d+).(\d+)', output)[0]
|
|
|
|
cuda_version = int(cuda_major_minor[0])*10 + int(cuda_major_minor[1])
|
|
|
|
|
2014-08-21 21:35:20 +00:00
|
|
|
if cuda_version != 65:
|
|
|
|
print("CUDA version %d.%d detected, build may succeed but only CUDA 6.5 is officially supported." % (cuda_version/10, cuda_version%10))
|
2013-06-19 17:54:23 +00:00
|
|
|
|
2011-12-01 16:33:21 +00:00
|
|
|
# nvcc flags
|
2011-12-08 19:16:43 +00:00
|
|
|
nvcc_flags = "-m%s" % (bits)
|
2014-05-26 14:48:30 +00:00
|
|
|
nvcc_flags += " --cubin --ptxas-options=\"-v\" --use_fast_math"
|
2013-06-19 17:54:23 +00:00
|
|
|
nvcc_flags += " -D__KERNEL_CUDA_VERSION__=%d" % (cuda_version)
|
2011-12-01 16:33:21 +00:00
|
|
|
nvcc_flags += " -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DNVCC"
|
2014-03-29 14:56:29 +00:00
|
|
|
nvcc_flags += " -I \"%s\" -I \"%s\" -I \"%s\" -I \"%s\"" % (util_dir, svm_dir, geom_dir, closure_dir)
|
2011-12-01 16:33:21 +00:00
|
|
|
|
|
|
|
# dependencies
|
2014-03-29 12:03:45 +00:00
|
|
|
dependencies = ['kernel.cu'] + kernel.Glob('*.h') + kernel.Glob('../util/*.h') + kernel.Glob('svm/*.h') + kernel.Glob('geom/*.h') + kernel.Glob('closure/*.h')
|
2011-12-06 12:29:54 +00:00
|
|
|
last_cubin_file = None
|
2011-12-01 16:33:21 +00:00
|
|
|
|
2014-08-26 15:02:03 +00:00
|
|
|
configs = (("kernel_%s.cubin", ''),
|
|
|
|
("kernel_experimental_%s.cubin", ' -D__KERNEL_CUDA_EXPERIMENTAL__'))
|
|
|
|
|
2011-12-01 16:33:21 +00:00
|
|
|
# add command for each cuda architecture
|
|
|
|
for arch in cuda_archs:
|
2014-08-26 15:02:03 +00:00
|
|
|
for config in configs:
|
|
|
|
# TODO(sergey): Use dict instead ocouple in order to increase readability?
|
|
|
|
name = config[0]
|
|
|
|
extra_flags = config[1]
|
|
|
|
|
|
|
|
cubin_file = os.path.join(build_dir, name % arch)
|
|
|
|
current_flags = nvcc_flags + extra_flags
|
|
|
|
|
|
|
|
if env['BF_CYCLES_CUDA_ENV']:
|
|
|
|
MS_SDK = "C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\SetEnv.cmd"
|
|
|
|
command = "\"%s\" & \"%s\" -arch=%s %s \"%s\" -o \"%s\"" % (MS_SDK, nvcc, arch, current_flags, kernel_file, cubin_file)
|
|
|
|
else:
|
|
|
|
command = "\"%s\" -arch=%s %s \"%s\" -o \"%s\"" % (nvcc, arch, current_flags, kernel_file, cubin_file)
|
|
|
|
|
|
|
|
kernel.Command(cubin_file, 'kernel.cu', command)
|
|
|
|
kernel.Depends(cubin_file, dependencies)
|
|
|
|
|
|
|
|
kernel_binaries.append(cubin_file)
|
|
|
|
|
|
|
|
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')
|
|
|
|
|