lib/bones/algorithm.rb in bones-compiler-1.3.1 vs lib/bones/algorithm.rb in bones-compiler-1.6.0
- old
+ new
@@ -38,11 +38,11 @@
end
@hash = {}
@lists = {:host_name => [],:host_definition => [], :argument_name => [], :argument_definition => [], :golden_name => []}
@arrays = Variablelist.new()
@constants = Variablelist.new()
- @merge_factor = nil
+ @merge_factor = 0
@register_caching_enabled = 1
@function_code = ''
@function_name = ''
# Set the initial hash
@@ -62,10 +62,11 @@
if function.node_exists?(@code)
@function_code = function
@function_name = function.name
end
end
+ raise_error("Incorrect code found in body of #{@name}, something wrong with the classification?") if @function_code == ""
end
# This method performs the code transformations according
# to the transformation settings as provided as an argument
# to the function. It calls the various code transformation
@@ -144,24 +145,29 @@
end
end
# Perform transformations for reduction operations (conditionally do this)
if transformation[1,1].to_i >= 1
- new_code = new_code.transform_reduction(@arrays.select(INPUT)[0],@arrays.select(OUTPUT)[0],transformation[1,1].to_i)
+ input = @arrays.select(INPUT)[0]
+ @arrays.select(OUTPUT).each do |output|
+ if output.species.shared?
+ new_code = new_code.transform_reduction(input,output,transformation[1,1].to_i)
+ end
+ end
end
# Perform thread-merging (experimental)
# TODO: Solve the problem related to constants (e.g chunk/example1.c)
- if @merge_factor == nil
+ if @merge_factor == 0
if transformation[0,1] == '4' && @hash[:parallelism].to_i >= 1024*1024
@merge_factor = 4
else
@merge_factor = 1
end
end
if @merge_factor > 1
- puts @hash[:parallelism]
+ #puts @hash[:parallelism]
if new_code.has_conditional_statements?
puts MESSAGE+'Not coarsening ('+@merge_factor.to_s+'x) because of conditional statements in kernel body.'
# TODO: Fix this temporary hack for multiple loops with mismatching bounds
elsif ((@hash[:parallelism].to_i % @merge_factor) != 0) || (@hash[:parallelism].to_i == 4192256)
puts MESSAGE+'Not coarsening ('+@merge_factor.to_s+'x) because of mismatching amount of parallelism ('+@hash[:parallelism]+').'
@@ -403,11 +409,15 @@
end
raise_error('No input nor output arrays detected, make sure they are properly defined') if arrays.empty?
DIRECTIONS.each do |direction|
species = @species.structures(direction)
- arrays = @arrays.select(direction)
+ if direction == INPUT && @species.shared?
+ arrays = @arrays.inputs_only
+ else
+ arrays = @arrays.select(direction)
+ end
if !arrays.empty?
# Check if the amount of input/ouput arrays is equal to the amount of input/output species
if species.length < arrays.length
array_names = arrays.map { |a| a.name }.join('","')
@@ -436,9 +446,14 @@
# Still haven't found anything, assign the species to an array of equal name
if !array
arrays.each do |free_array|
array = free_array if structure.name == free_array.name
end
+ end
+
+ # Still haven't found anything, raise an error
+ if !array
+ raise_error("Could not find a matching array in C-code for a species with name '#{species.first.name}'")
end
# Process the assignment
array.species = structure
raise_error("Species of '#{array.species.name}' is mismatched with array '#{array.name}'") if array.species.name != array.name