torch-rb 0.22.0 → 0.22.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6d84711879346fb2ee772ba127520ab533b5171a05a0609aa5ed96ca244db4d
4
- data.tar.gz: 0ad9c5a15d4e645240061fa19f3d56eb40770dfdc3594a1306ffde0c17792d5a
3
+ metadata.gz: 13a292607c0a4ecc21607db5128d779a2dbd349f9372fe7e140576af4b6e9e95
4
+ data.tar.gz: 5ce06edf45ef0c4e05d3e77b7517c3c15c3400c36d2b264afd6252bbd6de2ab1
5
5
  SHA512:
6
- metadata.gz: be84a03edc6bc7c62ac42ada37e104ed4df05f9fb7588730f2b8e5e9f6b2137dd7793b6bb71c85cd46b4ef8020c95fc9fef07aa2d4de86999c7ef683e955ad86
7
- data.tar.gz: 669b7cc9d525c3a305d6c1eead7a65d0290da32c40049653d5f4a0c4fcc5d9650234b1f3c6027e91465d950944a746e738daea9ec775b02fdaffe33978feb650
6
+ metadata.gz: 24e8f8557835301ed533bcd52eaf22a5bad643d267f2cdc8d9f49c8b6306d844d4a12411e1f32bf0512d54b8f3637aed507fa22d0b8d3c6db3633f5a24a23470
7
+ data.tar.gz: 39f7d61b3f39dde83ff24eeef19996f907e3943017d2af7c16c1f18b22c1538f208be78e990177e70f33a7dffa40d87bdce0e740307fac2f7c8c8bf3e0ffea5e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.22.2 (2025-11-04)
2
+
3
+ - Added support for CUDA 12.9+
4
+
5
+ ## 0.22.1 (2025-10-26)
6
+
7
+ - Fixed error with Rice 4.7
8
+
1
9
  ## 0.22.0 (2025-10-15)
2
10
 
3
11
  - Updated LibTorch to 2.9.0
data/ext/torch/extconf.rb CHANGED
@@ -33,9 +33,11 @@ unless inc && lib
33
33
  end
34
34
 
35
35
  cuda_inc, cuda_lib = dir_config("cuda")
36
- cuda_inc ||= "/usr/local/cuda/include"
37
36
  cuda_lib ||= "/usr/local/cuda/lib64"
38
37
 
38
+ cudnn_inc, cudnn_lib = dir_config("cudnn")
39
+ cudnn_lib ||= "/usr/local/cuda/lib"
40
+
39
41
  $LDFLAGS += " -L#{lib}" if Dir.exist?(lib)
40
42
  abort "LibTorch not found" unless have_library("torch")
41
43
 
@@ -45,6 +47,7 @@ have_library("nnpack")
45
47
  with_cuda = false
46
48
  if Dir["#{lib}/*torch_cuda*"].any?
47
49
  $LDFLAGS += " -L#{cuda_lib}" if Dir.exist?(cuda_lib)
50
+ $LDFLAGS += " -L#{cudnn_lib}" if Dir.exist?(cudnn_lib) && cudnn_lib != cuda_lib
48
51
  with_cuda = have_library("cuda") && have_library("cudnn")
49
52
  end
50
53
 
@@ -57,10 +60,12 @@ if RbConfig::CONFIG["host_os"] =~ /darwin/i && RbConfig::CONFIG["host_cpu"] =~ /
57
60
  end
58
61
  $LDFLAGS += ":#{cuda_lib}/stubs:#{cuda_lib}" if with_cuda
59
62
 
60
- # https://github.com/pytorch/pytorch/blob/v1.5.0/torch/utils/cpp_extension.py#L1232-L1238
63
+ # https://github.com/pytorch/pytorch/blob/v2.9.0/torch/utils/cpp_extension.py#L1351-L1364
61
64
  $LDFLAGS += " -lc10 -ltorch_cpu -ltorch"
62
65
  if with_cuda
63
- $LDFLAGS += " -lcuda -lnvrtc -lnvToolsExt -lcudart -lc10_cuda -ltorch_cuda -lcufft -lcurand -lcublas -lcudnn"
66
+ $LDFLAGS += " -lcuda -lnvrtc"
67
+ $LDFLAGS += " -lnvToolsExt" if File.exist?("#{cuda_lib}/libnvToolsExt.so")
68
+ $LDFLAGS += " -lcudart -lc10_cuda -ltorch_cuda -lcufft -lcurand -lcublas -lcudnn"
64
69
  # TODO figure out why this is needed
65
70
  $LDFLAGS += " -Wl,--no-as-needed,#{lib}/libtorch.so"
66
71
  end
data/ext/torch/ivalue.cpp CHANGED
@@ -55,7 +55,7 @@ void init_ivalue(Rice::Module& m, Rice::Class& rb_cIValue) {
55
55
  Rice::Array obj;
56
56
  for (auto& elem : list) {
57
57
  auto v = torch::IValue{elem};
58
- obj.push(Rice::Object(Rice::detail::To_Ruby<torch::IValue>().convert(v)));
58
+ obj.push(Rice::Object(Rice::detail::To_Ruby<torch::IValue>().convert(v)), false);
59
59
  }
60
60
  return obj;
61
61
  })
