-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuda_rules
51 lines (40 loc) · 1.25 KB
/
cuda_rules
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
#!/bin/bash
#
# 2021-12-16 J.Nider
realpath=$(readlink -f $0) # in case 'bake' was executed from a symbolic link
path=${realpath%/*} # full path of 'bake' script (minus the script name)
# include the linker rules automatically for convenience
source $path/ld_rules
#---------------------------
# compile .cu file to .o file
#
# Depends on: NVCC compiler name
# Optional: NVCCFLAGS additional flags to pass to compiler
# SRC_PATH full path to source file
# DST_PATH full path to destination file
#
function rule_cuda
{
local target=$1
local flags=${2:-$NVCCFLAGS}
local root=${target%.*}
local deps
local target_suffix=${target##*.}
# make sure target is of the right type
[[ "$target_suffix" =~ [oO] ]] || return -1
# the first dependency is the source file, otherwise guess at the name
_deps_of $target deps
local srcfile=${deps[0]:-$root.cu}
local suffix=${srcfile##*.}
# make sure source file exists and is of the right type
[[ "$suffix" == "cu" ]] && [[ -f "$srcfile" ]] || return -1
# make sure the compiler is set
[ $NVCC ] || {
echo "${FUNCNAME[0]}: 'NVCC' variable must be set to the name of the compiler"
exit
}
echo "Compiling $srcfile to $target"
local cmd="$NVCC $flags -c $srcfile -o $target"
[[ $__verbose ]] && echo $cmd
$cmd
}