Module: BOAST::Compilers
Instance Method Summary collapse
- #get_includes(narray_path) ⇒ Object
- #get_narray_path ⇒ Object
- #get_openmp_flags(compiler) ⇒ Object
- #setup_c_compiler(options, includes, narray_path, runner, probes) ⇒ Object
- #setup_compilers(probes, options = {}) ⇒ Object
- #setup_cuda_compiler(options, runner, probes) ⇒ Object
- #setup_cxx_compiler(options, includes, runner, probes) ⇒ Object
- #setup_fortran_compiler(options, runner, probes) ⇒ Object
- #setup_linker(options, probes) ⇒ Object
- #setup_linker_mppa(options, runner, probes) ⇒ Object
Instance Method Details
#get_includes(narray_path) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 23 def get_includes(narray_path) includes = "-I#{RbConfig::CONFIG["archdir"]}" includes += " -I#{RbConfig::CONFIG["rubyhdrdir"]} -I#{RbConfig::CONFIG["rubyhdrdir"]}/#{RbConfig::CONFIG["arch"]}" includes += " -I#{RbConfig::CONFIG["rubyarchhdrdir"]}" if RbConfig::CONFIG["rubyarchhdrdir"] includes += " -I#{narray_path}" if narray_path return includes end |
#get_narray_path ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 31 def get_narray_path narray_path = nil begin spec = Gem::Specification::find_by_name('narray') narray_path = spec.require_path if narray_path == "." then narray_path = spec.full_gem_path end rescue Gem::LoadError => e rescue NoMethodError => e spec = Gem::available?('narray') if spec then require 'narray' narray_path = Gem.loaded_specs['narray'].require_path if narray_path == "." then narray_path = Gem.loaded_specs['narray'].full_gem_path end end end return narray_path end |
#get_openmp_flags(compiler) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 12 def get_openmp_flags(compiler) openmp_flags = BOAST::get_openmp_flags[compiler] if not openmp_flags then keys = BOAST::get_openmp_flags.keys keys.each { |k| openmp_flags = BOAST::get_openmp_flags[k] if compiler.match(k) } end return openmp_flags end |
#setup_c_compiler(options, includes, narray_path, runner, probes) ⇒ Object
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 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 53 def setup_c_compiler(, includes, narray_path, runner, probes) c_mppa_compiler = "k1-gcc" c_compiler = [:CC] cflags = [:CFLAGS] probes.each { |p| cflags += " #{p.cflags}" if p.respond_to?(:cflags) } cflags += " -march=#{get_model}" cflags += " -fPIC #{includes}" cflags += " -DHAVE_NARRAY_H" if narray_path cflags += " -I/usr/local/k1tools/include" if @architecture == MPPA objext = RbConfig::CONFIG["OBJEXT"] if ([:openmp] or [:OPENMP]) and @lang == C and not disable_openmp then openmp_cflags = get_openmp_flags(c_compiler) raise "unkwown openmp flags for: #{c_compiler}" if not openmp_cflags cflags += " #{openmp_cflags}" end cflags_no_fpic = cflags.gsub("-fPIC","") rule ".nofpic#{objext}" => '.c' do |t| c_call_string = "#{c_compiler} #{cflags_no_fpic} -c -o #{t.name} #{t.source}" runner.call(t, c_call_string) end rule ".#{objext}" => '.c' do |t| c_call_string = "#{c_compiler} #{cflags} -c -o #{t.name} #{t.source}" runner.call(t, c_call_string) end rule ".#{objext}io" => ".cio" do |t| c_call_string = "#{c_mppa_compiler} -mcore=k1io -mos=rtems" c_call_string += " -mboard=developer -x c -c -o #{t.name} #{t.source}" runner.call(t, c_call_string) end rule ".#{objext}comp" => ".ccomp" do |t| c_call_string = "#{c_mppa_compiler} -mcore=k1dp -mos=nodeos" c_call_string += " -mboard=developer -x c -c -o #{t.name} #{t.source}" runner.call(t, c_call_string) end end |
#setup_compilers(probes, options = {}) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 211 def setup_compilers(probes, = {}) Rake::Task::clear verbose = [:VERBOSE] verbose = get_verbose if not verbose Rake::verbose(verbose) Rake::FileUtilsExt.verbose_flag=verbose narray_path = get_narray_path includes = get_includes(narray_path) runner = lambda { |t, call_string| if verbose then sh call_string else status, _, stderr = systemu call_string if not status.success? then puts stderr fail "#{t.source}: compilation failed" end status.success? end } setup_c_compiler(, includes, narray_path, runner, probes) setup_cxx_compiler(, includes, runner, probes) setup_fortran_compiler(, runner, probes) setup_cuda_compiler(, runner, probes) setup_linker_mppa(, runner, probes) if @architecture == MPPA return setup_linker(, probes) end |
#setup_cuda_compiler(options, runner, probes) ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 144 def setup_cuda_compiler(, runner, probes) cuda_compiler = [:NVCC] cudaflags = [:NVCCFLAGS] cudaflags += " --compiler-options '-fPIC','-D_FORCE_INLINES'" rule ".#{RbConfig::CONFIG["OBJEXT"]}" => '.cu' do |t| cuda_call_string = "#{cuda_compiler} #{cudaflags} -c -o #{t.name} #{t.source}" runner.call(t, cuda_call_string) end end |
#setup_cxx_compiler(options, includes, runner, probes) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 96 def setup_cxx_compiler(, includes, runner, probes) cxx_compiler = [:CXX] cxxflags = [:CXXFLAGS] cxxflags += " -fPIC #{includes}" if ([:openmp] or [:OPENMP]) and @lang == C and not disable_openmp then openmp_cxxflags = get_openmp_flags(cxx_compiler) raise "unkwown openmp flags for: #{cxx_compiler}" if not openmp_cxxflags cxxflags += " #{openmp_cxxflags}" end cxxflags_no_fpic = cxxflags.gsub("-fPIC","") rule ".nofpic#{RbConfig::CONFIG["OBJEXT"]}" => '.cpp' do |t| cxx_call_string = "#{cxx_compiler} #{cxxflags_no_fpic} -c -o #{t.name} #{t.source}" runner.call(t, cxx_call_string) end rule ".#{RbConfig::CONFIG["OBJEXT"]}" => '.cpp' do |t| cxx_call_string = "#{cxx_compiler} #{cxxflags} -c -o #{t.name} #{t.source}" runner.call(t, cxx_call_string) end end |
#setup_fortran_compiler(options, runner, probes) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 119 def setup_fortran_compiler(, runner, probes) f_compiler = [:FC] fcflags = [:FCFLAGS] fcflags += " -march=#{get_model}" fcflags += " -fPIC" fcflags += " -fno-second-underscore" if f_compiler == 'g95' if ([:openmp] or [:OPENMP]) and @lang == FORTRAN and not disable_openmp then openmp_fcflags = get_openmp_flags(f_compiler) raise "unkwown openmp flags for: #{f_compiler}" if not openmp_fcflags fcflags += " #{openmp_fcflags}" end fcflags_no_fpic = fcflags.gsub("-fPIC","") rule ".nofpic#{RbConfig::CONFIG["OBJEXT"]}" => '.f90' do |t| f_call_string = "#{f_compiler} #{fcflags_no_fpic} -c -o #{t.name} #{t.source}" runner.call(t, f_call_string) end rule ".#{RbConfig::CONFIG["OBJEXT"]}" => '.f90' do |t| f_call_string = "#{f_compiler} #{fcflags} -c -o #{t.name} #{t.source}" runner.call(t, f_call_string) end end |
#setup_linker(options, probes) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 175 def setup_linker(, probes) ldflags = [:LDFLAGS] ldflags += " -march=#{get_model}" ldflags += " -L#{RbConfig::CONFIG["libdir"]}" if RbConfig::CONFIG["ENABLE_SHARED"] != "no" then ldflags += " #{RbConfig::CONFIG["LIBRUBYARG"]}" else ldflags += " -Wl,-R#{RbConfig::CONFIG["libdir"]}" end probes.each { |p| ldflags += " #{p.ldflags}" if p.respond_to?(:ldflags) } ldflags += " -lcudart" if @lang == CUDA ldflags += " -L/usr/local/k1tools/lib64 -lmppaipc -lpcie -lz -lelf -lmppa_multiloader" if @architecture == MPPA ldflags += " -lmppamon -lmppabm -lm -lmppalock" if @architecture == MPPA c_compiler = [:CC] c_compiler = "cc" if not c_compiler linker = [:LD] linker = c_compiler if not linker if ([:openmp] or [:OPENMP]) and not disable_openmp then openmp_ldflags = get_openmp_flags(linker) raise "unknown openmp flags for: #{linker}" if not openmp_ldflags ldflags += " #{openmp_ldflags}" end if OS.mac? then ldshared = "-dynamic -bundle" ldshared_flags = "-Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress" else ldshared = "-shared" ldshared_flags = "-Wl,-Bsymbolic-functions -Wl,-z,relro -rdynamic -Wl,-export-dynamic" end return [linker, ldshared, ldshared_flags, ldflags] end |
#setup_linker_mppa(options, runner, probes) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/BOAST/Runtime/Compilers.rb', line 155 def setup_linker_mppa(, runner, probes) objext = RbConfig::CONFIG["OBJEXT"] ldflags = [:LDFLAGS] board = " -mboard=developer" ldflags += " -lmppaipc" linker = "k1-gcc" rule ".bincomp" => ".#{objext}comp" do |t| linker_string = "#{linker} -o #{t.name} #{t.source} -mcore=k1dp #{board} -mos=nodeos #{ldflags}" runner.call(t, linker_string) end rule ".binio" => ".#{objext}io" do |t| linker_string = "#{linker} -o #{t.name} #{t.source} -mcore=k1io #{board} -mos=rtems #{ldflags}" runner.call(t, linker_string) end end |