mkmf-cu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/mkmf-cu-nvcc +24 -0
- data/lib/mkmf-cu.rb +16 -0
- data/lib/mkmf-cu/opt.rb +132 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dddc0a150502a76ea3ad3bf7a36d15f20b1070c6
|
4
|
+
data.tar.gz: b62362f39b1bf24113b97cd87011a423f733702c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6dcba385c2537d8cab74fd10655691c54c3e2f1492d69b1d8c04571622eeca96e714da25fed4a86316cb0246e72e19053db3e8c7bee0aa1b4445961cb0aace6
|
7
|
+
data.tar.gz: 190fc8e035136c97a438c0a1ec343abef2434b515565ea0c16b76cb3725df6471c34e38c82fe4524ce6cffa54eac4ef620bae616f07ed943ed87f92d62a4c320
|
data/bin/mkmf-cu-nvcc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "mkmf-cu/opt"
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
opt, opt_h = build_optparser()
|
6
|
+
|
7
|
+
argv = ARGV.map{|e| e.dup }
|
8
|
+
|
9
|
+
$stderr.puts '[given command line options]: ' + ARGV.join(' ')
|
10
|
+
parse_ill_short(argv, opt_h)
|
11
|
+
parse_ill_short_with_arg(argv, opt_h)
|
12
|
+
|
13
|
+
argv = opt.parse(argv)
|
14
|
+
|
15
|
+
if opt_h["-c"].size > 0
|
16
|
+
s = generate_compiling_command_line(opt_h)
|
17
|
+
elsif opt_h['-dynamic'].size > 0 or opt_h['-shared'].size > 0
|
18
|
+
s = generate_linking_command_line(argv, opt_h)
|
19
|
+
else
|
20
|
+
raise
|
21
|
+
end
|
22
|
+
|
23
|
+
$stderr.puts "nvcc" + s
|
24
|
+
Open3.capture2("nvcc " + s)
|
data/lib/mkmf-cu.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
MakeMakefile::CONFIG["CC"] = "mkmf-cu-nvcc --mkmf-cu-ext=c"
|
4
|
+
MakeMakefile::CONFIG["CXX"] = "mkmf-cu-nvcc --mkmf-cu-ext=cxx"
|
5
|
+
MakeMakefile::C_EXT << "cu"
|
6
|
+
MakeMakefile::SRC_EXT << "cu"
|
7
|
+
|
8
|
+
def compile_cu_with_cxx_compiler
|
9
|
+
MakeMakefile::C_EXT.delete("cu")
|
10
|
+
MakeMakefile::CXX_EXT << "cu"
|
11
|
+
end
|
12
|
+
|
13
|
+
def compile_cu_with_cc_compiler
|
14
|
+
MakeMakefile::CXX_EXT.delete("cu")
|
15
|
+
MakeMakefile::C_EXT << "cu"
|
16
|
+
end
|
data/lib/mkmf-cu/opt.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require "optparse"
|
2
|
+
require "rbconfig"
|
3
|
+
|
4
|
+
def build_optparser
|
5
|
+
opt = OptionParser.new
|
6
|
+
opt_h = Hash.new{|h, k| h[k] = [] }
|
7
|
+
|
8
|
+
opt.on("--arch arg") {|v| opt_h["-arch"] << v }
|
9
|
+
opt.on("--std arg") {|v| opt_h["-std"] << v }
|
10
|
+
opt.on("--stdlib arg") {|v| opt_h["-stdlib"] << v }
|
11
|
+
|
12
|
+
opt.on("--Wl arg") {|v| opt_h["-Wl"] << v }
|
13
|
+
|
14
|
+
opt.on('--profile') {|v| opt_h["-pg"] << "" }
|
15
|
+
opt.on('-g') {|v| opt_h["-g"] << "" }
|
16
|
+
opt.on('-G', "--device-debug") {|v| opt_h["-G"] << "" }
|
17
|
+
|
18
|
+
opt.on('-I path') {|v| opt_h["-I"] << v }
|
19
|
+
opt.on('-D flag') {|v| opt_h["-D"] << v }
|
20
|
+
opt.on('-W flag') {|v| opt_h["-W"] << v }
|
21
|
+
opt.on('-o output') {|v| opt_h["-o"] << v }
|
22
|
+
opt.on('-c file') {|v| opt_h["-c"] << v }
|
23
|
+
opt.on('-f flag') {|v| opt_h["-f"] << v }
|
24
|
+
opt.on('-l file') {|v| opt_h["-l"] << v }
|
25
|
+
opt.on('-L path') {|v| opt_h["-L"] << v }
|
26
|
+
opt.on('-x pat', "--x pat") {|v| opt_h["-x"] << v }
|
27
|
+
opt.on('-O num'){|v| opt_h["-O"] << v if /[0-9]/ =~ v }
|
28
|
+
opt.on('--mkmf-cu-ext ext'){|v| opt_h["--mkmf-cu-ext"] << v}
|
29
|
+
|
30
|
+
return [opt, opt_h]
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_ill_short(argv, opt_h)
|
34
|
+
["-shared", "-rdynamic", "-dynamic", "-bundle", "-pipe", "-pg"].each{|opt|
|
35
|
+
if ind = argv.find_index(opt)
|
36
|
+
opt_h[opt] << ""
|
37
|
+
argv.delete_at(ind)
|
38
|
+
end
|
39
|
+
}
|
40
|
+
["-arch", "-std", "-stdlib"].each{|opt|
|
41
|
+
if ind = argv.find_index(opt)
|
42
|
+
argv[ind] = "-" + opt
|
43
|
+
end
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_ill_short_with_arg(argv, opt_h)
|
48
|
+
[/\A(\-stdlib)=(.*)/, /\A(\-Wl),(.*)/].each{|reg|
|
49
|
+
argv.each{|e|
|
50
|
+
if reg =~ e
|
51
|
+
e[0..-1] = "-" + $1 + '=' + $2
|
52
|
+
end
|
53
|
+
}
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def compiler_option(opt_h)
|
58
|
+
ret = ""
|
59
|
+
["-f", "-W", "-pipe"].each{|op|
|
60
|
+
opt_h[op].each{|e|
|
61
|
+
ret << " --compiler-options " + "#{op}#{e}"
|
62
|
+
}
|
63
|
+
}
|
64
|
+
["-stdlib"].each{|op|
|
65
|
+
opt_h[op].each{|e|
|
66
|
+
ret << " --compiler-options " + "#{op}=#{e}"
|
67
|
+
}
|
68
|
+
}
|
69
|
+
return ret
|
70
|
+
end
|
71
|
+
|
72
|
+
def linker_option(opt_h)
|
73
|
+
ret = ""
|
74
|
+
["-dynamic", "-bundle", "-shared", "-rdynamic"].each{|op|
|
75
|
+
opt_h[op].each{|e|
|
76
|
+
ret << " --linker-options " + op
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
opt_h["-Wl"].each{|e|
|
81
|
+
ret << " --linker-options " + e
|
82
|
+
}
|
83
|
+
|
84
|
+
return ret
|
85
|
+
end
|
86
|
+
|
87
|
+
def compiler_bin(opt_h)
|
88
|
+
if opt_h["--mkmf-cu-ext"][0] == "c"
|
89
|
+
" --compiler-bindir " + RbConfig::CONFIG["CC"]
|
90
|
+
elsif opt_h["--mkmf-cu-ext"][0] == "cxx"
|
91
|
+
" --compiler-bindir " + RbConfig::CONFIG["CXX"]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def generate_compiling_command_line(opt_h)
|
96
|
+
s = ""
|
97
|
+
# options nvcc can uderstatnd
|
98
|
+
["-pg", "-g", "-G", "-x", "-I", "-D", "-o", "-c", "-O"].each{|op|
|
99
|
+
opt_h[op].each{|e|
|
100
|
+
case op
|
101
|
+
when "-o", "-c", "-x"
|
102
|
+
s << " #{op} #{e}"
|
103
|
+
else
|
104
|
+
s << " #{op}#{e}"
|
105
|
+
end
|
106
|
+
}
|
107
|
+
}
|
108
|
+
s << compiler_option(opt_h)
|
109
|
+
s << compiler_bin(opt_h)
|
110
|
+
return s
|
111
|
+
end
|
112
|
+
|
113
|
+
def generate_linking_command_line(argv, opt_h)
|
114
|
+
s = ""
|
115
|
+
["-L", "-l", "-o", "-c", "-O"].each{|op|
|
116
|
+
opt_h[op].each{|e|
|
117
|
+
case op
|
118
|
+
when "-o", "-c"
|
119
|
+
s << " #{op} #{e}"
|
120
|
+
s << " " + argv[0] + " " if op == "-o"
|
121
|
+
else
|
122
|
+
s << " #{op}#{e}"
|
123
|
+
end
|
124
|
+
}
|
125
|
+
}
|
126
|
+
s << compiler_option(opt_h)
|
127
|
+
s << linker_option(opt_h)
|
128
|
+
|
129
|
+
s << compiler_bin(opt_h)
|
130
|
+
|
131
|
+
return s
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mkmf-cu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takashi Tamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Write Ruby extention in C/C++ with NVIDIA CUDA. A simple wrapper command
|
14
|
+
for nvcc and a monkey patch for mkmf.
|
15
|
+
email: ''
|
16
|
+
executables:
|
17
|
+
- mkmf-cu-nvcc
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/mkmf-cu-nvcc
|
22
|
+
- lib/mkmf-cu.rb
|
23
|
+
- lib/mkmf-cu/opt.rb
|
24
|
+
homepage: https://github.com/ruby-accel/mkmf-cu
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.5.1
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Write Ruby extention in C/C++ with NVIDIA CUDA.
|
48
|
+
test_files: []
|