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
@@ -1,18 +1,43 @@
1
+ require 'fileutils'
2
+
3
+ require_relative "../symbolic/symbolic"
4
+
1
5
  module Ikra
2
6
  module Configuration
3
7
  JOB_REORDERING = true
4
8
  @@expect_file_name = "last_generated"
5
9
 
6
10
  def self.resource_file_name(file_name)
7
- File.expand_path("resources/cuda/#{file_name}", File.dirname(File.dirname(File.expand_path(__FILE__))))
11
+ File.expand_path("resources/cuda/#{file_name}", File.dirname(File.dirname(File.expand_path(__FILE__))))
12
+ end
13
+
14
+ def self.codegen_expect_file_name_for(file_name)
15
+ FileUtils.mkdir_p(File.expand_path("gen/codegen_expect", File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))))
16
+
17
+ File.expand_path("gen/codegen_expect/#{file_name}", File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))))
18
+ end
19
+
20
+ def self.log_file_name_for(test_case_name)
21
+ FileUtils.mkdir_p(File.expand_path("gen/log", File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))))
22
+
23
+ File.expand_path("gen/log/#{test_case_name}.log", File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))))
8
24
  end
9
25
 
10
26
  def self.codegen_expect_file_name
11
- File.expand_path("gen/codegen_expect/#{@@expect_file_name}.cu", File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))))
27
+ if @@expect_file_name == nil
28
+ # Do not generate expect file
29
+ return nil
30
+ end
31
+
32
+ return codegen_expect_file_name_for(@@expect_file_name + ".cu")
12
33
  end
13
34
 
14
35
  def self.codegen_expect_file_name=(value)
15
- @@expect_file_name = value
36
+ @@expect_file_name = value
37
+ end
38
+
39
+ def self.reset_state
40
+ Symbolic::ArrayCommand.reset_unique_id
16
41
  end
17
42
  end
18
43
  end
@@ -1,25 +1,78 @@
1
1
  require "rbconfig"
2
+ require "logger"
2
3
 
3
4
  module Ikra
4
5
  module Configuration
6
+
7
+ # These values are used only if auto configuration fails
8
+ @cuda_manual_nvcc = "/usr/local/cuda-8.0/bin/nvcc"
9
+ @cuda_manual_common_include = "/home/matthias/NVIDIA_CUDA-7.5_Samples/common/inc"
10
+ @cuda_manual_cupti_include = "/usr/local/cuda-7.5/extras/CUPTI/include"
11
+
12
+ @is_initialized = false
13
+ @auto_config = true
14
+
5
15
  class << self
6
16
  SUPPORTED_OS = [:linux, :macosx]
7
- CUDA_NVCC = "/Developer/NVIDIA/CUDA-7.5/bin/nvcc"
17
+ ATTEMPT_AUTO_CONFIG = true
18
+
19
+ attr_accessor :cuda_manual_nvcc
20
+ attr_accessor :cuda_manual_common_include
21
+ attr_accessor :cuda_manual_cupti_include
22
+ attr_accessor :auto_config
23
+
24
+ def is_initialized?
25
+ return @is_initialized
26
+ end
8
27
 
9
- def check_software_configuration
28
+ def reinitialize!
10
29
  if !SUPPORTED_OS.include?(operating_system)
11
- raise "Operating system not supported: #{operating_system}"
30
+ raise AssertionError.new("Operating system not supported: #{operating_system}")
31
+ end
32
+
33
+ @cuda_nvcc = cuda_manual_nvcc
34
+ @cuda_common_include = cuda_manual_common_include
35
+ @cuda_cupti_include = cuda_manual_cupti_include
36
+
37
+ # Auto configuration
38
+ if auto_config
39
+ Log.info("Attempting CUDA path auto configuration")
40
+
41
+ nvcc_path = %x(which nvcc)
42
+
43
+ if $?.exitstatus == 0
44
+ cuda_path = File.expand_path("../..", nvcc_path)
45
+ @cuda_nvcc = File.expand_path("bin/nvcc", cuda_path)
46
+ @cuda_common_include = File.expand_path("samples/common/inc", cuda_path)
47
+ @cuda_cupti_include = File.expand_path("extras/CUPTI/include", cuda_path)
48
+ else
49
+ Log.warn("CUDA path auto configuration failed")
50
+ end
12
51
  end
13
52
 
14
53
  # Check if nvcc is installed
