Skip to content

Instantly share code, notes, and snippets.

@fjnl
Created Feb 5, 2012
Embed
What would you like to do?
add -code and -arch support to nvcc.jam.
# nvcc.jam Boost.Build Jam file for extended toolset.
# Copyright (c) 2010 - 2011 Kohei Takahashi (Flast).
# Distributed under the MIT license. for more detail see COPYING.
import "class" : new ;
import common ;
import feature : feature ;
import generators ;
import modules ;
import toolset : flags ;
import type ;
import unix ;
import regex : split ;
import sequence : join ;
import errors ;
if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
{
.debug-configuration = true ;
}
feature.extend toolset : nvcc ;
toolset.inherit-generators nvcc : unix : unix.link unix.link.dll ;
toolset.inherit nvcc : unix ;
generators.override nvcc.prebuilt : builtin.lib-generator ;
generators.override nvcc.prebuilt : builtin.prebuilt ;
generators.override nvcc.searched-lib-generator : searched-lib-generator ;
rule init ( version ? : command * : options * )
{
local condition = [ common.check-init-parameters nvcc : version $(version) ] ;
local command = [ common.get-invocation-command nvcc : nvcc : $(command) ] ;
handle-options nvcc : $(condition) : $(command) : $(options) ;
}
local rule handle-options ( toolset : condition * : command * : options * )
{
common.handle-options $(toolset) : $(condition) : $(command) : $(options) ;
flags nvcc.compile.cu OPTIONS $(condition)
: [ feature.get-values <cuflags> : $(options) ]
: unchecked ;
}
class CUDA-compiling-generator : C-compiling-generator
{
rule __init__ ( id : source-types + : target-types +
: requirements * : optional-properties * )
{
C-compiling-generator.__init__ $(id)
: $(source-types) : $(target-types)
: $(requirements) : $(optional-properties) ;
}
}
rule register-cuda-compiler ( id
: source-types + : target-types +
: requirements * : optional-properties * )
{
generators.register
[ new CUDA-compiling-generator $(id)
: $(source-types) : $(target-types)
: $(requirements) : $(optional-properties) ] ;
}
IMPORT $(__name__) : register-cuda-compiler : : generators.register-cuda-compiler ;
# FIXME: target feature should be non-free feature.
feature target : ptx cubin : free optional ;
flags nvcc.compile OPTIONS <target>ptx : --ptx ;
flags nvcc.compile OPTIONS <target>cubin : --cubin ;
generators.register-cuda-compiler nvcc.compile.cu : CUDA : OBJ : <toolset>nvcc ;
generators.register-cuda-compiler nvcc.compile.cu : CUDA : PTX : <toolset>nvcc <target>ptx ;
generators.register-cuda-compiler nvcc.compile.cu : CUDA : CUBIN : <toolset>nvcc <target>cubin ;
# FIXME: These are not very good way to change output suffix.
type.set-generated-target-suffix OBJ : <toolset>nvcc : o ;
type.set-generated-target-suffix OBJ : <toolset>nvcc <target>ptx : ptx ;
type.set-generated-target-suffix OBJ : <toolset>nvcc <target>cubin : cubin ;
flags nvcc.compile OPTIONS <address-model>32 : -m32 ;
flags nvcc.compile OPTIONS <address-model>64 : -m64 ;
flags nvcc.compile OPTIONS <debug-symbols>on : -g ;
feature device-debug-symbols : off on : propagated ;
flags nvcc.compile OPTIONS <device-debug-symbols>on : -G ;
feature cuda-architecture : : free optional ;
rule setup-cuda-architecture ( targets * : sources * : properties * )
{
local code = [ feature.get-values cuda-architecture : $(properties) ] ;
switch $(code)
{
case "" : code = ;
case "compute_10" : OPTIONS on $(targets) += -arch=$(code) ;
case "compute_11" : OPTIONS on $(targets) += -arch=$(code) ;
case "compute_12" : OPTIONS on $(targets) += -arch=$(code) ;
case "compute_13" : OPTIONS on $(targets) += -arch=$(code) ;
case "compute_20" : OPTIONS on $(targets) += -arch=$(code) ;
case "sm_10" : OPTIONS on $(targets) += -arch=$(code) ;
case "sm_11" : OPTIONS on $(targets) += -arch=$(code) ;
case "sm_12" : OPTIONS on $(targets) += -arch=$(code) ;
case "sm_13" : OPTIONS on $(targets) += -arch=$(code) ;
case "sm_20" : OPTIONS on $(targets) += -arch=$(code) ;
case "sm_21" : OPTIONS on $(targets) += -arch=$(code) ;
case "sm_22" : OPTIONS on $(targets) += -arch=$(code) ;
case "sm_23" : OPTIONS on $(targets) += -arch=$(code) ;
case * : errors.user-error "cuda-architecture $(code) is invalid." ;
}
}
feature cuda-code : : free optional ;
rule setup-cuda-code ( targets * : sources * : properties * )
{
local code = [ feature.get-values cuda-code : $(properties) ] ;
switch $(code)
{
case "" : code = ;
case "compute_10" : OPTIONS on $(targets) += -code=$(code) ;
case "compute_11" : OPTIONS on $(targets) += -code=$(code) ;
case "compute_12" : OPTIONS on $(targets) += -code=$(code) ;
case "compute_13" : OPTIONS on $(targets) += -code=$(code) ;
case "compute_20" : OPTIONS on $(targets) += -code=$(code) ;
case "sm_10" : OPTIONS on $(targets) += -code=$(code) ;
case "sm_11" : OPTIONS on $(targets) += -code=$(code) ;
case "sm_12" : OPTIONS on $(targets) += -code=$(code) ;
case "sm_13" : OPTIONS on $(targets) += -code=$(code) ;
case "sm_20" : OPTIONS on $(targets) += -code=$(code) ;
case "sm_21" : OPTIONS on $(targets) += -code=$(code) ;
case "sm_22" : OPTIONS on $(targets) += -code=$(code) ;
case "sm_23" : OPTIONS on $(targets) += -code=$(code) ;
case * : errors.user-error "cuda-code $(code) is invalid." ;
}
}
flags nvcc.compile DEFINES <define> ;
flags nvcc.compile INCLUDES <include> ;
feature cuflags : : free optional ;
flags nvcc.compile.cu OPTIONS <cuflags> ;
rule compile.cu ( targets * : sources * : properties * )
{
local target = [ feature.get-values target : $(properties) ] ;
switch $(target)
{
case "" :
OPTIONS on $(targets) += -c ;
case "ptx" :
case "cubin" :
case * :
EXIT "** error ** nvcc.jam: invalid target (" $(target) ")." ;
}
setup-cuda-architecture $(targets) : $(sources) : $(properties) ;
setup-cuda-code $(targets) : $(sources) : $(properties) ;
}
actions compile.cu
{
$(CONFIG_COMMAND) $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -o "$(<)" "$(>)"
}
flags nvcc.link LINKPATH <library-path> ;
flags nvcc.link LIBRARIES <library-file> ;
flags nvcc.link OPTIONS <linkflags> ;
#flags nvcc.link OPTIONS <link>shared : --shared ;
#flags nvcc.link OPTIONS <runtime-link>shared : --shared ;
#rule link ( targets * : sources * : properties * )
#{
#}
actions link bind LIBRARIES
{
$(CONFIG_COMMAND) $(OPTIONS) -L"$(LINKPATH)" -o "$(<)" "$(>)" $(LIBRARIES)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment