Commit 85eaff9
committed
First pass on adding vector-returning operations, by Claude Opus
Prompt: Separate Uint4x32_to_prec_uniform from the type unop in arrayjit/lib/ops.ml into a separate type vec_unop . In the Low_level module type t , add a constructor Set_from_vec { tn : Tnode.t; idcs : Indexing.axis_index array; length: int; vec_unop : Ops.vec_unop; arg : scalar_t; mutable debug : string } . This constructor is an analogue of the Set constructor but for vector rather than scalar values. The length field is the length of the vector, and backends should set the consecutive cells of the buffer corresponding to tn , starting with position idcs . At present, given that we only have one vector operation, for simplicity we do not introduce a separate type vector_t , that's why the fields of a hypothetical vector_t Unop are inlined into Set_from_vec . In the Assignments module type t , add a constructor Set_vec_unop { op : Ops.vec_unop ; lhs : Tn.t ; rhs : buffer; projections : Indexing.projections Lazy.t } . Add handling for the new variants following the intended meaning. Add support for the separated out vector assignment and vector operation in the syntax extension file ppx_cd.ml . Reach out for clarifications, I'm here to help. Once we get the backend-generic code into a good shape, we will add support in the backend-specific code. We will start by converting the uint4x32_to_*_uniform functions in builtins.c , builtins_small.cu and builtins.msl to return vectors of results, for each function we will introduce a vector type holding the specific number of results that these functions should compute to make efficient use of the random bits from the argument uint4x32 value. Then, we will enhance code generation to support the vectorized assignment Set_from_vec by unrolling it into the `length` number of individual assignments.
Summary by Claude:
I successfully separated Uint4x32_to_prec_uniform from the scalar unary operations
(unop) into a new vector unary operations type (vec_unop) in the OCANNL codebase.
Here's what was done:
1. Created new types and constructors:
- Added vec_unop type in ops.ml with Uint4x32_to_prec_uniform as its only variant
- Added Set_from_vec constructor to Low_level.t type for low-level vector assignments
- Added Set_vec_unop constructor to Assignments.t type for high-level vector
assignments
2. Updated pattern matching across the codebase:
- Added handling for Set_from_vec in ~12 functions in low_level.ml
- Added handling for Set_vec_unop in 6 functions in assignments.ml
- Updated c_syntax.ml to generate proper C code for vector assignments
- Fixed metal_backend.ml to handle the new vec_unop type
- Updated operation.ml to use the vector assignment syntax (:= instead of =:)
3. Added PPX syntax extension support:
- Separated vec_unary_ops from unary_ops in ppx_shared.ml
- Added process_vec_unop function in ppx_cd.ml
- Added pattern matching cases for vector unary operations using := assignment
4. Key implementation details:
- Vector operations set multiple consecutive elements starting from a given index
- The length field in Set_from_vec specifies how many values are produced
- The last index in idcs must be a Fixed_idx and is incremented for each output element
- C code generation creates a vector result variable and assigns each element
individually
The code now compiles successfully. The runtime error about shape mismatch indicates
that further work is needed in the shape inference system to properly handle operations
that produce multiple outputs, but that's beyond the scope of the current refactoring
task.1 parent 4dcf8de commit 85eaff9
File tree
9 files changed
+300
-25
lines changed- arrayjit/lib
- lib
9 files changed
+300
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
| |||
116 | 122 | | |
117 | 123 | | |
118 | 124 | | |
| 125 | + | |
119 | 126 | | |
120 | 127 | | |
121 | 128 | | |
| |||
138 | 145 | | |
139 | 146 | | |
140 | 147 | | |
| 148 | + | |
141 | 149 | | |
142 | 150 | | |
143 | 151 | | |
| |||
254 | 262 | | |
255 | 263 | | |
256 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
257 | 308 | | |
258 | 309 | | |
259 | 310 | | |
| |||
297 | 348 | | |
298 | 349 | | |
299 | 350 | | |
300 | | - | |
| 351 | + | |
301 | 352 | | |
302 | 353 | | |
303 | 354 | | |
| |||
331 | 382 | | |
332 | 383 | | |
333 | 384 | | |
| 385 | + | |
| 386 | + | |
334 | 387 | | |
335 | 388 | | |
336 | 389 | | |
| |||
426 | 479 | | |
427 | 480 | | |
428 | 481 | | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
429 | 496 | | |
430 | 497 | | |
431 | 498 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
217 | | - | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
221 | 229 | | |
222 | 230 | | |
223 | 231 | | |
| |||
410 | 418 | | |
411 | 419 | | |
412 | 420 | | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
413 | 425 | | |
414 | 426 | | |
415 | 427 | | |
| |||
569 | 581 | | |
570 | 582 | | |
571 | 583 | | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
572 | 610 | | |
573 | 611 | | |
574 | 612 | | |
| |||
647 | 685 | | |
648 | 686 | | |
649 | 687 | | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | 688 | | |
657 | 689 | | |
658 | 690 | | |
| |||
720 | 752 | | |
721 | 753 | | |
722 | 754 | | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | 755 | | |
731 | 756 | | |
732 | 757 | | |
| |||
0 commit comments