carray-jit 0.1.6 → 0.1.7

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: e052fd85b01164a6147a30ca655b8997ba7c87ac9c7ec8354d73447d1208b5ca
4
- data.tar.gz: 2a6ebb524fb6afee5c871c0a45ed13ecf2f120f9ef0194e36f486ac3b015b378
3
+ metadata.gz: 27ac95a6f004e19365a64f30d0a6e87384b1e20878b9374d8faf5b2cb328070d
4
+ data.tar.gz: d9ce3b1c9e3ebe5bc6c06288c4480fc25b1d88f58be5af635653e3f72067a637
5
5
  SHA512:
6
- metadata.gz: bd5017f5251ad7b9f4263bfc25091a938d3bccd7f18ef5d83a5a68b63f57e0df6c1ee4278ccd1b903a68cb77a5a156a47c98cbc4832edabbf144593778fed1b5
7
- data.tar.gz: d8d2733f8a98376561ccb183895e1e963eff8a1caea636d066e88ce4852f167fb8755c6f1225beaf0c89aea51bf18dab4482bde0a079983ff507e9cd66769b2f
6
+ metadata.gz: 80b9d9cc62dc9d6042fc6a1aac00071e0a29084b00c060872ccc0f72777b15a583c8a052f85126e94922f1e1b5c7fefdbdad70d46f7ecf1d5b26140690bfe4bc
7
+ data.tar.gz: c2ca9876c7d8c1d23e63290e2273e2219004932d19d2ffcf2c118a482c29b50bdd0570c55f4ec687908a916e751a0a58212e312ded6c279f977da2dc62c54cba
data/CHANGELOG.md CHANGED
@@ -37,6 +37,28 @@ version you have and a newer one.
37
37
  a release needs is said in the gemspec, and an entry says so only
38
38
  when the answer changes. -->
39
39
 
40
+ ## 0.1.7
41
+
42
+ - Change: needs CArray 3.0.6 or later in the 3.0 series; install it
43
+ alongside this release. An element-wise pass is handed to
44
+ `CArray::AddressBasis.sweep`, which 3.0.6 is the first to have.
45
+
46
+ - Change: the kernel cache keeps 2000 kernels per environment by
47
+ default, up from 512, which is about 60 MB on disk. A program that
48
+ compiled more than 512 rebuilt the ones evicted each time it ran. Set
49
+ `CARRAY_JIT_CACHE_LIMIT` for a different bound.
50
+
51
+ - Change: `jit_for` and `jit_init` cost less per call when called again
52
+ with operands that agree in name, type and mask, and a kernel writing
53
+ an `int64` array is vectorised as a `float64` one is.
54
+
55
+ - Fix: a lazy expression or `CArray.fuse` computed here keeps the sign of
56
+ a NaN as CArray does: `(a * -1).signbit` and a NaN fill of `shift`
57
+ gave other bits with the evaluator registered.
58
+
59
+ - Fix: kernels built at once by several threads, or in Ractors, no
60
+ longer raise `Errno::ENOENT`.
61
+
40
62
  ## 0.1.6
41
63
 
42
64
  - Change: needs CArray 3.0.5 or later in the 3.0 series; install it
data/README.md CHANGED
@@ -35,7 +35,7 @@ gem "carray-jit"
35
35
  Requires:
36
36
 
37
37
  - Ruby >= 3.2
38
- - CArray >= 3.0.5, < 3.1
38
+ - CArray >= 3.0.6, < 3.1
39
39
  - A C compiler
40
40
  - Prism and Fiddle (both ship with Ruby; Fiddle is a bundled gem)
41
41
 
data/carray-jit.gemspec CHANGED
@@ -33,7 +33,9 @@ Gem::Specification.new do |spec|
33
33
  spec.executables = ["carray-jit"]
34
34
 
35
35
  # A kernel reaches CArray's C by address, so the ceiling is the next minor.
36
- spec.add_dependency "carray", ">= 3.0.5", "< 3.1"
36
+ spec.add_dependency "carray", ">= 3.0.6", "< 3.1"
37
37
  # fiddle ships as a bundled gem; depend on it explicitly so Ruby 3.5+ resolves it.
38
- spec.add_dependency "fiddle"
38
+ # 1.1.1, which Ruby 3.2 ships, is the first with TYPE_UCHAR and the other
39
+ # unsigned types.
40
+ spec.add_dependency "fiddle", ">= 1.1.1"
39
41
  end
@@ -46,7 +46,7 @@ It is the same shape of block `CArray.jit_function` takes, and not the same thin
46
46
 
47
47
  #### Who drives the loop
48
48
 
49
- An element-wise pass is the one shape that is a *sweep* -- nothing reaches a neighbour, nothing chooses an order -- so CArray can drive it instead. Where this CArray has `ca_call_cslab` (3.0.1 and later), `jit_each` hands it the compiled body and lets it acquire the operands.
49
+ An element-wise pass is the one shape that is a *sweep* -- nothing reaches a neighbour, nothing chooses an order -- so CArray can drive it instead: `jit_each` hands its chunked sweep (`ca_call_cslab`) the compiled body and lets it acquire the operands.
50
50
 
