module BOAST
Constants
- ARCHITECTURES
- ARMCPUID_by_name
- ARMarchitectures
- AffinityProbe
@private
- BP
- Call
- Dim
- EXTENDED
- EnergyProbe
- FUNCCALLS
- INSTRUCTIONS
- LANGUAGES
- MODELS
- OP
- Var
- X86CPUID_by_name
- X86architectures
Public Class Methods
Generates setters and getters for the specified boolean state @param [Symbol] state @!macro [attach] boolean_state_accessor
@!method $1? @scope class @return the boolean evaluation of the *$1* state @!parse state_accessor $1
# File lib/BOAST/Language/State.rb, line 61 def self.boolean_state_accessor(state) state_accessor(state) s = <<EOF module_function def #{state}? @@#{state} end EOF eval s end
Generates an initializer for the specified state using default value or environment variable. Calls this initializer. @param [Symbol] state @param [Object] default default value @param [String] get_env_string if specified, an escaped string that can be evaluated. the envs variable can be used in the string to obtain what the corresponding environment variable was. Example: ‘“const_get(#{ envs })”’ @param [Symbol] env name of the corresponding environment variable @!macro [attach] default_state_getter
@!method get_default_$1 @scope class @private
# File lib/BOAST/Language/State.rb, line 83 def self.default_state_getter(state, default, get_env_string=nil, env = state.upcase) envs = "ENV['#{env}']" s = <<EOF module_function def get_default_#{state} #{state} = @@boast_config[#{state.inspect}] #{state} = #{default.inspect} unless #{state} #{state} = #{get_env_string ? eval( "#{get_env_string}" ) : "YAML::load(#{envs})" } if #{envs} return #{state} end @@#{state} = get_default_#{state} EOF eval s end
# File lib/BOAST/Language/HighLevelOperators.rb, line 138 def self.generic_trigonometric_operator_generator( name ) eval <<EOF class #{name.capitalize} < TrigonometricOperator extend Functor def get_intrinsic_symbol return :#{name.upcase} end def get_name return { C => "#{name}", CUDA => "#{name}", CL => "#{name}", FORTRAN => "#{name}" } end end EOF end
# File lib/BOAST/Language/State.rb, line 6 def self.included(base) EXTENDED.each { |m| base.send(:include, m) } end
@deprecated
# File lib/BOAST/Language/Print.rb, line 10 def self.open(a) opn(a) end
@deprecated
# File lib/BOAST/Language/Print.rb, line 5 def self.print(a, *args) pr(a, *args) end
Generates setters and getters for the specified state @param [Symbol] state @!macro [attach] state_accessor
@!method $1 @scope class @return the BOAST *$1* state @!method $1=( val ) @scope class Sets *$1* state to a new value @param val the new value of *$1* state @return the new +$1+ state @!method get_$1 @scope class @return the *$1* state @!method set_$1( val ) @scope class Sets *$1* state to a new value @param val the new value of *$1* state @return the new *$1* state
# File lib/BOAST/Language/State.rb, line 31 def self.state_accessor(state) s = <<EOF module_function def #{state}=(val) @@#{state} = val end def #{state} @@#{state} end def set_#{state}(val) @@#{state} = val end def get_#{state} @@#{state} end EOF eval s end
Public Instance Methods
Returns an annotation number for the given name. The number is incremented for a given name is incremented each time this name is called
# File lib/BOAST/Language/Algorithm.rb, line 134 def annotate_number(name) num = @@annotate_numbers[name] @@annotate_numbers[name] = num + 1 return num end
# File lib/BOAST/Language/Config.rb, line 23 def assert_boast_config_dir home_config_dir = ENV["XDG_CONFIG_HOME"] home_config_dir = "#{Dir.home}/.config" unless home_config_dir Dir.mkdir( home_config_dir ) unless File::exist?( home_config_dir ) return nil unless File::directory?(home_config_dir) boast_config_dir = "#{home_config_dir}/BOAST" Dir.mkdir( boast_config_dir ) unless File::exist?( boast_config_dir ) return nil unless File::directory?(boast_config_dir) return boast_config_dir end
One of BOAST
keywords: closes a BOAST
ControlStructure
or Procedure
. Calls the close method of the given object. @param a the BOAST
object to close
# File lib/BOAST/Language/Algorithm.rb, line 191 def close(a) a.close end
Decrements the indent level @param [Integer] increment number of space to remove
# File lib/BOAST/Language/Algorithm.rb, line 123 def decrement_indent_level(increment = get_indent_increment) set_indent_level( get_indent_level - increment ) end
Returns the symbol corresponding to the active architecture
# File lib/BOAST/Language/Algorithm.rb, line 60 def get_architecture_name return ARCHITECTURES[architecture] end
# File lib/BOAST/Runtime/Config.rb, line 110 def get_compiler_options return @@compiler_default_options.clone end
@private
# File lib/BOAST/Language/Config.rb, line 162 def get_default_architecture architecture = nil begin env = nil if ENV["ARCHITECTURE"] then env = ENV["ARCHITECTURE"] elsif ENV["ARCH"] then env = ENV["ARCH"] end raise "Error" if env and not ARCHITECTURES.include?(env) architecture = const_get(env) if env rescue raise "'#{env}' is not a valid value for ARCH or ARCHITECTURE!" end return architecture if architecture return ARM if YAML::load( OS.report )["host_cpu"].match(/arm|aarch64/) return X86 end
Returns the symbol corresponding to the active language
# File lib/BOAST/Language/Algorithm.rb, line 65 def get_lang_name return LANGUAGES[lang] end
# File lib/BOAST/Runtime/Config.rb, line 106 def get_openmp_flags return @@openmp_default_flags.clone end
# File lib/BOAST/Runtime/Config.rb, line 133 def get_run_config return @@run_config.clone end
Increments the indent level @param [Integer] increment number of space to add
# File lib/BOAST/Language/Algorithm.rb, line 117 def increment_indent_level(increment = get_indent_increment) set_indent_level( get_indent_level + increment ) end
Returns a string with as many space as the indent level.
# File lib/BOAST/Language/Algorithm.rb, line 128 def indent return " "*get_indent_level end
# File lib/BOAST/Language/Config.rb, line 156 def model=(val) set_model_old(val) Intrinsics::generate_conversions end
One of BOAST
keywords: opens a BOAST
ControlStructure
or Procedure
. Calls the open method of the given object. @param a the BOAST
object to open
# File lib/BOAST/Language/Algorithm.rb, line 184 def opn(a) a.open end
Pops the specified states values @param vars a list of state symbols
# File lib/BOAST/Language/Algorithm.rb, line 106 def pop_env(*vars) vars.each { |key| raise "Unknown module variable #{key}!" unless @@env.has_key?(key) ret = @@env[key].pop raise "No stored value for #{key}!" if ret.nil? BOAST::send("set_#{key}", ret) } end
One of BOAST
keywords: prints BOAST
objects. Annotates the given object. Calls the given object pr method with the optional arguments. @param a a BOAST
Expression
, ControlStructure
or Procedure
@param args an optional list of parameters
# File lib/BOAST/Language/Algorithm.rb, line 167 def pr(a, *args, &block) pr_annotate(a) if annotate? a.pr(*args, &block) end
Annotates an Object
by inlining a YAML structure in a comment. If
object’s class is part of the annotate list an indepth version of the annotation will be generated. @param [Object] a object to annotate
# File lib/BOAST/Language/Algorithm.rb, line 149 def pr_annotate(a) name = a.class.name.gsub("BOAST::","") if annotate_list.include?(name) then description = nil if a.is_a?(Annotation) and a.annotate_indepth?(0) then description = a.annotation(0) end annotation = { "#{name}#{annotate_number(name)}" => description } Comment(YAML::dump(annotation)).pr end end
Updates states and stores their value in a stack for later retrieval @overload push_env
( vars ) @overload push_env
( vars, &block ) @param [Hash] vars contains state symbols and values pairs @yield states will be popped after the given block is called
# File lib/BOAST/Language/Algorithm.rb, line 81 def push_env(vars, &block) keys = [] vars.each { |key, value| var = nil begin var = BOAST::send("get_#{key}") rescue BOAST::pop_env(*keys) raise "Unknown module variable #{key}!" end @@env[key].push(var) BOAST::send("set_#{key}", value) keys.push(key) } if block then begin block.call ensure BOAST::pop_env(*vars.keys) end end end
# File lib/BOAST/Runtime/Config.rb, line 75 def read_boast_compiler_config boast_config_dir = assert_boast_config_dir return unless boast_config_dir compiler_options_file = "#{boast_config_dir}/compiler_options" if File::exist?( compiler_options_file ) then File::open( compiler_options_file, "r" ) { |f| @@compiler_default_options.update( YAML::load( f.read ) ) } else File::open( compiler_options_file, "w" ) { |f| f.write YAML::dump( @@compiler_default_options ) } end openmp_flags_file = "#{boast_config_dir}/openmp_flags" if File::exist?( openmp_flags_file ) then File::open( openmp_flags_file, "r" ) { |f| @@openmp_default_flags.update( YAML::load( f.read ) ) } else File::open( openmp_flags_file, "w" ) { |f| f.write YAML::dump( @@openmp_default_flags ) } end @@compiler_default_options.each_key { |k| @@compiler_default_options[k] = ENV[k.to_s] if ENV[k.to_s] } @@compiler_default_options[:LD] = ENV["LD"] if ENV["LD"] end
# File lib/BOAST/Language/Config.rb, line 34 def read_boast_config boast_config_dir = assert_boast_config_dir return unless boast_config_dir boast_config_file = "#{boast_config_dir}/config" if File::exist?( boast_config_file ) then File::open( boast_config_file, "r" ) { |f| @@boast_config.update( YAML::load( f.read ) ) } else File::open( boast_config_file, "w" ) { |f| f.write YAML::dump( @@boast_config ) } end end
# File lib/BOAST/Runtime/Config.rb, line 114 def read_boast_run_config boast_config_dir = assert_boast_config_dir run_config_file = "#{boast_config_dir}/run_config" if File::exist?( run_config_file ) then File::open( run_config_file, "r" ) { |f| @@run_config.update( YAML::load( f.read ) ) } else File::open( run_config_file, "w" ) { |f| f.write YAML::dump( @@run_config ) } end @@run_options.each { |o| @@run_config[o] = YAML::load(ENV[o.to_s]) if ENV[o.to_s] } end
# File lib/BOAST/Language/Parens.rb, line 7 def register_funccall(name, options = {}) sym = name.to_sym ret = options[:return] ? options[:return] : options[:returns] FUNCCALLS[sym] = {} FUNCCALLS[sym][:parameters] = options[:parameters] FUNCCALLS[sym][:return] = ret s =<<EOF def self.#{name}(*args) return FuncCall(#{sym.inspect}, *args#{ ret ? ", return: FUNCCALLS[#{sym.inspect}][:return]" : ""}) end EOF eval s end
Resets the annotate_numbers to an empty Hash
# File lib/BOAST/Language/Algorithm.rb, line 141 def reset_annotate_numbers @@annotate_numbers = Hash::new { |h,k| h[k] = 0 } end
# File lib/BOAST/Language/Config.rb, line 150 def set_model(val) set_model_old(val) Intrinsics::generate_conversions end
@return the boolean evaluation of the use_vla state. false if lang is CL or CUDA.
# File lib/BOAST/Language/Config.rb, line 144 def use_vla? return false if [CL,CUDA].include?(lang) return use_vla_old? end