Module: BOAST
- Extended by:
- TypeTransition
- Defined in:
- lib/BOAST/If.rb,
lib/BOAST/For.rb,
lib/BOAST/Case.rb,
lib/BOAST/Index.rb,
lib/BOAST/Print.rb,
lib/BOAST/State.rb,
lib/BOAST/While.rb,
lib/BOAST/Parens.rb,
lib/BOAST/Pragma.rb,
lib/BOAST/CKernel.rb,
lib/BOAST/FuncCall.rb,
lib/BOAST/Functors.rb,
lib/BOAST/Variable.rb,
lib/BOAST/Algorithm.rb,
lib/BOAST/DataTypes.rb,
lib/BOAST/Operators.rb,
lib/BOAST/Procedure.rb,
lib/BOAST/Arithmetic.rb,
lib/BOAST/Expression.rb,
lib/BOAST/Inspectable.rb,
lib/BOAST/Transitions.rb,
lib/BOAST/BOAST_OpenCL.rb,
lib/BOAST/Optimization.rb,
lib/BOAST/ControlStructure.rb
Defined Under Namespace
Modules: Arithmetic, Functor, Inspectable, PrivateStateAccessor, TypeTransition, VarFunctor
Classes: Addition, Affectation, BasicBinaryOperator, BooleanParameter, CKernel, CStruct, Case, ConstArray, ControlStructure, CustomType, DataType, Different, Dimension, Division, Expression, For, FuncCall, GenericOptimization, If, Index, Int, Minus, Multiplication, Not, Operator, OptimizationParameter, Pragma, Procedure, Real, Set, Sizet, Substraction, Ternary, Variable, While
Constant Summary
collapse
- FORTRAN_LINE_LENGTH =
72
- FORTRAN =
1
- C =
2
- CL =
3
- CUDA =
4
- X86 =
1
- ARM =
2
- Var =
Variable
- Dim =
Dimension
- Call =
FuncCall
- OCL_CUDA_DIM_ASSOC =
{ 0 => "x", 1 => "y", 2 => "z" }
- CUDA_THREADIDX =
CStruct("threadIdx",:type_name => "cuda_trheadIdx", :members => [Int("x", :signed => false),Int("y", :signed => false),Int("z", :signed => false)])
- CUDA_BLOCKIDX =
CStruct("blockIdx",:type_name => "cuda_blockIdx", :members => [Int("x", :signed => false),Int("y", :signed => false),Int("z", :signed => false)])
- CUDA_BLOCKDIM =
CStruct("blockDim",:type_name => "cuda_blockDim", :members => [Int("x", :signed => false),Int("y", :signed => false),Int("z", :signed => false)])
- CUDA_GRIDDIM =
CStruct("gridDim",:type_name => "cuda_gridDim", :members => [Int("x", :signed => false),Int("y", :signed => false),Int("z", :signed => false)])
- OP =
OptimizationParameter
- BP =
BooleanParameter
- @@compiler_default_options =
{
:FC => 'gfortran',
:FCFLAGS => '-O2 -Wall',
:CC => 'gcc',
:CFLAGS => '-O2 -Wall',
:CXX => 'g++',
:CXXFLAGS => '-O2 -Wall',
:NVCC => 'nvcc',
:NVCCFLAGS => '-O2',
:LDFLAGS => '',
:CLFLAGS => '',
:CLVENDOR => nil,
:CLPLATFORM => nil,
:CLDEVICE => nil,
:CLDEVICETYPE => nil,
:openmp => false
}
- @@openmp_default_flags =
{
"gcc" => "-fopenmp",
"icc" => "-openmp",
"gfortran" => "-fopenmp",
"ifort" => "-openmp",
"g++" => "-fopenmp",
"icpc" => "-openmp"
}
- @@verbose =
false
- @@output =
STDOUT
- @@lang =
get_default_lang
- @@replace_constants =
true
- @@default_int_size =
4
- @@default_int_signed =
true
- @@default_real_size =
8
- @@indent_level =
0
- @@indent_increment =
2
- @@array_start =
1
- @@chain_code =
false
- @@architecture =
X86
- @@debug =
get_default_debug
- @@env =
Hash::new{|h, k| h[k] = []}
- @@boast_inspect =
false
Class Method Summary
collapse
get_transition, set_transition, transition
Class Method Details
.barrier(*locality) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/BOAST/BOAST_OpenCL.rb', line 12
def barrier(*locality)
if lang == CL then
loc=""
if locality.include?(:local) and locality.include?(:global) then
return FuncCall::new("barrier","CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE")
elsif locality.include?(:local) then
return FuncCall::new("barrier","CLK_LOCAL_MEM_FENCE")
elsif locality.include?(:global) then
return FuncCall::new("barrier","CLK_GLOBAL_MEM_FENCE")
else
raise "Unsupported locality"
end
elsif lang == CUDA then
return FuncCall::new("__syncthreads")
else
raise "Unsupported language!"
end
end
|
.boolean_state_accessor(*args) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/BOAST/State.rb', line 27
def self.boolean_state_accessor(*args)
self.state_accessor(*args)
args.each { |arg|
s = <<EOF
def #{arg}?
!!@@#{arg}
end
module_function :#{arg}?
EOF
eval s
}
end
|
.close(a) ⇒ Object
130
131
132
|
# File 'lib/BOAST/Algorithm.rb', line 130
def close(a)
a.close
end
|
.decl(*a) ⇒ Object
124
125
126
127
128
|
# File 'lib/BOAST/Algorithm.rb', line 124
def decl(*a)
a.each { |d|
d.decl
}
end
|
.decrement_indent_level(increment = get_indent_increment) ⇒ Object
112
113
114
|
# File 'lib/BOAST/Algorithm.rb', line 112
def decrement_indent_level(increment = get_indent_increment)
set_indent_level( get_indent_level - increment )
end
|
.functorize(klass) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/BOAST/Functors.rb', line 4
def functorize(klass)
name = klass.name.split('::').last
s = <<EOF
def #{name}(*args,&block)
#{name}::new(*args,&block)
end
module_function :#{name}
EOF
eval s
end
|
.get_compiler_options ⇒ Object
88
89
90
|
# File 'lib/BOAST/CKernel.rb', line 88
def get_compiler_options
return @@compiler_default_options.clone
end
|
.get_default_debug ⇒ Object
65
66
67
68
69
|
# File 'lib/BOAST/Algorithm.rb', line 65
def get_default_debug
debug = false
debug = ENV["DEBUG"] if ENV["DEBUG"]
return debug
end
|
.get_default_lang ⇒ Object
59
60
61
62
63
|
# File 'lib/BOAST/Algorithm.rb', line 59
def get_default_lang
lang = const_get(ENV["BOAST_LANG"]) if ENV["BOAST_LANG"]
return lang if lang
return FORTRAN
end
|
.get_global_id(dim) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/BOAST/BOAST_OpenCL.rb', line 52
def get_global_id(dim)
if lang == CL then
return FuncCall::new("get_global_id",dim, :returns => Sizet)
elsif lang == CUDA then
d = OCL_CUDA_DIM_ASSOC[dim]
raise "Unsupported dimension!" if not d
return eval "CUDA_THREADIDX.#{d}+CUDA_BLOCKIDX.#{d}*CUDA_BLOCKDIM.#{d}"
else
raise "Unsupported language!"
end
end
|
.get_global_size(dim) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/BOAST/BOAST_OpenCL.rb', line 40
def get_global_size(dim)
if lang == CL then
return FuncCall::new("get_global_size", dim, :returns => Sizet)
elsif lang == CUDA then
d = OCL_CUDA_DIM_ASSOC[dim]
raise "Unsupported dimension!" if not d
return eval "CUDA_GRIDDIM.#{d}*CUDA_BLOCKDIM.#{d}"
else
raise "Unsupported language!"
end
end
|
.get_group_id(dim) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/BOAST/BOAST_OpenCL.rb', line 100
def get_group_id(dim)
if lang == CL then
return FuncCall::new("get_group_id",dim, :returns => Sizet)
elsif lang == CUDA then
d = OCL_CUDA_DIM_ASSOC[dim]
raise "Unsupported dimension!" if not d
return eval "CUDA_BLOCKIDX.#{d}"
else
raise "Unsupported language!"
end
end
|
.get_local_id(dim) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/BOAST/BOAST_OpenCL.rb', line 76
def get_local_id(dim)
if lang == CL then
return FuncCall::new("get_local_id",dim, :returns => Sizet)
elsif lang == CUDA then
d = OCL_CUDA_DIM_ASSOC[dim]
raise "Unsupported dimension!" if not d
return eval "CUDA_THREADIDX.#{d}"
else
raise "Unsupported language!"
end
end
|
.get_local_size(dim) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/BOAST/BOAST_OpenCL.rb', line 64
def get_local_size(dim)
if lang == CL then
return FuncCall::new("get_local_size",dim, :returns => Sizet)
elsif lang == CUDA then
d = OCL_CUDA_DIM_ASSOC[dim]
raise "Unsupported dimension!" if not d
return eval "CUDA_BLOCKDIM.#{d}"
else
raise "Unsupported language!"
end
end
|
.get_num_groups(dim) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/BOAST/BOAST_OpenCL.rb', line 88
def get_num_groups(dim)
if lang == CL then
return FuncCall::new("get_num_groups",dim, :returns => Sizet)
elsif lang == CUDA then
d = OCL_CUDA_DIM_ASSOC[dim]
raise "Unsupported dimension!" if not d
return eval "CUDA_GRIDDIM.#{d}"
else
raise "Unsupported language!"
end
end
|
.get_openmp_flags ⇒ Object
84
85
86
|
# File 'lib/BOAST/CKernel.rb', line 84
def get_openmp_flags
return @@openmp_default_flags.clone
end
|
.get_work_dim ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/BOAST/BOAST_OpenCL.rb', line 32
def get_work_dim
if lang == CL then
return FuncCall::new("get_work_dim", :returns => Int("wd", :signed => false))
else
raise "Unsupported language!"
end
end
|
.increment_indent_level(increment = get_indent_increment) ⇒ Object
108
109
110
|
# File 'lib/BOAST/Algorithm.rb', line 108
def increment_indent_level(increment = get_indent_increment)
set_indent_level( get_indent_level + increment )
end
|
.indent ⇒ Object
116
117
118
|
# File 'lib/BOAST/Algorithm.rb', line 116
def indent
return " "*get_indent_level
end
|
.open(a) ⇒ Object
7
8
9
|
# File 'lib/BOAST/Print.rb', line 7
def self.open(a)
a.open
end
|
.opn(a) ⇒ Object
134
135
136
|
# File 'lib/BOAST/Algorithm.rb', line 134
def opn(a)
a.open
end
|
.pop_env(*vars) ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'lib/BOAST/Algorithm.rb', line 99
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?
class_variable_set("@@"+key.to_s, ret)
}
end
|
.pr(a) ⇒ Object
120
121
122
|
# File 'lib/BOAST/Algorithm.rb', line 120
def pr(a)
a.pr
end
|
.print(a) ⇒ Object
3
4
5
|
# File 'lib/BOAST/Print.rb', line 3
def self.print(a)
a.pr
end
|
.push_env(vars = {}) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/BOAST/Algorithm.rb', line 86
def push_env(vars = {})
vars.each { |key,value|
var = nil
begin
var = class_variable_get("@@"+key.to_s)
rescue
raise "Unknown module variable #{key}!"
end
@@env[key].push(var)
class_variable_set("@@"+key.to_s, value)
}
end
|
.read_boast_config ⇒ Object
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
78
79
80
|
# File 'lib/BOAST/CKernel.rb', line 48
def read_boast_config
home_config_dir = ENV["XDG_CONFIG_HOME"]
home_config_dir = "#{Dir.home}/.config" if not home_config_dir
Dir.mkdir( home_config_dir ) if not File::exist?( home_config_dir )
return if not File::directory?(home_config_dir)
boast_config_dir = "#{home_config_dir}/BOAST"
Dir.mkdir( boast_config_dir ) if not File::exist?( 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"]
@@verbose = ENV["VERBOSE"] if ENV["VERBOSE"]
end
|
.register_funccall(name) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/BOAST/Parens.rb', line 5
def register_funccall(name)
s =<<EOF
def self.#{name}(*args)
return FuncCall("#{name}", *args)
end
EOF
eval s
end
|
.Return(value) ⇒ Object
5
6
7
|
# File 'lib/BOAST/Expression.rb', line 5
def Return(value)
return Expression("return",nil, value)
end
|
.state_accessor(*args) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/BOAST/State.rb', line 3
def self.state_accessor(*args)
args.each { |arg|
s = <<EOF
def #{arg}=(val)
@@#{arg} = val
end
module_function :#{arg}=
def #{arg}
@@#{arg}
end
module_function :#{arg}
def set_#{arg}(val)
@@#{arg} = val
end
module_function :set_#{arg}
def get_#{arg}
@@#{arg}
end
module_function :get_#{arg}
EOF
eval s
}
end
|
.var_functorize(klass) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/BOAST/Functors.rb', line 16
def var_functorize(klass)
name = klass.name.split('::').last
s = <<EOF
def #{name}(*args,&block)
Variable::new(args[0],#{name},*args[1..-1], &block)
end
module_function :#{name}
EOF
eval s
end
|