ikra 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ast/builder.rb +225 -77
  3. data/lib/ast/host_section_builder.rb +38 -0
  4. data/lib/ast/interpreter.rb +67 -0
  5. data/lib/ast/lexical_variables_enumerator.rb +3 -2
  6. data/lib/ast/nodes.rb +521 -31
  7. data/lib/ast/printer.rb +116 -18
  8. data/lib/ast/ssa_generator.rb +192 -0
  9. data/lib/ast/visitor.rb +235 -21
  10. data/lib/config/configuration.rb +28 -3
  11. data/lib/config/os_configuration.rb +62 -9
  12. data/lib/cpu/cpu_implementation.rb +39 -0
  13. data/lib/ikra.rb +13 -3
  14. data/lib/resources/cuda/allocate_device_memory.cpp +5 -0
  15. data/lib/resources/cuda/allocate_host_memory.cpp +1 -0
  16. data/lib/resources/cuda/allocate_memcpy_environment_to_device.cpp +11 -0
  17. data/lib/resources/cuda/ast/assignment.cpp +1 -0
  18. data/lib/resources/cuda/block_function_head.cpp +7 -1
  19. data/lib/resources/cuda/entry_point.cpp +47 -0
  20. data/lib/resources/cuda/env_builder_copy_array.cpp +8 -2
  21. data/lib/resources/cuda/free_device_memory.cpp +3 -0
  22. data/lib/resources/cuda/free_memory_for_command.cpp +24 -0
  23. data/lib/resources/cuda/header.cpp +23 -9
  24. data/lib/resources/cuda/header_structs.cpp +92 -0
  25. data/lib/resources/cuda/host_section_block_function_head.cpp +12 -0
  26. data/lib/resources/cuda/host_section_entry_point.cpp +55 -0
  27. data/lib/resources/cuda/host_section_free_device_memory.cpp +18 -0
  28. data/lib/resources/cuda/host_section_launch_parallel_section.cpp +14 -0
  29. data/lib/resources/cuda/host_section_malloc_memcpy_device_to_host.cpp +10 -0
  30. data/lib/resources/cuda/kernel.cpp +9 -2
  31. data/lib/resources/cuda/launch_kernel.cpp +5 -0
  32. data/lib/resources/cuda/memcpy_device_to_host.cpp +3 -0
  33. data/lib/resources/cuda/memcpy_device_to_host_expr.cpp +10 -0
  34. data/lib/resources/cuda/reduce_body.cpp +88 -0
  35. data/lib/resources/cuda/stencil_array_reconstruction.cpp +2 -0
  36. data/lib/resources/cuda/stencil_body.cpp +16 -0
  37. data/lib/resources/cuda/struct_definition.cpp +4 -0
  38. data/lib/ruby_core/array.rb +34 -0
  39. data/lib/ruby_core/array_command.rb +313 -0
  40. data/lib/ruby_core/core.rb +103 -0
  41. data/lib/ruby_core/interpreter.rb +16 -0
  42. data/lib/ruby_core/math.rb +32 -0
  43. data/lib/ruby_core/ruby_integration.rb +256 -0
  44. data/lib/symbolic/host_section.rb +115 -0
  45. data/lib/symbolic/input.rb +87 -0
  46. data/lib/symbolic/input_visitor.rb +68 -0
  47. data/lib/symbolic/symbolic.rb +793 -117
  48. data/lib/symbolic/visitor.rb +70 -8
  49. data/lib/translator/array_command_struct_builder.rb +163 -0
  50. data/lib/translator/ast_translator.rb +572 -0
  51. data/lib/translator/block_translator.rb +104 -48
  52. data/lib/translator/commands/array_combine_command.rb +41 -0
  53. data/lib/translator/commands/array_identity_command.rb +28 -0
  54. data/lib/translator/commands/array_index_command.rb +52 -0
  55. data/lib/translator/commands/array_reduce_command.rb +135 -0
  56. data/lib/translator/commands/array_stencil_command.rb +129 -0
  57. data/lib/translator/commands/array_zip_command.rb +30 -0
  58. data/lib/translator/commands/command_translator.rb +264 -0
  59. data/lib/translator/cuda_errors.rb +32 -0
  60. data/lib/translator/environment_builder.rb +263 -0
  61. data/lib/translator/host_section/array_host_section_command.rb +150 -0
  62. data/lib/translator/host_section/array_in_host_section_command.rb +41 -0
  63. data/lib/translator/host_section/ast_translator.rb +14 -0
  64. data/lib/translator/host_section/parallel_section_invocation_visitor.rb +20 -0
  65. data/lib/translator/host_section/program_builder.rb +89 -0
  66. data/lib/translator/input_translator.rb +226 -0
  67. data/lib/translator/kernel_builder.rb +137 -0
  68. data/lib/translator/kernel_launcher/for_loop_kernel_launcher.rb +40 -0
  69. data/lib/translator/kernel_launcher/kernel_launcher.rb +259 -0
  70. data/lib/translator/kernel_launcher/while_loop_kernel_launcher.rb +38 -0
  71. data/lib/translator/last_returns_visitor.rb +19 -10
  72. data/lib/translator/program_builder.rb +197 -0
  73. data/lib/translator/program_launcher.rb +273 -0
  74. data/lib/translator/struct_type.rb +55 -0
  75. data/lib/translator/translator.rb +34 -11
  76. data/lib/translator/variable_classifier_visitor.rb +56 -0
  77. data/lib/types/inference/ast_inference.rb +586 -0
  78. data/lib/types/inference/clear_types_visitor.rb +11 -0
  79. data/lib/types/inference/command_inference.rb +101 -0
  80. data/lib/types/inference/input_inference.rb +62 -0
  81. data/lib/types/{object_tracer.rb → inference/object_tracer.rb} +5 -6
  82. data/lib/types/inference/ruby_extension.rb +35 -0
  83. data/lib/types/inference/symbol_table.rb +131 -0
  84. data/lib/types/types.rb +14 -0
  85. data/lib/types/types/array_command_type.rb +123 -0
  86. data/lib/types/types/array_type.rb +137 -0
  87. data/lib/types/{class_type.rb → types/class_type.rb} +42 -18
  88. data/lib/types/{primitive_type.rb → types/primitive_type.rb} +20 -7
  89. data/lib/types/types/ruby_type.rb +88 -0
  90. data/lib/types/types/struct_type.rb +179 -0
  91. data/lib/types/types/union_type.rb +239 -0
  92. metadata +160 -18
  93. data/lib/ast/method_definition.rb +0 -37
  94. data/lib/ast/translator.rb +0 -264
  95. data/lib/resources/cuda/kernel_launcher.cpp +0 -28
  96. data/lib/scope.rb +0 -166
  97. data/lib/translator/command_translator.rb +0 -421
  98. data/lib/translator/local_variables_enumerator.rb +0 -35
  99. data/lib/translator/method_translator.rb +0 -24
  100. data/lib/types/array_type.rb +0 -51
  101. data/lib/types/ruby_extension.rb +0 -67
  102. data/lib/types/ruby_type.rb +0 -45
  103. data/lib/types/type_inference.rb +0 -382
  104. data/lib/types/union_type.rb +0 -155
