tensor_stream-opencl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +51 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +58 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/tensor_stream/opencl.rb +7 -0
  14. data/lib/tensor_stream/opencl/kernels/_bool_operand.cl +45 -0
  15. data/lib/tensor_stream/opencl/kernels/_operand.cl +45 -0
  16. data/lib/tensor_stream/opencl/kernels/abs.cl +20 -0
  17. data/lib/tensor_stream/opencl/kernels/acos.cl +8 -0
  18. data/lib/tensor_stream/opencl/kernels/add.cl +3 -0
  19. data/lib/tensor_stream/opencl/kernels/apply_adam.cl +23 -0
  20. data/lib/tensor_stream/opencl/kernels/apply_gradient.cl +9 -0
  21. data/lib/tensor_stream/opencl/kernels/apply_momentum.cl +16 -0
  22. data/lib/tensor_stream/opencl/kernels/argmax.cl +8 -0
  23. data/lib/tensor_stream/opencl/kernels/argmin.cl +8 -0
  24. data/lib/tensor_stream/opencl/kernels/asin.cl +9 -0
  25. data/lib/tensor_stream/opencl/kernels/cast.cl +10 -0
  26. data/lib/tensor_stream/opencl/kernels/ceil.cl +8 -0
  27. data/lib/tensor_stream/opencl/kernels/cond.cl.erb +6 -0
  28. data/lib/tensor_stream/opencl/kernels/cos.cl +8 -0
  29. data/lib/tensor_stream/opencl/kernels/div.cl.erb +3 -0
  30. data/lib/tensor_stream/opencl/kernels/exp.cl +8 -0
  31. data/lib/tensor_stream/opencl/kernels/floor.cl +8 -0
  32. data/lib/tensor_stream/opencl/kernels/floor_div.cl +48 -0
  33. data/lib/tensor_stream/opencl/kernels/floor_mod.cl +3 -0
  34. data/lib/tensor_stream/opencl/kernels/gemm.cl +32 -0
  35. data/lib/tensor_stream/opencl/kernels/log.cl +8 -0
  36. data/lib/tensor_stream/opencl/kernels/log1p.cl +8 -0
  37. data/lib/tensor_stream/opencl/kernels/log_softmax.cl +26 -0
  38. data/lib/tensor_stream/opencl/kernels/max.cl +46 -0
  39. data/lib/tensor_stream/opencl/kernels/min.cl +46 -0
  40. data/lib/tensor_stream/opencl/kernels/mod.cl +3 -0
  41. data/lib/tensor_stream/opencl/kernels/mul.cl +3 -0
  42. data/lib/tensor_stream/opencl/kernels/negate.cl +8 -0
  43. data/lib/tensor_stream/opencl/kernels/pack.cl +24 -0
  44. data/lib/tensor_stream/opencl/kernels/pow.cl +46 -0
  45. data/lib/tensor_stream/opencl/kernels/real_div.cl +3 -0
  46. data/lib/tensor_stream/opencl/kernels/reciprocal.cl +8 -0
  47. data/lib/tensor_stream/opencl/kernels/round.cl +8 -0
  48. data/lib/tensor_stream/opencl/kernels/sigmoid.cl +9 -0
  49. data/lib/tensor_stream/opencl/kernels/sigmoid_grad.cl +55 -0
  50. data/lib/tensor_stream/opencl/kernels/sign.cl +21 -0
  51. data/lib/tensor_stream/opencl/kernels/sin.cl +9 -0
  52. data/lib/tensor_stream/opencl/kernels/softmax.cl +26 -0
  53. data/lib/tensor_stream/opencl/kernels/softmax_cross.cl +32 -0
  54. data/lib/tensor_stream/opencl/kernels/softmax_cross_grad.cl +28 -0
  55. data/lib/tensor_stream/opencl/kernels/softmax_grad.cl +46 -0
  56. data/lib/tensor_stream/opencl/kernels/sqrt.cl +9 -0
  57. data/lib/tensor_stream/opencl/kernels/square.cl +9 -0
  58. data/lib/tensor_stream/opencl/kernels/squared_difference.cl +53 -0
  59. data/lib/tensor_stream/opencl/kernels/sub.cl +3 -0
  60. data/lib/tensor_stream/opencl/kernels/tan.cl +8 -0
  61. data/lib/tensor_stream/opencl/kernels/tanh.cl +8 -0
  62. data/lib/tensor_stream/opencl/kernels/tanh_grad.cl +7 -0
  63. data/lib/tensor_stream/opencl/kernels/where.cl +8 -0
  64. data/lib/tensor_stream/opencl/math_ops.rb +133 -0
  65. data/lib/tensor_stream/opencl/nn_ops.rb +191 -0
  66. data/lib/tensor_stream/opencl/opencl_buffer.rb +35 -0
  67. data/lib/tensor_stream/opencl/opencl_device.rb +5 -0
  68. data/lib/tensor_stream/opencl/opencl_evaluator.rb +933 -0
  69. data/lib/tensor_stream/opencl/opencl_template_helper.rb +99 -0
  70. data/lib/tensor_stream/opencl/version.rb +5 -0
  71. data/tensor_stream-opencl.gemspec +40 -0
  72. metadata +185 -0