15
- %x(#{CUDA_NVCC})
54
+ %x(#{@cuda_nvcc} 2>&1)
16
55
  if $?.exitstatus != 1
17
- raise "nvcc not installed"
56
+ raise AssertionError.new("nvcc not installed")
18
57
  end
58
+
59
+ if !File.directory?(@cuda_common_include)
60
+ raise AssertionError.new("Directory does not exist: #{@cuda_common_include}. Check OS configuration!")
61
+ end
62
+
63
+ if !File.directory?(@cuda_cupti_include)
64
+ raise AssertionError.new("Directory does not exist: #{@cuda_cupti_include}. Check OS configuration!")
65
+ end
66
+
67
+ @is_initialized = true
19
68
  end
20
69
 
21
70
  def nvcc_invocation_string(in_file, out_file)
22
- "#{CUDA_NVCC} -o #{out_file} -I/usr/local/cuda/samples/common/inc --shared -Xcompiler -fPIC #{in_file}"
71
+ if !is_initialized?
72
+ reinitialize!
73
+ end
74
+
75
+ return "#{@cuda_nvcc} -o #{out_file} -I#{@cuda_common_include} -I#{@cuda_cupti_include} --shared -Xcompiler -fPIC -std=c++11 #{in_file} 2>&1"
23
76
  end
24
77
 
25
78
  def so_suffix
@@ -30,7 +83,7 @@ module Ikra
30
83
  elsif operating_system == :windows
31
84
  "dll"
32
85
  else
33
- raise "Operating system not supported"
86
+ raise AssertionError.new("Operating system not supported")
34
87
  end
35
88
  end
36
89
 
@@ -48,9 +101,9 @@ module Ikra
48
101
  when /solaris|bsd/
49
102
  :unix
50
103
  else
51
- raise "Unknown operating system"
104
+ raise AssertionError.new("Unknown operating system")
52
105
  end
53
106
  end
54
107
  end
55
108
  end
56
- end
109
+ end
@@ -0,0 +1,39 @@
1
+ class Array
2
+ def stencil(neighbors, out_of_range_value, use_parameter_array: true, with_index: false, &block)
3
+ copy = self.dup
4
+
5
+ return Array.new(size) do |index|
6
+ if neighbors.min + index < 0 || neighbors.max + index > size - 1
7
+ out_of_range_value
8
+ else
9
+ values = neighbors.map do |offset|
10
+ copy[index + offset]
11
+ end
12
+
13
+ if use_parameter_array
14
+ if with_index
15
+ block.call(values, index)
16
+ else
17
+ block.call(values)
18
+ end
19
+ else
20
+ if with_index
21
+ block.call(*values, index)
22
+ else
23
+ block.call(*values)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ def combine(*others, &block)
31
+ return Array.new(self.size) do |index|
32
+ other_elements = others.map do |other|
33
+ other[index]
34
+ end
35
+
36
+ block.call(self[index], *other_elements)
37
+ end
38
+ end
39
+ end
@@ -1,7 +1,17 @@
1
1
  require "logger"
2
- require_relative "symbolic/symbolic"
3
- require_relative "entity"
4
2
 
5
3
  module Ikra
6
4
  Log = Logger.new(STDOUT)
7
- end
5
+
6
+ class AssertionError < RuntimeError
7
+
8
+ end
9
+ end
10
+
11
+ require_relative "ruby_core/ruby_integration"
12
+ require_relative "symbolic/symbolic"
13
+ require_relative "entity"
14
+ require_relative "translator/cuda_errors"
15
+ require_relative "cpu/cpu_implementation"
16
+
17
+ Ikra::Translator::CommandTranslator::ProgramBuilder::Launcher.reset_time
@@ -0,0 +1,5 @@
1
+ timeStartMeasure();
2
+ /*{type}*/ * /*{name}*/;
3
+ checkErrorReturn(program_result, cudaMalloc(&/*{name}*/, /*{bytes}*/));
4
+ program_result->device_allocations->push_back(/*{name}*/);
5
+ timeReportMeasure(program_result, allocate_memory);
@@ -0,0 +1 @@
1
+ /*{type}*/ * /*{name}*/ = (/*{type}*/ *) malloc(/*{bytes}*/);
@@ -0,0 +1,11 @@
1
+ /* Allocate device environment and copy over struct */
2
+ environment_t */*{dev_env}*/;
3
+
4
+ timeStartMeasure();
5
+ checkErrorReturn(program_result, cudaMalloc(&/*{dev_env}*/, sizeof(environment_t)));
6
+ timeReportMeasure(program_result, allocate_memory);
7
+
8
+ timeStartMeasure();
9
+ checkErrorReturn(program_result, cudaMemcpy(/*{dev_env}*/, /*{host_env}*/, sizeof(environment_t), cudaMemcpyHostToDevice));
10
+ timeReportMeasure(program_result, transfer_memory);
11
+
@@ -0,0 +1 @@
1
+ /*{target}*/ = /*{source}*/
@@ -1 +1,7 @@
1
- __device__ /*{return_type}*/ /*{name}*/(/*{parameters}*/)
1
+
2
+ // TODO: There should be a better to check if /*{name}*/ is already defined
3
+ #ifndef /*{name}*/_func
4
+ #define /*{name}*/_func
5
+ __device__ /*{result_type}*/ /*{name}*/(/*{parameters}*/)
6
+ /*{body}*/
7
+ #endif
@@ -0,0 +1,47 @@
1
+ #undef checkErrorReturn
2
+ #define checkErrorReturn(result_var, expr) \
3
+ if (result_var->last_error = expr) \
4
+ {\
5
+ cudaError_t error = cudaGetLastError();\
6
+ printf("!!! Cuda Failure %s:%d (%i): '%s'\n", __FILE__, __LINE__, expr, cudaGetErrorString(error));\
7
+ cudaDeviceReset();\
8
+ return result_var;\
9
+ }
10
+
11
+ extern "C" EXPORT result_t *launch_kernel(environment_t */*{host_env_var_name}*/)
12
+ {
13
+ // CUDA Initialization
14
+ program_result = new result_t();
15
+ program_result->device_allocations = new vector<void*>();
16
+
17
+ timeStartMeasure();
18
+
19
+ cudaError_t cudaStatus = cudaSetDevice(0);
20
+
21
+ if (cudaStatus != cudaSuccess) {
22
+ fprintf(stderr, "cudaSetDevice failed! Do you have a CUDA-capable GPU installed?\n");
23
+ program_result->last_error = -1;
24
+ return program_result;
25
+ }
26
+
27
+ checkErrorReturn(program_result, cudaFree(0));
28
+
29
+ timeReportMeasure(program_result, setup_cuda);
30
+
31
+
32
+ /* Prepare environment */
33
+ /*{prepare_environment}*/
34
+
35
+ /* Launch all kernels */
36
+ /*{launch_all_kernels}*/
37
+
38
+ /* Copy over result to the host */
39
+ program_result->result = /*{host_result_array}*/;
40
+
41
+ /* Free device memory */
42
+ /*{free_device_memory}*/
43
+
44
+ delete program_result->device_allocations;
45
+
46
+ return program_result;
47
+ }
@@ -1,4 +1,10 @@
1
1
 
2
2
  void * temp_ptr_/*{field}*/ = /*{host_env}*/->/*{field}*/;
3
- checkCudaErrors(cudaMalloc((void **) &/*{host_env}*/->/*{field}*/, /*{size_bytes}*/));
4
- checkCudaErrors(cudaMemcpy(/*{host_env}*/->/*{field}*/, temp_ptr_/*{field}*/, /*{size_bytes}*/, cudaMemcpyHostToDevice));
3
+
4
+ timeStartMeasure();
5
+ checkErrorReturn(program_result, cudaMalloc((void **) &/*{host_env}*/->/*{field}*/, /*{size_bytes}*/));
6
+ timeReportMeasure(program_result, allocate_memory);
7
+
8
+ timeStartMeasure();
9
+ checkErrorReturn(program_result, cudaMemcpy(/*{host_env}*/->/*{field}*/, temp_ptr_/*{field}*/, /*{size_bytes}*/, cudaMemcpyHostToDevice));
10
+ timeReportMeasure(program_result, transfer_memory);
@@ -0,0 +1,3 @@
1
+ timeStartMeasure();
2
+ checkErrorReturn(program_result, cudaFree(/*{name}*/));
3
+ timeReportMeasure(program_result, free_memory);
@@ -0,0 +1,24 @@
1
+ ({
2
+ /*{type}*/ cmd_to_free = /*{receiver}*/;
3
+
4
+ timeStartMeasure();
5
+ bool freed_memory = false;
6
+
7
+ if (cmd_to_free->result != 0) {
8
+ checkErrorReturn(program_result, cudaFree(cmd_to_free->result));;
9
+
10
+ // Remove from list of allocations
11
+ program_result->device_allocations->erase(
12
+ std::remove(
13
+ program_result->device_allocations->begin(),
14
+ program_result->device_allocations->end(),
15
+ cmd_to_free->result),
16
+ program_result->device_allocations->end());
17
+
18
+ freed_memory = true;
19
+ }
20
+
21
+ timeReportMeasure(program_result, free_memory);
22
+
23
+ freed_memory;
24
+ })
@@ -1,4 +1,8 @@
1
1
  #include <stdio.h>
2
+ #include <assert.h>
3
+ #include <chrono>
4
+ #include <vector>
5
+ #include <algorithm>
2
6
 
3
7
  #include <helper_cuda.h>
4
8
  #include <helper_cuda_gl.h>
@@ -30,17 +34,27 @@ typedef int obj_id_t;
30
34
  typedef int class_id_t;
31
35
  /* ----- END Class Type ----- */
32
36
 
33
- /* ----- BEGIN Union Type ----- */
34
- typedef struct union_type_struct
35
- {
36
- class_id_t class_id;
37
- obj_id_t object_id;
38
- } union_t;
39
- /* ----- END Union Type ----- */
40
-
41
-
42
37
  /* ----- BEGIN Environment (lexical variables) ----- */
43
38
  // environment_struct must be defined later
44
39
  typedef struct environment_struct environment_t;
45
40
  /* ----- END Environment (lexical variables) ----- */
46
41
 
42
+
43
+ /* ----- BEGIN Forward declarations ----- */
44
+ typedef struct result_t result_t;
45
+ /* ----- END Forward declarations ----- */
46
+
47
+ // Define program result variable. Also contains benchmark numbers.
48
+ result_t *program_result;
49
+
50
+ // Variables for measuring time
51
+ chrono::high_resolution_clock::time_point start_time;
52
+ chrono::high_resolution_clock::time_point end_time;
53
+
54
+ /* ----- BEGIN Macros ----- */
55
+ #define timeStartMeasure() start_time = chrono::high_resolution_clock::now();
56
+
57
+ #define timeReportMeasure(result_var, variable_name) \
58
+ end_time = chrono::high_resolution_clock::now(); \
59
+ result_var->time_##variable_name = result_var->time_##variable_name + chrono::duration_cast<chrono::microseconds>(end_time - start_time).count();
60
+ /* ----- END Macros ----- */
@@ -0,0 +1,92 @@
1
+ /* ----- BEGIN Structs ----- */
2
+ struct variable_size_array_t {
3
+ void *content;
4
+ int size;
5
+
6
+ variable_size_array_t(void *content_ = NULL, int size_ = 0) : content(content_), size(size_) { };
7
+
8
+ static const variable_size_array_t error_return_value;
9
+ };
10
+
11
+ // error_return_value is used in case a host section terminates abnormally
12
+ const variable_size_array_t variable_size_array_t::error_return_value =
13
+ variable_size_array_t(NULL, 0);
14
+
15
+ /* ----- BEGIN Union Type ----- */
16
+ typedef union union_type_value {
17
+ obj_id_t object_id;
18
+ int int_;
19
+ float float_;
20
+ bool bool_;
21
+ void *pointer;
22
+ variable_size_array_t variable_size_array;
23
+
24
+ __host__ __device__ union_type_value(int value) : int_(value) { };
25
+ __host__ __device__ union_type_value(float value) : float_(value) { };
26
+ __host__ __device__ union_type_value(bool value) : bool_(value) { };
27
+ __host__ __device__ union_type_value(void *value) : pointer(value) { };
28
+ __host__ __device__ union_type_value(variable_size_array_t value) : variable_size_array(value) { };
29
+
30
+ __host__ __device__ static union_type_value from_object_id(obj_id_t value)
31
+ {
32
+ return union_type_value(value);
33
+ }
34
+
35
+ __host__ __device__ static union_type_value from_int(int value)
36
+ {
37
+ return union_type_value(value);
38
+ }
39
+
40
+ __host__ __device__ static union_type_value from_float(float value)
41
+ {
42
+ return union_type_value(value);
43
+ }
44
+
45
+ __host__ __device__ static union_type_value from_bool(bool value)
46
+ {
47
+ return union_type_value(value);
48
+ }
49
+
50
+ __host__ __device__ static union_type_value from_pointer(void *value)
51
+ {
52
+ return union_type_value(value);
53
+ }
54
+
55
+ __host__ __device__ static union_type_value from_variable_size_array_t(variable_size_array_t value)
56
+ {
57
+ return union_type_value(value);
58
+ }
59
+ } union_v_t;
60
+
61
+ typedef struct union_type_struct
62
+ {
63
+ class_id_t class_id;
64
+ union_v_t value;
65
+
66
+ __host__ __device__ union_type_struct(
67
+ class_id_t class_id_ = 0, union_v_t value_ = union_v_t(0))
68
+ : class_id(class_id_), value(value_) { };
69
+
70
+ static const union_type_struct error_return_value;
71
+ } union_t;
72
+
73
+ // error_return_value is used in case a host section terminates abnormally
74
+ const union_type_struct union_t::error_return_value = union_type_struct(0, union_v_t(0));
75
+ /* ----- END Union Type ----- */
76
+
77
+ typedef struct result_t {
78
+ /*{result_type}*/ result;
79
+ int last_error;
80
+
81
+ uint64_t time_setup_cuda;
82
+ uint64_t time_prepare_env;
83
+ uint64_t time_kernel;
84
+ uint64_t time_free_memory;
85
+ uint64_t time_transfer_memory;
86
+ uint64_t time_allocate_memory;
87
+
88
+ // Memory management
89
+ vector<void*> *device_allocations;
90
+ } result_t;
91
+ /* ----- END Structs ----- */
92
+