@@ -0,0 +1,239 @@
1
+ # No explicit `require`s. This file should be includes via types.rb
2
+
3
+ require "forwardable"
4
+ require "set"
5
+
6
+ module Ikra
7
+ module Types
8
+
9
+ # Represents a possibly polymorphic type consisting of 0..* instances of {RubyType}. Only
10
+ # primitive types or class types are allowed for these inner types, but not union types.
11
+ class UnionType
12
+ include RubyType
13
+ include Enumerable
14
+ extend Forwardable
15
+
16
+ def_delegator :@types, :each
17
+
18
+ # @return [Set<RubyType>] Inner types
19
+ attr_accessor :types
20
+
21
+ def ==(other)
22
+ return other.class == self.class && other.types == self.types
23
+ end
24
+
25
+ def dup
26
+ result = super
27
+ result.types = @types.dup
28
+ return result
29
+ end
30
+
31
+ def initialize(*types)
32
+ # Check arguments
33
+ types.each do |type|
34
+ if type.is_union_type?
35
+ raise AssertionError.new(
36
+ "Union type not allowed as inner type of union type")
37
+ end
38
+ end
39
+
40
+ @types = Set.new(types)
41
+ end
42
+
43
+ def empty?
44
+ return @types.empty?
45
+ end
46
+
47
+ # Removes all type information.
48
+ def clear!
49
+ @types.clear
50
+ end
51
+
52
+ # Removes all singleton types contained in `union_type` from this type.
53
+ def remove!(union_type)
54
+ if union_type.is_singleton?
55
+ raise AssertionError.new("Union type expected")
56
+ else
57
+ @types.delete_if do |type|
58
+ union_type.include?(type)
59
+ end
60
+ end
61
+ end
62
+
63
+ def size
64
+ return @types.size
65
+ end
66
+
67
+ def to_c_type
68
+ if is_singleton?
69
+ return @types.first.to_c_type
70
+ else
71
+ return "union_t"
72
+ end
73
+ end
74
+
75
+ def c_size
76
+ if is_singleton?
77
+ return @types.first.c_size
78
+ else
79
+ return "sizeof(union_t)"
80
+ end
81
+ end
82
+
83
+ def to_ruby_type
84
+ if is_singleton?
85
+ return @types.first.to_ruby_type
86
+ else
87
+ raise NotImplementedError.new
88
+ end
89
+ end
90
+
91
+ def to_ffi_type
92
+ if is_singleton?
93
+ return @types.first.to_ffi_type
94
+ else
95
+ raise NotImplementedError.new
96
+ end
97
+ end
98
+
99
+ def is_primitive?
100
+ if is_singleton?
101
+ return @types.first.is_primitive?
102
+ else
103
+ return false
104
+ end
105
+ end
106
+
107
+ def is_union_type?
108
+ return true
109
+ end
110
+
111
+ def to_union_type
112
+ return self
113
+ end
114
+
115
+ def is_singleton?
116
+ return @types.size == 1
117
+ end
118
+
119
+ # Returns the single inner type or raises an error if this union type contains more than one inner type.
120
+ # @return [RubyType] Inner type
121
+ def singleton_type
122
+ if !is_singleton?
123
+ raise AssertionError.new(
124
+ "Union type is not singleton (found #{@types.size} types)")
125
+ end
126
+
127
+ return @types.first
128
+ end
129
+
130
+ # Merges all inner types of the argument into this union type.
131
+ # @param [UnionType] union_type The other union type
132
+ # @return [Bool] true if the argument added new inner types to this union type
133
+ def expand(union_type)
134
+ if not union_type.is_union_type?
135
+ raise AssertionError.new(
136
+ "Cannot expand with non-union type: #{union_type}")
137
+ end
138
+
139
+ is_expanded = false
140
+
141
+ for type in union_type
142
+ is_expanded = is_expanded | add(type)
143
+ end
144
+
145
+ return is_expanded
146
+ end
147
+
148
+ # Merges all inner types of the argument into this union type.
149
+ # @param [UnionType] union_type The other union type
150
+ # @return [UnionType] self
151
+ def expand_return_type(union_type)
152
+ expand(union_type)
153
+ return self
154
+ end
155
+
156
+ # Adds a singleton type to this union type.
157
+ # @return True if the type was extended
158
+ def add(singleton_type)
159
+ if singleton_type.is_union_type?
160
+ raise AssertionError.new("Singleton type expected")
161
+ end
162
+
163
+ if singleton_type == PrimitiveType::Int && include?(PrimitiveType::Float)
164
+ # Special rule: Coerce int to float
165
+ return false
166
+ elsif singleton_type == PrimitiveType::Float && include?(PrimitiveType::Int)
167
+ # Special rule: Coerce int to float
168
+ @types.delete(PrimitiveType::Int)
169
+ @types.add(singleton_type)
170
+ return true
171
+ else
172
+ is_expanded = !@types.include?(singleton_type)
173
+ @types.add(singleton_type)
174
+ return is_expanded
175
+ end
176
+ end
177
+
178
+ # Determines if this union type contains a specific singleton type.
179
+ # @param [RubyType] singleton_type The other type
180
+ # @return [Bool] true if the type is included
181
+ def include?(singleton_type)
182
+ if singleton_type.is_union_type?
183
+ raise AssertionError.new("Union type can never be included in union type")
184
+ end
185
+
186
+ @types.include?(singleton_type)
187
+ end
188
+
189
+ def include_all?(union_type)
190
+ if not union_type.is_union_type?
191
+ raise AssertionError.new("Union type expected")
192
+ end
193
+
194
+ return (union_type.types - @types).size == 0
195
+ end
196
+
197
+ # Alias for {#include_all?}
198
+ def <=(union_type)
199
+ return union_type.include_all?(self)
200
+ end
201
+
202
+ def to_s
203
+ return "U{#{@types.to_a.join(", ")}}"
204
+ end
205
+
206
+ class << self
207
+ def create_int
208
+ return new(PrimitiveType::Int)
209
+ end
210
+
211
+ def create_float
212
+ return new(PrimitiveType::Float)
213
+ end
214
+
215
+ def create_bool
216
+ return new(PrimitiveType::Bool)
217
+ end
218
+
219
+ def create_void
220
+ return new(PrimitiveType::Void)
221
+ end
222
+
223
+ def create_nil
224
+ return new(PrimitiveType::Nil)
225
+ end
226
+
227
+ def create_unknown
228
+ return new(UnknownType::Instance)
229
+ end
230
+
231
+ def parameter_hash_to_s(hash)
232
+ return hash.map do |name, type|
233
+ name.to_s + ": " + type.to_s
234
+ end.join(", ")
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ikra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Springer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-04 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -70,6 +70,90 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 0.8.2
73
+ - !ruby/object:Gem::Dependency
74
+ name: ruby2ruby
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 1.3.1
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: 1.3.1
87
+ - !ruby/object:Gem::Dependency
88
+ name: sexp_processor
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: 3.2.0
94
+ type: :runtime
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 3.2.0
101
+ - !ruby/object:Gem::Dependency
102
+ name: ruby_parser
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: 2.3.1
108
+ type: :runtime
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: 2.3.1
115
+ - !ruby/object:Gem::Dependency
116
+ name: file-tail
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: 1.0.10
122
+ type: :runtime
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: 1.0.10
129
+ - !ruby/object:Gem::Dependency
130
+ name: bacon
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: pry
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
73
157
  description: GPGPU Accelerator for Array-based Computations