51
51
  The body is the same either way. The sweep entry point is a wrapper that calls the same kernel with the chunk as its bounds, so what changes is who opens the arrays, not what they compute.
52
52
 
@@ -56,7 +56,7 @@ A **strided view** is the case where there is. A column, a transpose, every othe
56
56
 
57
57
  The rank does not stand in the way, and the arrays are not reshaped to get it out of the way. CArray's acquire reads an operand's element count and element size and never looks at its shape, so a chunk is already a flat run of cells; what has to be flat is the *kernel*, and it is compiled at rank one over the same cells rather than as a nest over the axes. One such kernel then serves whatever rank it is given, because the rank has left the loop.
58
58
 
59
- Four things keep the driver here. An operand that is a **strided view**, for the reason just measured: it is walked in place here, and re-gathered there for nothing. A **stretched operand**, which is the one thing that cannot be flattened: broadcasting arrives as a stride of zero on an axis, and a flat run has no axes, so cell k of the output would stop lining up with cell k of the operand. A body that **asks about a mask**, because a chunk carries no per-cell mask to ask it of -- CArray ORs and propagates the masks, but `a[i] == UNDEF` is a question about one cell. A CArray **without the family** at all, which is asked for by symbol rather than assumed, so an older one falls back without the caller hearing about it.
59
+ Four things keep the driver here. An operand that is a **strided view**, for the reason just measured: it is walked in place here, and re-gathered there for nothing. A **stretched operand**, which is the one thing that cannot be flattened: broadcasting arrives as a stride of zero on an axis, and a flat run has no axes, so cell k of the output would stop lining up with cell k of the operand. A body that **asks about a mask**, because a chunk carries no per-cell mask to ask it of -- CArray ORs and propagates the masks, but `a[i] == UNDEF` is a question about one cell. And **more than seven operands**, because seven is the widest the sweep family is generated for.
60
60
 
61
61
  Whichever drives it, an operand that is **read while the pass writes the array it is a view of** is copied once before the loop. `a = b * 2.0` reads the whole right-hand side and then assigns; a kernel walks cell by cell, which is the same thing until a cell it reads is one it has written -- `hi = lo * 2.0` over two blocks that share six cells, a transpose written over itself. The copy is what makes those read the values the expression started with, as CArray's own operators do, and it is what lets the chunked sweep take them: what it re-gathers per chunk is then a copy nothing is writing to. Sharing a root is the test rather than overlapping cells, a view knowing what it is a view of; `a = a + 1.0` is not that case, the cell read being the cell written.
62
62
 
@@ -854,7 +854,7 @@ A window may be opened inside a window, and `#call` may be made inside one: both
854
854
 
855
855
  One flag per compiled object and one per thread, so two functions never share a window and neither do two threads. The second half matters more than it sounds: the object is shared whether or not anybody meant to share it, because two blocks with the same text compile to one function. So a program that never mentions threads can open two windows on one body, and one flag between them is a window neither of them can read -- the second to open puts down what the first had already recorded. The flag and the hook are `_Thread_local`, which costs about half a nanosecond a call, and only on a body that has a flag at all.
856
856
 