@@ -0,0 +1,99 @@
1
+ require 'erb'
2
+ class OpenclTemplateHelper
3
+ def initialize(source)
4
+ @source = source
5
+ end
6
+
7
+ def generate(args = {})
8
+ current_scope = binding
9
+
10
+ args.each do |k, v|
11
+ current_scope.local_variable_set(k.to_sym, v)
12
+ end
13
+
14
+ ERB.new(@source, nil, '%').result(current_scope)
15
+ end
16
+
17
+ def floating_point?(dtype)
18
+ TensorStream::Ops::FLOATING_POINT_TYPES.include?(dtype)
19
+ end
20
+
21
+ def render(template, locals = {})
22
+ filename = File.join(File.dirname(__FILE__), 'kernels', "_#{template}")
23
+ source = File.read(filename)
24
+ current_scope = binding
25
+ locals.each do |k, v|
26
+ current_scope.local_variable_set(k.to_sym, v)
27
+ end
28
+ ERB.new(source, nil, '%').result(current_scope)
29
+ end
30
+
31
+ def dtype_to_c_type(dtype)
32
+ case dtype.to_s
33
+ when 'float64'
34
+ 'double'
35
+ when 'float32', 'float'
36
+ 'float'
37
+ when 'int32', 'int'
38
+ 'int'
39
+ when 'int16'
40
+ 'short'
41
+ when 'uint8'
42
+ 'uchar'
43
+ when 'boolean'
44
+ 'uchar'
45
+ else
46
+ raise "unknown dtype #{dtype}"
47
+ end
48
+ end
49
+
50
+ def min_value_for(dtype)
51
+ case dtype.to_s
52
+ when 'float64'
53
+ 'DBL_MIN'
54
+ when 'float32', 'float'
55
+ 'FLT_MIN'
56
+ when 'int32', 'int'
57
+ 'INT_MIN'
58
+ when 'int16'
59
+ 'SHRT_MIN'
60
+ when 'int8'
61
+ '0'
62
+ when 'boolean'
63
+ '0'
64
+ else
65
+ raise "unknown dtype #{dtype}"
66
+ end
67
+ end
68
+
69
+ def operator_to_c(op)
70
+ case op
71
+ when 'less'
72
+ '<'
73
+ when 'less_equal'
74
+ '<='
75
+ when 'equal'
76
+ '=='
77
+ when 'greater'
78
+ '>'
79
+ when 'greater_equal'
80
+ '>='
81
+ when 'not_equal'
82
+ '!='
83
+ when 'logical_and'
84
+ '&&'
85
+ when 'div'
86
+ '/'
87
+ when 'add'
88
+ '+'
89
+ when 'sub'
90
+ '-'
91
+ when 'mul'
92
+ '*'
93
+ when 'mod'
94
+ '%'
95
+ else
96
+ raise "unsupported op #{op}"
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ module TensorStream
2
+ module Opencl
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tensor_stream/opencl/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tensor_stream-opencl"
8
+ spec.version = TensorStream::Opencl::VERSION
9
+ spec.authors = ["Joseph Dayo"]
10
+ spec.email = ["joseph.dayo@gmail.com"]
11
+
12
+ spec.summary = %q{OpenCL evaluator for tensor_stream}
13
+ spec.description = %q{OpenCL evaluator for tensor_stream}
14
+ spec.homepage = "https://github.com/jedld/tensor_stream-opencl"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_dependency "tensor_stream"
39
+ spec.add_dependency "opencl_ruby_ffi"
40
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tensor_stream-opencl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Dayo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tensor_stream
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: opencl_ruby_ffi
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: OpenCL evaluator for tensor_stream
84
+ email:
85
+ - joseph.dayo@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/tensor_stream/opencl.rb
102
+ - lib/tensor_stream/opencl/kernels/_bool_operand.cl
103
+ - lib/tensor_stream/opencl/kernels/_operand.cl
104
+ - lib/tensor_stream/opencl/kernels/abs.cl
105
+ - lib/tensor_stream/opencl/kernels/acos.cl
106
+ - lib/tensor_stream/opencl/kernels/add.cl
107
+ - lib/tensor_stream/opencl/kernels/apply_adam.cl
108
+ - lib/tensor_stream/opencl/kernels/apply_gradient.cl
109
+ - lib/tensor_stream/opencl/kernels/apply_momentum.cl
110
+ - lib/tensor_stream/opencl/kernels/argmax.cl
111
+ - lib/tensor_stream/opencl/kernels/argmin.cl
112
+ - lib/tensor_stream/opencl/kernels/asin.cl
113
+ - lib/tensor_stream/opencl/kernels/cast.cl
114
+ - lib/tensor_stream/opencl/kernels/ceil.cl
115
+ - lib/tensor_stream/opencl/kernels/cond.cl.erb
116
+ - lib/tensor_stream/opencl/kernels/cos.cl
117
+ - lib/tensor_stream/opencl/kernels/div.cl.erb
118
+ - lib/tensor_stream/opencl/kernels/exp.cl
119
+ - lib/tensor_stream/opencl/kernels/floor.cl
120
+ - lib/tensor_stream/opencl/kernels/floor_div.cl
121
+ - lib/tensor_stream/opencl/kernels/floor_mod.cl
122
+ - lib/tensor_stream/opencl/kernels/gemm.cl
123
+ - lib/tensor_stream/opencl/kernels/log.cl
124
+ - lib/tensor_stream/opencl/kernels/log1p.cl
125
+ - lib/tensor_stream/opencl/kernels/log_softmax.cl
126
+ - lib/tensor_stream/opencl/kernels/max.cl
127
+ - lib/tensor_stream/opencl/kernels/min.cl
128
+ - lib/tensor_stream/opencl/kernels/mod.cl
129
+ - lib/tensor_stream/opencl/kernels/mul.cl
130
+ - lib/tensor_stream/opencl/kernels/negate.cl
131
+ - lib/tensor_stream/opencl/kernels/pack.cl
132
+ - lib/tensor_stream/opencl/kernels/pow.cl
133
+ - lib/tensor_stream/opencl/kernels/real_div.cl
134
+ - lib/tensor_stream/opencl/kernels/reciprocal.cl
135
+ - lib/tensor_stream/opencl/kernels/round.cl
136
+ - lib/tensor_stream/opencl/kernels/sigmoid.cl
137
+ - lib/tensor_stream/opencl/kernels/sigmoid_grad.cl
138
+ - lib/tensor_stream/opencl/kernels/sign.cl
139
+ - lib/tensor_stream/opencl/kernels/sin.cl
140
+ - lib/tensor_stream/opencl/kernels/softmax.cl
141
+ - lib/tensor_stream/opencl/kernels/softmax_cross.cl
142
+ - lib/tensor_stream/opencl/kernels/softmax_cross_grad.cl
143
+ - lib/tensor_stream/opencl/kernels/softmax_grad.cl
144
+ - lib/tensor_stream/opencl/kernels/sqrt.cl
145
+ - lib/tensor_stream/opencl/kernels/square.cl
146
+ - lib/tensor_stream/opencl/kernels/squared_difference.cl
147
+ - lib/tensor_stream/opencl/kernels/sub.cl
148
+ - lib/tensor_stream/opencl/kernels/tan.cl
149
+ - lib/tensor_stream/opencl/kernels/tanh.cl
150
+ - lib/tensor_stream/opencl/kernels/tanh_grad.cl
151
+ - lib/tensor_stream/opencl/kernels/where.cl
152
+ - lib/tensor_stream/opencl/math_ops.rb
153
+ - lib/tensor_stream/opencl/nn_ops.rb
154
+ - lib/tensor_stream/opencl/opencl_buffer.rb
155
+ - lib/tensor_stream/opencl/opencl_device.rb
156
+ - lib/tensor_stream/opencl/opencl_evaluator.rb
157
+ - lib/tensor_stream/opencl/opencl_template_helper.rb
158
+ - lib/tensor_stream/opencl/version.rb
159
+ - tensor_stream-opencl.gemspec
160
+ homepage: https://github.com/jedld/tensor_stream-opencl
161
+ licenses:
162
+ - MIT
163
+ metadata:
164
+ allowed_push_host: https://rubygems.org
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.6.10
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: OpenCL evaluator for tensor_stream
185
+ test_files: []