74
158
  email: matthias.springer@acm.org
75
159
  executables: []
@@ -77,24 +161,50 @@ extensions: []
77
161
  extra_rdoc_files: []
78
162
  files:
79
163
  - lib/ast/builder.rb
164
+ - lib/ast/host_section_builder.rb
165
+ - lib/ast/interpreter.rb
80
166
  - lib/ast/lexical_variables_enumerator.rb
81
- - lib/ast/method_definition.rb
82
167
  - lib/ast/nodes.rb
83
168
  - lib/ast/printer.rb
84
- - lib/ast/translator.rb
169
+ - lib/ast/ssa_generator.rb
85
170
  - lib/ast/visitor.rb
86
171
  - lib/config/configuration.rb
87
172
  - lib/config/os_configuration.rb
173
+ - lib/cpu/cpu_implementation.rb
88
174
  - lib/entity.rb
89
175
  - lib/ikra.rb
90
176
  - lib/parsing.rb
177
+ - lib/resources/cuda/allocate_device_memory.cpp
178
+ - lib/resources/cuda/allocate_host_memory.cpp
179
+ - lib/resources/cuda/allocate_memcpy_environment_to_device.cpp
180
+ - lib/resources/cuda/ast/assignment.cpp
91
181
  - lib/resources/cuda/block_function_head.cpp
