lib/bones/engine.rb in bones-compiler-1.3.1 vs lib/bones/engine.rb in bones-compiler-1.6.0
- old
+ new
@@ -89,20 +89,20 @@
opt :application, 'Input application file', :short => 'a', :type => String
opt :target, 'Target processor (choose from: '+pp_targets+')', :short => 't', :type => String
opt :measurements, 'Enable/disable timers', :short => 'm', :default => false
opt :verify, 'Verify correctness of the generated code', :short => 'c', :default => false
opt :only_alg_number, 'Only generate code for the x-th species (99 -> all)', :short => 'o', :type => Integer, :default => 99
- opt :merge_factor, 'Thread merge factor, default is 1 (==disabled)', :short => 'f', :type => Integer, :default => 1
+ opt :merge_factor, 'Thread merge factor, default is 1 (==disabled)', :short => 'f', :type => Integer, :default => 0
opt :register_caching,'Enable register caching: 1:enabled (default), 0:disabled', :short => 'r', :type => Integer, :default => 1
opt :zero_copy ,'Enable OpenCL zero-copy: 1:enabled (default), 0:disabled', :short => 'z', :type => Integer, :default => 1
opt :skeletons ,'Enable non-default skeletons: 1:enabled (default), 0:disabled', :short => 's', :type => Integer, :default => 1
end
Trollop::die 'no input file supplied (use: --application)' if !@options[:application_given]
Trollop::die 'no target supplied (use: --target)' if !@options[:target_given]
- Trollop::die 'input file "'+@options[:application]+'"does not exist ' if !File.exists?(@options[:application])
+ Trollop::die 'input file "'+@options[:application]+'" does not exist' if !File.exists?(@options[:application])
Trollop::die 'target not supported, supported targets are: '+pp_targets if !targets.include?(@options[:target].upcase)
- @options[:name] = @options[:application].split('/').last.split('.').first
+ @options[:name] = File.basename(@options[:application], ".*")
@options[:target] = @options[:target].upcase
# Extension for the host files corresponding to the target.
@extension = File.extname(Dir[File.join(BONES_DIR_SKELETONS,@options[:target],'common','*')][0])
@@ -202,13 +202,14 @@
@result[:host_declarations].push('void bones_synchronize(int bones_task_id);')
# Perform code generation (memory allocs)
allocs = []
preprocessor.copies.each do |copy|
- if !allocs.include?(copy.name)
+ name_scop = Set.new([copy.name, copy.scop])
+ if !allocs.include?(name_scop)
generate_memory('alloc',copy,arrays,0)
- allocs << copy.name
+ allocs << name_scop
end
end
# Perform code generation (memory copies)
preprocessor.copies.each_with_index do |copy,index|
@@ -217,13 +218,14 @@
end
# Perform code generation (memory frees)
frees = []
preprocessor.copies.each do |copy|
- if !frees.include?(copy.name)
+ name_scop = Set.new([copy.name, copy.scop])
+ if !frees.include?(name_scop)
generate_memory('free',copy,arrays,0)
- frees << copy.name
+ frees << name_scop
end
end
end
@@ -238,11 +240,11 @@
# * +target+ - a file containing the host code for the target.
# * +kernel+ - a file containing the kernel code for the target.
def write_output
# Create a new directory for the output
- directory = @options[:application].split('.').first+'_'+@options[:target]
+ directory = @options[:application].rpartition('.').first+'_'+@options[:target]
Dir.mkdir(directory,0744) unless File.directory?(directory)
parser = C::Parser.new
parser.type_names << 'FILE'
parser.type_names << 'size_t'
@@ -271,16 +273,17 @@
verification.puts @result[:verify_code]
end
end
# Populate the target file (host)
+
File.open(File.join(directory,@options[:name]+OUTPUT_HOST+@extension),'w') do |target|
target.puts '#include <cuda_runtime.h>'+NL if @options[:target] == 'GPU-CUDA'
target.puts "#define ZEROCOPY 0"+NL if @options[:zero_copy] == 0 && @options[:target] == 'CPU-OPENCL-INTEL'
target.puts "#define ZEROCOPY 1"+NL if @options[:zero_copy] == 1 && @options[:target] == 'CPU-OPENCL-INTEL'
target.puts @result[:header_code]
target.puts
- target.puts @result[:host_device_mem_globals]
+ target.puts @result[:host_device_mem_globals].uniq
target.puts
target.puts @result[:algorithm_declarations]
target.puts @result[:host_code_lists]
target.puts
target.puts File.read(File.join(@dir[:common_library],GLOBAL_TIMERS+@extension))