857
- The thread is the native one, which for Ruby is the thread that opened the window -- except under the M:N scheduler (a non-main Ractor's threads, or `RUBY_MN_THREADS=1`), where a Ruby thread is not tied to one native thread and the window cannot be relied on to be the same copy throughout.
857
+ The thread is the native one, which for Ruby is the thread that opened the window -- except under the M:N scheduler, where a Ruby thread is not tied to one native thread and the window cannot be relied on to be the same copy throughout. Which threads that is depends on `RUBY_MN_THREADS`: unset or `0`, a non-main Ractor's threads; `1`, the main Ractor's threads other than the main thread as well; and from Ruby 4.1, `2`, the main thread too, so that no thread is outside it. `-1`, also from Ruby 4.1, takes every thread out of it.
858
858
 
859
859
  What this leaves outside the window is a library that calls the body from threads of its own. The flag such a call raises belongs to the thread that raised it: the body stops answering there, as it should, and the window watching from Ruby sees nothing and raises nothing. A library that calls back on the thread it was called from -- which is what GSL and NLopt do -- is inside the window.
860
860
 
data/docs/04_Compiling.md CHANGED
@@ -67,7 +67,7 @@ In `~/.cache/carray-jit` (honouring `XDG_CACHE_HOME`), one directory per version
67
67
 
68
68
  A kernel is only good for the version that generated it and the architecture it was built for, so those get their own directories. CArray's version is there for the same reason and one of its own: a kernel is handed CArray's memory, on layouts CArray decides, so one compiled against one version and run against the next would answer wrongly rather than fail to load.
69
69
 
70
- The two numbers say different things and move on their own clocks: the first is the version that generated the kernel, the second the version it was generated against. This gem is not versioned with CArray, and one release of it meets more than one -- the dependency is `>= 3.0.5, < 3.1`, so 3.0.5 and 3.0.6 both satisfy it -- and a layout the kernel reaches into can move between them. A new release does not spend its cache budget on entries nothing can reach any more, and a home directory shared between machines -- over NFS, or between Rosetta and native -- does not have one architecture evicting the other's kernels. A directory whose newest entry has not been touched in 30 days (`CARRAY_JIT_CACHE_MAX_AGE_DAYS`) is removed.
70
+ The two numbers say different things and move on their own clocks: the first is the version that generated the kernel, the second the version it was generated against. This gem is not versioned with CArray, and one release of it meets more than one -- the dependency is `>= 3.0.6, < 3.1`, so 3.0.6 and 3.0.7 both satisfy it -- and a layout the kernel reaches into can move between them. A new release does not spend its cache budget on entries nothing can reach any more, and a home directory shared between machines -- over NFS, or between Rosetta and native -- does not have one architecture evicting the other's kernels. A directory whose newest entry has not been touched in 30 days (`CARRAY_JIT_CACHE_MAX_AGE_DAYS`) is removed.
71
71
 
72
72
  ```ruby
73
73
  CArray::JIT.cache_root #=> "/home/you/.cache/carray-jit"
@@ -99,7 +99,7 @@ The path is expanded where it is given, so a relative one does not move when the
99
99
 
100
100
  `CARRAY_JIT_CACHE` and `CARRAY_JIT_NO_CACHE` still come first, so whoever runs the program has the last word on where a cache may be written and whether there is one at all. `CArray::JIT.cache_root = nil` restores the default.
101
101
 
102
- The cache is **bounded**: past `CARRAY_JIT_CACHE_LIMIT` kernels per environment (512 by default, so about 9 MB) the least recently used are evicted, source and object together. Reuse updates an entry's timestamp, so what a program actually runs stays. This is the one place carray-jit deliberately parts with RubyInline, whose `~/.ruby_inline` has no eviction at all and grows for the life of the account.
102
+ The cache is **bounded**: past `CARRAY_JIT_CACHE_LIMIT` kernels per environment (2000 by default, so about 60 MB) the least recently used are evicted, source and object together. Reuse updates an entry's timestamp, so what a program actually runs stays. This is the one place carray-jit deliberately parts with RubyInline, whose `~/.ruby_inline` has no eviction at all and grows for the life of the account.
103
103
 
104
104
  Removing a cached object never breaks a kernel already in use: unlinking a loaded shared object leaves its mapping intact.
105
105
 
@@ -143,7 +143,7 @@ carray_jit_contiguous (char **pointers, int64_t *strides, int64_t *bounds, ...)
143
143
  const int64_t legendre_s0 = strides[0];
144
144
  const double x = reals[0];
145
145
 
146
- for (int64_t i = bounds[0]; i < bounds[1]; i++) {
146
+ for (int64_t i = bounds[0], i__limit = bounds[1]; i < i__limit; i++) {
147
147
  double w;
148
148
  double wy;
149
149
  w = x * ((double *)(p_legendre))[i - 1];
@@ -165,7 +165,7 @@ root /home/you/.cache/carray-jit
165
165
  environment 0.1.0-carray3.0.1-arm64-darwin24
166
166
  kernels 3
167
167
  size 50.1 KB
168
- limit 512 kernels
168
+ limit 2000 kernels
169
169
 
170
170
  other environments:
171
171
  0.0.9-carray3.0.1-arm64-darwin24 1.2 MB last used 2026-01-01
@@ -217,7 +217,7 @@ carray_jit_contiguous (char **pointers, int64_t *strides, int64_t *bounds, ...)
217
217
  | `CARRAY_JIT_DUMP` | Print generated C to stderr before compiling |
218
218
  | `CARRAY_JIT_CACHE` | Cache directory (default `~/.cache/carray-jit`, or what `CArray::JIT.cache_root=` named), or `none` |
219
219
  | `CARRAY_JIT_NO_CACHE` | Keep the cache in a temporary directory, removed on exit |
220
- | `CARRAY_JIT_CACHE_LIMIT` | Kernels retained on disk, per environment (default 512) |
220
+ | `CARRAY_JIT_CACHE_LIMIT` | Kernels retained on disk, per environment (default 2000) |
221
221
  | `CARRAY_JIT_CACHE_MAX_AGE_DAYS` | Days an unused environment's directory is kept (default 30) |
222
222
  | `CARRAY_JIT_CC` | C compiler (default `RbConfig::CONFIG["CC"]`) |
223
223
  | `CARRAY_JIT_REASSOCIATE` | `0` makes the serial accumulator the default for the process |
@@ -1880,7 +1880,7 @@ class CArray
1880
1880
  "`#{name}` to; declare what it points at",
1881
1881
  argument.location)
1882
1882
  end
1883
- wanted = CDeclaration::DATA_TYPES.fetch(parameter.element.fiddle).to_s
1883
+ wanted = CDeclaration::DATA_TYPES.fetch(parameter.element.abi).to_s
1884
1884
  unless storage == wanted
1885
1885
  raise Unsupported.new(
1886
1886
  "`#{c_function}` takes `#{parameter.text}` there, which is a " \