182
+ - lib/resources/cuda/entry_point.cpp
92
183
  - lib/resources/cuda/env_builder_copy_array.cpp
184
+ - lib/resources/cuda/free_device_memory.cpp
185
+ - lib/resources/cuda/free_memory_for_command.cpp
93
186
  - lib/resources/cuda/header.cpp
187
+ - lib/resources/cuda/header_structs.cpp
188
+ - lib/resources/cuda/host_section_block_function_head.cpp
189
+ - lib/resources/cuda/host_section_entry_point.cpp
190
+ - lib/resources/cuda/host_section_free_device_memory.cpp
191
+ - lib/resources/cuda/host_section_launch_parallel_section.cpp
192
+ - lib/resources/cuda/host_section_malloc_memcpy_device_to_host.cpp
94
193
  - lib/resources/cuda/kernel.cpp
95
- - lib/resources/cuda/kernel_launcher.cpp
194
+ - lib/resources/cuda/launch_kernel.cpp
195
+ - lib/resources/cuda/memcpy_device_to_host.cpp
196
+ - lib/resources/cuda/memcpy_device_to_host_expr.cpp
197
+ - lib/resources/cuda/reduce_body.cpp
96
198
  - lib/resources/cuda/soa_header.cpp
97
- - lib/scope.rb
199
+ - lib/resources/cuda/stencil_array_reconstruction.cpp
200
+ - lib/resources/cuda/stencil_body.cpp
201
+ - lib/resources/cuda/struct_definition.cpp
202
+ - lib/ruby_core/array.rb
203
+ - lib/ruby_core/array_command.rb
204
+ - lib/ruby_core/core.rb
205
+ - lib/ruby_core/interpreter.rb
206
+ - lib/ruby_core/math.rb
207
+ - lib/ruby_core/ruby_integration.rb
98
208
  - lib/sourcify/Gemfile
