Module: BOAST::Compilers

Includes:
Rake::DSL
Included in:
CKernel
Defined in:
lib/BOAST/Runtime/Compilers.rb

Instance Method Summary collapse

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_pathObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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.full_gem_path
  rescue Gem::LoadError => e
  rescue NoMethodError => e
    spec = Gem::available?('narray')
    if spec then
      require 'narray' 
      narray_path = Gem.loaded_specs['narray'].full_gem_path
    end
  end
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) ⇒ Object



46
47
48
49
50
51
52
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
# File 'lib/BOAST/Runtime/Compilers.rb', line 46

def setup_c_compiler(options, includes, narray_path, runner)
  c_mppa_compiler = "k1-gcc"
  c_compiler = options[:CC]
  cflags = options[: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 (options[:openmp] or options[: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

  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(options = {}) ⇒ Object



173
174
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
# File 'lib/BOAST/Runtime/Compilers.rb', line 173

def setup_compilers(options = {})
  Rake::Task::clear
  verbose = options[: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, stdout, stderr = systemu call_string
      if not status.success? then
        puts stderr
        fail "#{t.source}: compilation failed"
      end
      status.success?
    end
  }

  setup_c_compiler(options, includes, narray_path, runner)
  setup_cxx_compiler(options, includes, runner)
  setup_fortran_compiler(options, runner)
  setup_cuda_compiler(options, runner)
  
  setup_linker_mppa(options, runner) if @architecture == MPPA

  return setup_linker(options)

end

#setup_cuda_compiler(options, runner) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/BOAST/Runtime/Compilers.rb', line 113

def setup_cuda_compiler(options, runner)
  cuda_compiler = options[:NVCC]
  cudaflags = options[: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) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/BOAST/Runtime/Compilers.rb', line 79

def setup_cxx_compiler(options, includes, runner)
  cxx_compiler = options[:CXX]
  cxxflags = options[:CXXFLAGS]
  cxxflags += " -fPIC #{includes}"
  if (options[:openmp] or options[: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

  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) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/BOAST/Runtime/Compilers.rb', line 95

def setup_fortran_compiler(options, runner)
  f_compiler = options[:FC]
  fcflags = options[:FCFLAGS]
  fcflags += " -march=#{get_model}"
  fcflags += " -fPIC"
  fcflags += " -fno-second-underscore" if f_compiler == 'g95'
  if (options[:openmp] or options[: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

  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) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/BOAST/Runtime/Compilers.rb', line 144

def setup_linker(options)
  ldflags = options[:LDFLAGS]
  ldflags += " -march=#{get_model}"
  ldflags += " -L#{RbConfig::CONFIG["libdir"]} #{RbConfig::CONFIG["LIBRUBYARG"]}"
  ldflags += " -lrt" if not OS.mac?
  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 = options[:CC]
  c_compiler = "cc" if not c_compiler
  linker = options[:LD]
  linker = c_compiler if not linker
  if (options[:openmp] or options[: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
    ldflags = "-Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress #{ldflags}"
    ldshared = "-dynamic -bundle"
  else
    ldflags = "-Wl,-Bsymbolic-functions -Wl,-z,relro -rdynamic -Wl,-export-dynamic #{ldflags}"
    ldshared = "-shared"
  end

  return [linker, ldshared, ldflags]
end

#setup_linker_mppa(options, runner) ⇒ Object



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 124

def setup_linker_mppa(options, runner)
  objext = RbConfig::CONFIG["OBJEXT"]
  ldflags = options[: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