BOAST 0.8 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/BOAST.gemspec +1 -1
- data/lib/BOAST/CKernel.rb +118 -14
- metadata +2 -2
data/BOAST.gemspec
CHANGED
data/lib/BOAST/CKernel.rb
CHANGED
@@ -4,9 +4,72 @@ require 'rake'
|
|
4
4
|
require 'tempfile'
|
5
5
|
require 'rbconfig'
|
6
6
|
require 'systemu'
|
7
|
+
require 'yaml'
|
7
8
|
|
8
9
|
module BOAST
|
9
10
|
@@verbose = false
|
11
|
+
@@compiler_default_options = {
|
12
|
+
:FC => 'gfortran',
|
13
|
+
:FCFLAGS => '-O2 -Wall',
|
14
|
+
:CC => 'gcc',
|
15
|
+
:CFLAGS => '-O2 -Wall',
|
16
|
+
:CXX => 'g++',
|
17
|
+
:CXXFLAGS => '-O2 -Wall',
|
18
|
+
:NVCC => 'nvcc',
|
19
|
+
:NVCCFLAGS => '-O2',
|
20
|
+
:LDFLAGS => '',
|
21
|
+
:CLFLAGS => '',
|
22
|
+
:openmp => false
|
23
|
+
}
|
24
|
+
|
25
|
+
@@openmp_default_flags = {
|
26
|
+
"gcc" => "-fopenmp",
|
27
|
+
"icc" => "-openmp",
|
28
|
+
"gfortran" => "-fopenmp",
|
29
|
+
"ifort" => "-openmp",
|
30
|
+
"g++" => "-fopenmp",
|
31
|
+
"icpc" => "-openmp"
|
32
|
+
}
|
33
|
+
|
34
|
+
def BOAST::read_boast_config
|
35
|
+
home_config_dir = ENV["XDG_CONFIG_HOME"]
|
36
|
+
home_config_dir = "#{Dir.home}/.config" if not home_config_dir
|
37
|
+
Dir.mkdir( home_config_dir ) if not File::exist?( home_config_dir )
|
38
|
+
return if not File::directory?(home_config_dir)
|
39
|
+
boast_config_dir = "#{home_config_dir}/BOAST"
|
40
|
+
Dir.mkdir( boast_config_dir ) if not File::exist?( boast_config_dir )
|
41
|
+
compiler_options_file = "#{boast_config_dir}/compiler_options"
|
42
|
+
if File::exist?( compiler_options_file ) then
|
43
|
+
File::open( compiler_options_file, "r" ) { |f|
|
44
|
+
@@compiler_default_options.update( YAML::load( f.read ) )
|
45
|
+
}
|
46
|
+
else
|
47
|
+
File::open( compiler_options_file, "w" ) { |f|
|
48
|
+
f.write YAML::dump( @@compiler_default_options )
|
49
|
+
}
|
50
|
+
end
|
51
|
+
openmp_flags_file = "#{boast_config_dir}/openmp_flags"
|
52
|
+
if File::exist?( openmp_flags_file ) then
|
53
|
+
File::open( openmp_flags_file, "r" ) { |f|
|
54
|
+
@@openmp_default_flags.update( YAML::load( f.read ) )
|
55
|
+
}
|
56
|
+
else
|
57
|
+
File::open( openmp_flags_file, "w" ) { |f|
|
58
|
+
f.write YAML::dump( @@openmp_default_flags )
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
BOAST::read_boast_config
|
64
|
+
|
65
|
+
def BOAST::get_openmp_flags
|
66
|
+
return @@openmp_default_flags.clone
|
67
|
+
end
|
68
|
+
|
69
|
+
def BOAST::get_compiler_options
|
70
|
+
return @@compiler_default_options.clone
|
71
|
+
end
|
72
|
+
|
10
73
|
|
11
74
|
def BOAST::get_verbose
|
12
75
|
return @@verbose
|
@@ -68,21 +131,14 @@ module BOAST
|
|
68
131
|
Rake::verbose(verbose)
|
69
132
|
Rake::FileUtilsExt.verbose_flag=verbose
|
70
133
|
f_compiler = options[:FC]
|
71
|
-
f_compiler = "gfortran" if not f_compiler
|
72
134
|
c_compiler = options[:CC]
|
73
|
-
c_compiler = "cc" if not c_compiler
|
74
135
|
cxx_compiler = options[:CXX]
|
75
|
-
cxx_compiler = "g++" if not cxx_compiler
|
76
136
|
cuda_compiler = options[:NVCC]
|
77
|
-
cuda_compiler = "nvcc"if not cuda_compiler
|
78
137
|
f_flags = options[:FCFLAGS]
|
79
|
-
f_flags = "-O2 -Wall" if not f_flags
|
80
138
|
f_flags += " -fPIC"
|
81
139
|
f_flags += " -fno-second-underscore" if f_compiler == 'g95'
|
82
140
|
ld_flags = options[:LDFLAGS]
|
83
|
-
ld_flags = "" if not ld_flags
|
84
141
|
cuda_flags = options[:NVCCFLAGS]
|
85
|
-
cuda_flags = "-O2" if not cuda_flags
|
86
142
|
cuda_flags += " --compiler-options '-fPIC'"
|
87
143
|
|
88
144
|
|
@@ -104,13 +160,48 @@ module BOAST
|
|
104
160
|
end
|
105
161
|
end
|
106
162
|
includes += " -I#{narray_path}" if narray_path
|
107
|
-
cflags =
|
108
|
-
cxxflags =
|
163
|
+
cflags = options[:CFLAGS]
|
164
|
+
cxxflags = options[:CXXFLAGS]
|
165
|
+
cflags += " -fPIC #{includes}"
|
166
|
+
cxxflags += " -fPIC #{includes}"
|
109
167
|
cflags += " -DHAVE_NARRAY_H" if narray_path
|
110
|
-
cflags += options[:CFLAGS] if options[:CFLAGS]
|
111
168
|
fcflags = f_flags
|
112
169
|
cudaflags = cuda_flags
|
113
170
|
|
171
|
+
if options[:openmp] then
|
172
|
+
case @lang
|
173
|
+
when BOAST::C
|
174
|
+
openmp_c_flags = BOAST::get_openmp_flags[c_compiler]
|
175
|
+
if not openmp_c_flags then
|
176
|
+
keys = BOAST::get_openmp_flags.keys
|
177
|
+
keys.each { |k|
|
178
|
+
openmp_c_flags = BOAST::get_openmp_flags[k] if c_compiler.match(k)
|
179
|
+
}
|
180
|
+
end
|
181
|
+
raise "unkwown openmp flags for: #{c_compiler}" if not openmp_c_flags
|
182
|
+
cflags += " #{openmp_c_flags}"
|
183
|
+
openmp_cxx_flags = BOAST::get_openmp_flags[cxx_compiler]
|
184
|
+
if not openmp_cxx_flags then
|
185
|
+
keys = BOAST::get_openmp_flags.keys
|
186
|
+
keys.each { |k|
|
187
|
+
openmp_cxx_flags = BOAST::get_openmp_flags[k] if cxx_compiler.match(k)
|
188
|
+
}
|
189
|
+
end
|
190
|
+
raise "unkwown openmp flags for: #{cxx_compiler}" if not openmp_cxx_flags
|
191
|
+
cxxflags += " #{openmp_cxx_flags}"
|
192
|
+
when BOAST::FORTRAN
|
193
|
+
openmp_f_flags = BOAST::get_openmp_flags[f_compiler]
|
194
|
+
if not openmp_f_flags then
|
195
|
+
keys = BOAST::get_openmp_flags.keys
|
196
|
+
keys.each { |k|
|
197
|
+
openmp_f_flags = BOAST::get_openmp_flags[k] if f_compiler.match(k)
|
198
|
+
}
|
199
|
+
end
|
200
|
+
raise "unkwown openmp flags for: #{f_compiler}" if not openmp_f_flags
|
201
|
+
fcflags += " #{openmp_f_flags}"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
114
205
|
runner = lambda { |t, call_string|
|
115
206
|
if verbose then
|
116
207
|
sh call_string
|
@@ -244,17 +335,30 @@ EOF
|
|
244
335
|
end
|
245
336
|
|
246
337
|
def build(options = {})
|
247
|
-
|
248
|
-
|
338
|
+
compiler_options = BOAST::get_compiler_options
|
339
|
+
compiler_options.update(options)
|
340
|
+
return build_opencl(comiler_options) if @lang == BOAST::CL
|
341
|
+
ldflags = self.setup_compiler(compiler_options)
|
249
342
|
extension = ".c" if @lang == BOAST::C
|
250
343
|
extension = ".cu" if @lang == BOAST::CUDA
|
251
344
|
extension = ".f90" if @lang == BOAST::FORTRAN
|
252
345
|
#temporary
|
253
|
-
c_compiler =
|
346
|
+
c_compiler = compiler_options[:CC]
|
254
347
|
c_compiler = "cc" if not c_compiler
|
255
|
-
linker =
|
348
|
+
linker = compiler_options[:LD]
|
256
349
|
linker = c_compiler if not linker
|
257
350
|
#end temporary
|
351
|
+
if options[:openmp] then
|
352
|
+
openmp_ld_flags = BOAST::get_openmp_flags[linker]
|
353
|
+
if not openmp_ld_flags then
|
354
|
+
keys = BOAST::get_openmp_flags.keys
|
355
|
+
keys.each { |k|
|
356
|
+
openmp_ld_flags = BOAST::get_openmp_flags[k] if linker.match(k)
|
357
|
+
}
|
358
|
+
end
|
359
|
+
raise "unkwown openmp flags for: #{linker}" if not openmp_ld_flags
|
360
|
+
ldflags += " #{openmp_ld_flags}"
|
361
|
+
end
|
258
362
|
source_file = Tempfile::new([@procedure.name,extension])
|
259
363
|
path = source_file.path
|
260
364
|
target = path.chomp(File::extname(path))+".o"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: BOAST
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.9'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: narray
|