99
209
  - lib/sourcify/HISTORY.txt
100
210
  - lib/sourcify/LICENSE
@@ -277,24 +387,56 @@ files:
277
387
  - lib/sourcify/spec/raw_scanner/slash_operator_shared_spec.rb
278
388
  - lib/sourcify/spec/run_build.sh
279
389
  - lib/sourcify/spec/spec_helper.rb
390
+ - lib/symbolic/host_section.rb
391
+ - lib/symbolic/input.rb
392
+ - lib/symbolic/input_visitor.rb
280
393
  - lib/symbolic/symbolic.rb
281
394
  - lib/symbolic/visitor.rb
395
+ - lib/translator/array_command_struct_builder.rb
396
+ - lib/translator/ast_translator.rb
282
397
  - lib/translator/block_translator.rb
283
- - lib/translator/command_translator.rb
398
+ - lib/translator/commands/array_combine_command.rb
399
+ - lib/translator/commands/array_identity_command.rb
400
+ - lib/translator/commands/array_index_command.rb
401
+ - lib/translator/commands/array_reduce_command.rb
402
+ - lib/translator/commands/array_stencil_command.rb
403
+ - lib/translator/commands/array_zip_command.rb
404
+ - lib/translator/commands/command_translator.rb
405
+ - lib/translator/cuda_errors.rb
406
+ - lib/translator/environment_builder.rb
407
+ - lib/translator/host_section/array_host_section_command.rb
408
+ - lib/translator/host_section/array_in_host_section_command.rb
409
+ - lib/translator/host_section/ast_translator.rb
410
+ - lib/translator/host_section/parallel_section_invocation_visitor.rb
411
+ - lib/translator/host_section/program_builder.rb
412
+ - lib/translator/input_translator.rb
413
+ - lib/translator/kernel_builder.rb
414
+ - lib/translator/kernel_launcher/for_loop_kernel_launcher.rb
415
+ - lib/translator/kernel_launcher/kernel_launcher.rb
416
+ - lib/translator/kernel_launcher/while_loop_kernel_launcher.rb
284
417
  - lib/translator/last_returns_visitor.rb
285
- - lib/translator/local_variables_enumerator.rb
286
- - lib/translator/method_translator.rb
418
+ - lib/translator/program_builder.rb
419
+ - lib/translator/program_launcher.rb
420
+ - lib/translator/struct_type.rb
287
421
  - lib/translator/translator.rb
422
+ - lib/translator/variable_classifier_visitor.rb
288
423
  - lib/type_aware_array.rb
289
- - lib/types/array_type.rb
290
- - lib/types/class_type.rb
291
- - lib/types/object_tracer.rb
292
- - lib/types/primitive_type.rb
293
- - lib/types/ruby_extension.rb
294
- - lib/types/ruby_type.rb
295
- - lib/types/type_inference.rb
296
- - lib/types/union_type.rb
297
- homepage: https://github.com/prg-titech/ikra-ruby
424
+ - lib/types/inference/ast_inference.rb
425
+ - lib/types/inference/clear_types_visitor.rb
426
+ - lib/types/inference/command_inference.rb
427
+ - lib/types/inference/input_inference.rb
428
+ - lib/types/inference/object_tracer.rb
429
+ - lib/types/inference/ruby_extension.rb
430
+ - lib/types/inference/symbol_table.rb
431
+ - lib/types/types.rb
432
+ - lib/types/types/array_command_type.rb
433
+ - lib/types/types/array_type.rb
434
+ - lib/types/types/class_type.rb
435
+ - lib/types/types/primitive_type.rb
436
+ - lib/types/types/ruby_type.rb
437
+ - lib/types/types/struct_type.rb
438
+ - lib/types/types/union_type.rb
439
+ homepage: https://prg-titech.github.io/ikra-ruby/
298
440
  licenses:
299
441
  - MIT
300
442
  metadata: {}