@@ -50,14 +50,25 @@ namespace Rice::detail {
50
50
  template<typename T>
51
51
  class To_Ruby<c10::complex<T>> {
52
52
  public:
53
+ To_Ruby() = default;
54
+
55
+ explicit To_Ruby(Arg* arg) : arg_(arg) { }
56
+
53
57
  VALUE convert(c10::complex<T> const& x) {
54
58
  return rb_dbl_complex_new(x.real(), x.imag());
55
59
  }
60
+
61
+ private:
62
+ Arg* arg_ = nullptr;
56
63
  };
57
64
 
58
65
  template<typename T>
59
66
  class From_Ruby<c10::complex<T>> {
60
67
  public:
68
+ From_Ruby() = default;
69
+
70
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
71
+
61
72
  Convertible is_convertible(VALUE value) { return Convertible::Cast; }
62
73
 
63
74
  c10::complex<T> convert(VALUE x) {
@@ -65,6 +76,9 @@ namespace Rice::detail {
65
76
  VALUE imag = rb_funcall(x, rb_intern("imag"), 0);
66
77
  return c10::complex<T>(From_Ruby<T>().convert(real), From_Ruby<T>().convert(imag));
67
78
  }
79
+
80
+ private:
81
+ Arg* arg_ = nullptr;
68
82
  };
69
83
 
70
84
  template<>
@@ -75,6 +89,10 @@ namespace Rice::detail {
75
89
  template<>
76
90
  class From_Ruby<FanModeType> {
77
91
  public:
92
+ From_Ruby() = default;
93
+
94
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
95
+
78
96
  Convertible is_convertible(VALUE value) { return Convertible::Cast; }
79
97
 
80
98
  FanModeType convert(VALUE x) {
@@ -87,6 +105,9 @@ namespace Rice::detail {
87
105
  throw std::runtime_error("Unsupported nonlinearity type: " + s);
88
106
  }
89
107
  }
108
+
109
+ private:
110
+ Arg* arg_ = nullptr;
90
111
  };
91
112
 
92
113
  template<>
@@ -97,6 +118,10 @@ namespace Rice::detail {
97
118
  template<>
98
119
  class From_Ruby<NonlinearityType> {
99
120
  public:
121
+ From_Ruby() = default;
122
+
123
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
124
+
100
125
  Convertible is_convertible(VALUE value) { return Convertible::Cast; }
101
126
 
102
127
  NonlinearityType convert(VALUE x) {
@@ -127,6 +152,9 @@ namespace Rice::detail {
127
152
  throw std::runtime_error("Unsupported nonlinearity type: " + s);
128
153
  }
129
154
  }
155
+
156
+ private:
157
+ Arg* arg_ = nullptr;
130
158
  };
131
159
 
132
160
  template<>
@@ -137,6 +165,10 @@ namespace Rice::detail {
137
165
  template<>
138
166
  class From_Ruby<Scalar> {
139
167
  public:
168
+ From_Ruby() = default;
169
+
170
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
171
+
140
172
  Convertible is_convertible(VALUE value) { return Convertible::Cast; }
141
173
 
142
174
  Scalar convert(VALUE x) {
@@ -146,5 +178,8 @@ namespace Rice::detail {
146
178
  return torch::Scalar(From_Ruby<double>().convert(x));
147
179
  }
148
180
  }
181
+
182
+ private:
183
+ Arg* arg_ = nullptr;
149
184
  };
150
185
  } // namespace Rice::detail
data/ext/torch/tensor.cpp CHANGED
@@ -20,7 +20,7 @@ Array flat_data(Tensor& tensor) {
20
20
 
21
21
  Array a;
22
22
  for (int i = 0; i < tensor.numel(); i++) {
23
- a.push(view[i].item().to<T>());
23
+ a.push(view[i].item().to<T>(), false);
24
24
  }
25
25
  return a;
26
26
  }
@@ -129,7 +129,7 @@ void init_tensor(Rice::Module& m, Rice::Class& c, Rice::Class& rb_cTensorOptions
129
129
  [](Tensor& self) {
130
130
  Array a;
131
131
  for (auto &size : self.sizes()) {
132
- a.push(size);
132
+ a.push(size, false);
133
133
  }
134
134
  return a;
135
135
  })
@@ -138,7 +138,7 @@ void init_tensor(Rice::Module& m, Rice::Class& c, Rice::Class& rb_cTensorOptions
138
138
  [](Tensor& self) {
139
139
  Array a;
140
140
  for (auto &stride : self.strides()) {
141
- a.push(stride);
141
+ a.push(stride, false);
142
142
  }
143
143
  return a;
144
144
  })
data/lib/torch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Torch
2
- VERSION = "0.22.0"
2
+ VERSION = "0.22.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torch-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.22.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '4.5'
18
+ version: '4.7'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '4.5'
25
+ version: '4.7'
26
26
  email: andrew@ankane.org
27
27
  executables: []
28
28
  extensions: