tensor_stream-opencl 0.3.1 → 0.4.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +35 -0
- data/CHANGELOG.md +38 -0
- data/Gemfile +16 -0
- data/README.md +28 -0
- data/benchmark/benchmark.rb +67 -46
- data/benchmark.json +704 -0
- data/bin/opencl_check.rb +32 -0
- data/lib/tensor_stream/opencl/array_ops.rb +24 -0
- data/lib/tensor_stream/opencl/images_ops.rb +52 -11
- data/lib/tensor_stream/opencl/nn_ops.rb +35 -219
- data/lib/tensor_stream/opencl/opencl_buffer.rb +12 -0
- data/lib/tensor_stream/opencl/opencl_evaluator.rb +81 -67
- data/lib/tensor_stream/opencl/opencl_template_helper.rb +2 -2
- data/lib/tensor_stream/opencl/random_ops.rb +72 -19
- data/lib/tensor_stream/opencl/version.rb +1 -1
- data/samples/mnist_data_3.0_preload.rb +173 -0
- data/tensor_stream-opencl.gemspec +5 -2
- metadata +44 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1c00d22564cef50ae50f6302975c6bd35d1e594d70f3645f2c2fa5f7bf31ad8c
|
|
4
|
+
data.tar.gz: 31bb29c838d9ee652d52b9053781110b13e4b80937d777e368df54349c1ea2a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4aca3b8e774e9ff7b8b50fb25511616069bb5357d8b0c9dab1af2b8681a5aabd6b580e57912750c2fa6326a29dd9b4ef10ade9685d897e1c004f54a5022c0bcd
|
|
7
|
+
data.tar.gz: d5f689330ef270475a5ea907cded4d1c9c1abdc160e1f565974a9e4b5dfd39bf0b3d5c42444252f0c1efc73d3a6001c8b8be0282aa065412feeb20082d4404eb
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
ruby: ["3.1", "3.3", "3.4"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- name: Clone core next to this repo (shared spec support + path gem)
|
|
18
|
+
run: git clone --depth 1 https://github.com/jedld/tensor_stream.git ../tensor_stream
|
|
19
|
+
- name: Install system dependencies (POCL OpenCL ICD + jpeg gem headers)
|
|
20
|
+
run: sudo apt-get update -q && sudo apt-get install -yq --no-install-recommends pocl-opencl-icd ocl-icd-libopencl1 libjpeg-dev
|
|
21
|
+
- name: Verify OpenCL device is visible
|
|
22
|
+
run: ls /etc/OpenCL/vendors && cat /etc/OpenCL/vendors/*.icd && ldconfig -p | grep -i libopencl
|
|
23
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
|
24
|
+
uses: ruby/setup-ruby@v1
|
|
25
|
+
with:
|
|
26
|
+
ruby-version: ${{ matrix.ruby }}
|
|
27
|
+
- name: Install gems
|
|
28
|
+
run: |
|
|
29
|
+
# numo-narray and narray need a legacy C dialect on GCC 14+
|
|
30
|
+
# runners (C23 removed K&R-style empty parameter lists)
|
|
31
|
+
bundle config set --local build.numo-narray "--with-cflags=-std=gnu17"
|
|
32
|
+
bundle config set --local build.narray "--with-cflags=-std=gnu17"
|
|
33
|
+
bundle install --jobs 4 --retry 3
|
|
34
|
+
- name: Run specs (OpenCL evaluator on POCL CPU device)
|
|
35
|
+
run: bundle exec rspec
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.4.0] - 2026-12-06
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Kernel template compilation on Ruby 3+: the removed positional
|
|
7
|
+
`ERB.new(src, nil, '%')` form now uses `trim_mode:`; previously every
|
|
8
|
+
kernel compile raised.
|
|
9
|
+
- Heap corruption in the softmax family (`softmax`, `log_softmax`,
|
|
10
|
+
`softmax_cross_entropy_with_logits(_v2)`, `sparse_*`, `*_grad`):
|
|
11
|
+
rank-1 logits were misread as `shape[0]` rows of that same width, so
|
|
12
|
+
kernels wrote `n^2` elements into `n`-element buffers.
|
|
13
|
+
- `unstack`/`split`: sub-buffer regions that violate
|
|
14
|
+
`CL_DEVICE_MEM_BASE_ADDR_ALIGN` (e.g. small slices) now fall back to
|
|
15
|
+
discrete device buffers with a rect copy instead of failing with
|
|
16
|
+
`CL_MISALIGNED_SUB_BUFFER_OFFSET` on strict ICDs (POCL).
|
|
17
|
+
- Inputs arriving from the ruby evaluator's numo-narray fast path are
|
|
18
|
+
converted to ruby arrays before being packed into GPU buffers.
|
|
19
|
+
- Implemented the evaluator storage-manager hook required by core
|
|
20
|
+
(`get_storage_manager`).
|
|
21
|
+
- Latent NameError in the sub-buffer fallback branches.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
- Requires `tensor_stream >= 1.3`.
|
|
25
|
+
- The GPU-resident "variable container" model was removed:
|
|
26
|
+
`variable_v2`, `assign*`, `apply_*` optimizers and `save_ts/restore_ts`
|
|
27
|
+
now execute on the ruby evaluator, matching core's host-side variable
|
|
28
|
+
storage (values transition to GPU buffers per op). Device-resident
|
|
29
|
+
variable storage with on-device apply kernels is future work.
|
|
30
|
+
- `narray_ffi` is now an explicit dependency.
|
|
31
|
+
- CI runs the full shared-op suite against the POCL software OpenCL
|
|
32
|
+
ICD (Ruby 3.1/3.3/3.4), so no GPU drivers are needed to develop the
|
|
33
|
+
backend; GPU-device-specific specs self-skip when no GPU is present.
|
|
34
|
+
- Added `bin/opencl_check.rb` smoke tool; README documents the
|
|
35
|
+
compatibility and development setup.
|
|
36
|
+
|
|
37
|
+
## [0.3.2] and earlier
|
|
38
|
+
- See git history.
|
data/Gemfile
CHANGED
|
@@ -4,3 +4,19 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
|
4
4
|
|
|
5
5
|
# Specify your gem's dependencies in tensor_stream-opencl.gemspec
|
|
6
6
|
gemspec
|
|
7
|
+
|
|
8
|
+
gem "benchmark"
|
|
9
|
+
gem "drb"
|
|
10
|
+
gem "mutex_m"
|
|
11
|
+
gem "bigdecimal"
|
|
12
|
+
|
|
13
|
+
# develop against the local core checkout when present (monorepo style
|
|
14
|
+
# sibling checkout); CI tracks core master until 1.3+ is pushed to
|
|
15
|
+
# rubygems, after which the released gem dependency also resolves
|
|
16
|
+
if Dir.exist?(File.expand_path("../tensor_stream", __dir__))
|
|
17
|
+
gem "tensor_stream", path: "../tensor_stream"
|
|
18
|
+
else
|
|
19
|
+
gem "tensor_stream", github: "jedld/tensor_stream"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
gem "numo-narray"
|
data/README.md
CHANGED
|
@@ -81,10 +81,38 @@ ts.device('/device:GPU:1') do
|
|
|
81
81
|
end
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
## Compatibility and architecture notes
|
|
85
|
+
|
|
86
|
+
- Requires tensor_stream >= 1.3 (works with the numo-narray fast path: values
|
|
87
|
+
coming from the ruby evaluator are converted to OpenCL buffers at
|
|
88
|
+
evaluator transitions).
|
|
89
|
+
- Tested on Ruby 3.1–3.4. CI runs the full shared op suite against a POCL
|
|
90
|
+
(software) OpenCL device, so no GPU is needed to develop or verify the
|
|
91
|
+
backend. Ruby 4.x is not supported yet: the opencl_ruby_ffi/narray_ffi
|
|
92
|
+
native extensions corrupt memory there (crashes surface mid-suite).
|
|
93
|
+
- Variable storage is host side (the ruby evaluator owns `variable_v2` /
|
|
94
|
+
`assign` / `apply_*` optimizer ops); values cross to GPU buffers per op.
|
|
95
|
+
GPU-resident variable storage with on-device apply kernels is planned.
|
|
96
|
+
- Eager execution (`tf.enable_eager_execution`) always evaluates on the
|
|
97
|
+
ruby evaluator; the OpenCL evaluator is for session/graph execution.
|
|
98
|
+
|
|
84
99
|
## Development
|
|
85
100
|
|
|
86
101
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
87
102
|
|
|
103
|
+
The specs need an OpenCL device. Without GPU drivers, install the POCL
|
|
104
|
+
software ICD (`sudo apt-get install pocl-opencl-icd` on Debian/Ubuntu);
|
|
105
|
+
CI uses exactly this. If your system loader doesn't pick it up
|
|
106
|
+
automatically, point `opencl_ruby_ffi` at it:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
export OCL_ICD_VENDORS=/path/to/vendors.d # directory containing pocl.icd
|
|
110
|
+
export LD_LIBRARY_PATH=/path/to/lib # contains libpocl.so
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Run `bundle exec ruby bin/opencl_check.rb` for a quick device + evaluator
|
|
114
|
+
smoke test before running the full suite.
|
|
115
|
+
|
|
88
116
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
89
117
|
|
|
90
118
|
## Contributing
|
data/benchmark/benchmark.rb
CHANGED
|
@@ -102,50 +102,71 @@ puts TensorStream::Evaluator.default_evaluators
|
|
|
102
102
|
|
|
103
103
|
sess2 = tf.session
|
|
104
104
|
|
|
105
|
-
if os == :macosx
|
|
106
|
-
|
|
107
|
-
else
|
|
108
|
-
|
|
109
|
-
end
|
|
105
|
+
cpu = if os == :macosx
|
|
106
|
+
`sysctl -n machdep.cpu.brand_string`
|
|
107
|
+
else
|
|
108
|
+
`cat /proc/cpuinfo | grep "model name" | head -1`
|
|
109
|
+
end
|
|
110
|
+
|
|
110
111
|
device = TensorStream::Evaluator::OpenclEvaluator.default_device.native_device
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
112
|
+
cl_device = "#{device.platform.to_s} #{device.name}"
|
|
113
|
+
|
|
114
|
+
tests = {
|
|
115
|
+
"argmin" => argmin,
|
|
116
|
+
"bias_add_grad" => bias_add_grad,
|
|
117
|
+
"bias_add" => bias_add,
|
|
118
|
+
"conv2d_backprop" => conv2d_grad,
|
|
119
|
+
"conv2d" => conv2d,
|
|
120
|
+
"index" =>index,
|
|
121
|
+
"min" => min,
|
|
122
|
+
"sum" => sum,
|
|
123
|
+
"sum axis 1" => sum_axis_1,
|
|
124
|
+
"split" => split,
|
|
125
|
+
"add_n" => add_n,
|
|
126
|
+
"out of order matmul" => out_of_order,
|
|
127
|
+
"softmax" => softmax,
|
|
128
|
+
"matmul" => matmul,
|
|
129
|
+
"test model" => ->(sess) { sess.run(model, feed_dict: { p => rand, q => rand }) },
|
|
130
|
+
"single function test" => ->(sess) { sess.run(single_function_test, feed_dict: { p => rand, q => rand }) },
|
|
131
|
+
"pow (float)" => ->(sess) { sess.run(pow_f, feed_dict: { p => rand, q => rand }) },
|
|
132
|
+
"pow (int)" => ->(sess) { sess.run(pow_i, feed_dict: { p => rand, q => rand }) },
|
|
133
|
+
"dropout" => dropout
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
stats = {
|
|
137
|
+
"ruby" => {},
|
|
138
|
+
"opencl" => {},
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
puts "rehersal"
|
|
142
|
+
tests.each do |k, v|
|
|
143
|
+
if v.is_a?(Proc)
|
|
144
|
+
r = Benchmark.measure("ruby #{k}") { 10.times do v.call(sess) end }
|
|
145
|
+
r = Benchmark.measure("opencl #{k}") { 10.times do v.call(sess2) end }
|
|
146
|
+
else
|
|
147
|
+
r = Benchmark.measure("ruby #{k}") { 10.times do sess.run(v) end }
|
|
148
|
+
r = Benchmark.measure("opencl #{k}") { 10.times do sess2.run(v) end }
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
puts "writing benchmark"
|
|
153
|
+
|
|
154
|
+
tests.each do |k, v|
|
|
155
|
+
if v.is_a?(Proc)
|
|
156
|
+
r = Benchmark.measure(k) { 100.times do v.call(sess) end }
|
|
157
|
+
stats["ruby"][r.label] = { real: r.real, stime: r.stime, total: r.total, utime: r.utime }
|
|
158
|
+
r = Benchmark.measure(k) { 100.times do v.call(sess2) end }
|
|
159
|
+
stats["opencl"][r.label] = { real: r.real, stime: r.stime, total: r.total, utime: r.utime }
|
|
160
|
+
else
|
|
161
|
+
r = Benchmark.measure(k) { 100.times do sess.run(v) end }
|
|
162
|
+
stats["ruby"][r.label] = { real: r.real, stime: r.stime, total: r.total, utime: r.utime }
|
|
163
|
+
r = Benchmark.measure(k) { 100.times do sess2.run(v) end }
|
|
164
|
+
stats["opencl"][r.label] = { real: r.real, stime: r.stime, total: r.total, utime: r.utime }
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
output = {
|
|
169
|
+
"#{RUBY_ENGINE }-#{RUBY_VERSION}/#{os}/#{cpu.strip.gsub("model name\t: ", "")}/#{cl_device.strip}" => stats
|
|
170
|
+
}
|
|
171
|
+
current_benchmark = JSON.parse(File.read('benchmark.json'))
|
|
172
|
+
File.write("benchmark_#{Time.now.strftime('%Y%m%d%H%M')}.json", JSON.pretty_generate(current_benchmark.merge(output)))
|