ikra 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,155 +0,0 @@
1
- require_relative "ruby_type"
2
- require "set"
3
-
4
- module Ikra
5
- module Types
6
-
7
- # Represents a possibly polymorphic type consisting of 0..* instances of {RubyType}. Only primitive types or class types are allowed for these inner types, but not union types.
8
- class UnionType
9
- include RubyType
10
-
11
- # @return [Set<RubyType>] Inner types
12
- attr_reader :types
13
-
14
- def initialize(*types)
15
- # Check arguments
16
- types.each do |type|
17
- if type.is_union_type?
18
- raise "Union type not allowed as inner type of union type"
19
- end
20
- end
21
-
22
- @types = Set.new(types)
23
- end
24
-
25
- def to_c_type
26
- if @types.size == 1
27
- @types.first.to_c_type
28
- else
29
- "union_t"
30
- end
31
- end
32
-
33
- def to_ruby_type
34
- if @types.size == 1
35
- @types.first.to_ruby_type
36
- else
37
- raise "Not implemented yet"
38
- end
39
- end
40
-
41
- def is_primitive?
42
- if @types.size == 1
43
- @types.first.is_primitive?
44
- else
45
- false
46
- end
47
- end
48
-
49
- def is_union_type?
50
- true
51
- end
52
-
53
- def is_singleton?
54
- @types.size == 1
55
- end
56
-
57
- # Returns the single inner type or raises an error if this union type contains more than one inner type.
58
- # @return [RubyType] Inner type
59
- def singleton_type
60
- if @types.size != 1
61
- raise "Union type is not singleton"
62
- end
63
-
64
- @types.first
65
- end
66
-
67
- # Merges all inner types of the argument into this union type.
68
- # @param [UnionType] union_type The other union type
69
- # @return [Bool] true if the argument added new inner types to this union type
70
- def expand(union_type)
71
- if not union_type.is_union_type?
72
- raise "Cannot expand with non-union type"
73
- end
74
-
75
- is_expanded = (union_type.types - @types).size > 0
76
- @types.merge(union_type.types)
77
- is_expanded
78
- end
79
-
80
- # Merges all inner types of the argument into this union type.
81
- # @param [UnionType] union_type The other union type
82
- # @return [UnionType] self
83
- def expand_return_type(union_type)
84
- expand(union_type)
85
- self
86
- end
87
-
88
- def expand_with_singleton_type(singleton_type)
89
- if singleton_type.is_union_type?
90
- raise "Singleton type expected"
91
- end
92
-
93
- is_expanded = !@types.include?(singleton_type)
94
- @types.add(singleton_type)
95
- is_expanded
96
- end
97
-
98
- # Determines if this union type contains a specific singleton type.
99
- # @param [RubyType] singleton_type The other type
100
- # @return [Bool] true if the type is included
101
- def include?(singleton_type)
102
- if singleton_type.is_union_type?
103
- raise "Union type can never be included in union type"
104
- end
105
-
106
- @types.include?(singleton_type)
107
- end
108
-
109
- def include_all?(union_type)
110
- if not union_type.is_union_type?
111
- raise "Union type expected"
112
- end
113
-
114
- (union_type.types - @types).size == 0
115
- end
116
-
117
- # Alias for {#include_all?}
118
- def <=(union_type)
119
- union_type.include_all?(self)
120
- end
121
-
122
- def to_s
123
- "{#{@types.to_a.join(", ")}}"
124
- end
125
-
126
- class << self
127
- def create_int
128
- new(PrimitiveType::Int)
129
- end
130
-
131
- def create_float
132
- new(PrimitiveType::Float)
133
- end
134
-
135
- def create_bool
136
- new(PrimitiveType::Bool)
137
- end
138
-
139
- def create_void
140
- new(PrimitiveType::Void)
141
- end
142
-
143
- def create_unknown
144
- new(UnknownType::Instance)
145
- end
146
-
147
- def parameter_hash_to_s(hash)
148
- hash.map do |name, type|
149
- name.to_s + ": " + type.to_s
150
- end.join(", ")
151
- end
152
- end
153
- end
154
- end
155
- end