Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SConscript « kernel « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6459c3ed1831443b87e40f04cc7c689714738469 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/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 *****

import re
import subprocess
import sys
import os
import Blender as B

def normpath(path):
    return os.path.abspath(os.path.normpath(path))

Import ('env')

kernel_binaries = []

#Bitness
if B.bitness == 32:
    bits = 32
else:
    bits = 64

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")
    closure_dir = os.path.join(source_dir, "../closure")

    # get CUDA version
    nvcc_pipe = subprocess.Popen([nvcc, "--version"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    output, erroroutput = nvcc_pipe.communicate()
    cuda_major_minor = re.findall(r'release (\d+).(\d+)', output)[0]
    cuda_version = int(cuda_major_minor[0])*10 + int(cuda_major_minor[1])

    if cuda_version != 50:
        print("CUDA version %d.%d detected, build may succeed but only CUDA 5.0 is officially supported." % (cuda_version/10, cuda_version%10))

    # nvcc flags
    nvcc_flags = "-m%s" % (bits)
    nvcc_flags += " --cubin --ptxas-options=\"-v\""
    nvcc_flags += " -D__KERNEL_CUDA_VERSION__=%d" % (cuda_version)
    nvcc_flags += " -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DNVCC"
    nvcc_flags += " -I \"%s\" -I \"%s\" -I \"%s\"" % (util_dir, svm_dir, closure_dir)

    # dependencies
    dependencies = ['kernel.cu'] + kernel.Glob('*.h') + kernel.Glob('../util/*.h') + kernel.Glob('svm/*.h') + kernel.Glob('closure/*.h')
    last_cubin_file = None

    # add command for each cuda architecture
    for arch in cuda_archs:
        cubin_file = os.path.join(build_dir, "kernel_%s.cubin" % arch)

		# build flags depending on CUDA version and arch
        if cuda_version < 50:
            if arch == "sm_35":
                print("Can't build kernel for CUDA sm_35 architecture, skipping")
                continue

            # CUDA 4.x
            if arch.startswith("sm_1"):
                # sm_1x
                cuda_arch_flags = "--maxrregcount=24 --opencc-options -OPT:Olimit=0"
            elif arch.startswith("sm_2"):
                # sm_2x
                cuda_arch_flags = "--maxrregcount=24"
            else:
                # sm_3x
                cuda_arch_flags = "--maxrregcount=32"
        else:
            # CUDA 5.x
            if arch.startswith("sm_1"):
                # sm_1x
                cuda_arch_flags = "--maxrregcount=24 --opencc-options -OPT:Olimit=0 --use_fast_math"
            elif arch.startswith("sm_2"):
                # sm_2x
                cuda_arch_flags = "--maxrregcount=32 --use_fast_math"
            else:
                # sm_3x
                cuda_arch_flags = "--maxrregcount=32 --use_fast_math"

        command = "\"%s\" -arch=%s %s %s \"%s\" -o \"%s\"" % (nvcc, arch, nvcc_flags, cuda_arch_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

Return('kernel_binaries')