Repository navigation
Conversation
Resolve conflicts with main and bring the CUDA Tile IR backend back to a state where the full correctness suite passes under host-cuda-cuda_capability_120-cuda_tile_ir (host and PTX CUDA also pass). Notable changes on top of the merge: - Target bytecode 13.4 and use alloca for per-thread local storage. - Add Func::gpu_min_resident_blocks scheduling directive (occupancy hint). - Emit tile stores for output instead of scalar stores. - Thread register tiles and memory tokens through For/If regions, restoring the outer token after reduce regions. - Native transpose, row-wise VectorReduce, power-of-two checks on concat/slice fast paths, nested ramp/broadcast support. - Emit tile IR assert for AssertStmt in kernels. - LICM no longer lifts expressions containing any vector subexpression. - lower_mux only unwraps scalar broadcast indices. - Skip wmma tests and gpu_thread_barrier under tile IR. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Factor region capture and carried-value handling into shared helpers, merge register tile bookkeeping into one record, build VectorReduce bodies from Halide Exprs with identities from Type::max/min, drop RewrapInnermost from FuseGPUThreadLoops, and tidy RemapCUDATileIRLoops. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Unify binary/unary/comparison emission, make Call lowering table-driven, share concat/extract helpers for shuffles, simplify Cast, atomics, block id lookup, pointer casts and buffer element type tracking. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restructure the LowerMma matcher as a single function with early returns, decompose linear expressions by substitution, and let emit_op take an op's leading varint fields. Add write_varints, write_list and optional-operand helpers for the remaining encodings. The generated bytecode is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Require constant operand strides when matching, as the codegen does, and decompose both operands' base addresses the same way. A constant k offset in A's base (e.g. from unrolling the k loop) now goes into its k tile coordinate rather than its pointer offset. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Integer, float, and reduction-identity constants now share one bit encoding. float16 constants previously emitted four-byte payloads, producing invalid bytecode, and bfloat16 was tagged as f16 because Type::is_float() is also true for bfloat. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ConstantOp already splats a scalar payload across a tile, so there's no need to build vector constants with a reshape and broadcast. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tomics Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Key the type table on its entries rather than hand-built strings, share section framing and little-endian writing, and build the function table before the string and type tables it refers to instead of pre-registering its entries. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ed helpers The shared lower_euclidean_div/mod helpers had simplify() removed because it canonicalized power-of-two masks back into Mod nodes. Handle power-of-two divisors in the Tile IR pre-pass with shifts and masks instead, as CodeGen_C does, so the shared helpers match main again. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Lower concat_bits everywhere during flatten_nested_ramps, which removes the wrapper mutator, the Stmt lower_concat_bits export, and the backend's own call to it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reduce region is generated from the same Expr combiner as the scalarized fallback, so SaturatingAdd (identity zero) no longer needs to be scalarized. Checked with a vectorized atomic saturating_add reduction on uint8 and uint16. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the ReturnOp into the emitter, shadow buffer pointers with their aligned versions, and pass the tensor view operands as op fields. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ister tile accessors Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add an overview comment to CodeGen_TileIR_Dev.cpp describing the lowering passes, classes, and runtime path, and clarify related comments in LICM, PartitionLoops, and TileIR.h. A total VectorReduce of a non-power-of-two vector reduced the padding lanes too, which gave wrong answers for min and max. Select the identity into the padding lanes first. Add a regression test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Atomic RMW ops on non-power-of-two vectors pass the padding mask, so the padding lanes no longer write past the end of the buffer. - The compare-and-swap fallback runs one scalar CAS loop per lane, and threads the memory token through the loop. It previously passed a vector condition to cuda_tile.if, which the driver rejected. - LowerMma only matches floating-point products. mmaf rejects integer operands. - Float not-equal uses an unordered comparison, so it is true for NaN. - trunc is select(x < 0, ceil(x), floor(x)) rather than a round trip through int32, which was wrong for magnitudes beyond 2^31 and inf. Adds gpu_vectorized_atomics and gpu_integer_matmul tests, and large inputs to the round test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Atomic codegen matched the whole body against a single unpredicated Store and emitted anything else non-atomically. It now works per Store, like CodeGen_LLVM: a Store whose value loads from the stored buffer becomes an atomic RMW or a compare-and-swap loop, and other Stores are relaxed. Atomic nodes that need a mutex are a user error, as on PTX. Inside a compare-and-swap loop, loads of the element being updated read the compared value, and other loads of the buffer are relaxed, selecting the compared value when the indices alias at runtime. This matches the semantics of #9700 for the LLVM backends. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Matches the CUDA backend's error rather than emitting bytecode that fails verification. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A Register allocation in a Tile IR kernel silently fell back to an alloca when its accesses weren't one full-tile access, so dynamically indexed registers (gpu_register_dynamic_index) weren't rejected. RemapCUDATileIRLoops now keeps Register memory only for allocations promote_gpu_registers would give per-thread registers to (shared predicate holds_thread_registers), demoting the rest to Auto, since Tile IR has no per-thread or per-warp registers. promote_gpu_registers then runs get_subtile on the remaining ones in place, giving the same errors as on PTX and dense constant subtile indices. To consume those, the codegen's register tiles become a set of disjoint dense subtiles, each its own SSA value, and predicated stores to them select against the old value. This also promotes Auto allocations accessed as several disjoint subtiles. RegisterTileAnalyzer now visits let values, which it previously skipped, missing loads in them. Shuffles that broadcast a vector or repeat each lane now use reshape+broadcast instead of per-element extracts. With f31_in$0 in register_shuffle promoted, the extract path faulted with CUDA_ERROR_MISALIGNED_ADDRESS, probably a tileiras miscompile. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Type stored lanes in 16 bits, capping vectors at 65535 lanes, which is too small for the tile-sized vectors a tile-based GPU backend manipulates. Lanes are now a uint32_t (up to 2^31-1 usable, as lanes() returns int), and the handle/struct metadata index shrinks to 16 bits to keep sizeof(Type) == 8. The ABI halide_type_t is unaffected: it never carried lanes. Type::hash() can no longer memcpy the first 32 bits, so it mixes the code, bits, and lanes explicitly. IRMatch's 4-byte BoundConstType can't hold a 32-bit lane count, so the matcher binds full Types again. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Lets a schedule ask the GPU compiler to fit at least n blocks of a kernel on one processor at once, trading per-block resources (mostly registers) for occupancy. Like gpu_max_registers, it takes an explicit DeviceAPI and only CUDA acts on it, where it becomes the PTX .minnctapersm directive (via the nvvm.minctasm function attribute). Other device APIs warn and ignore it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Buffer parameters gain device_alignment()/set_device_alignment(), the device-side counterpart of host_alignment. It defaults to the element size, and is serialized alongside host_alignment. PTX codegen used host_alignment to reason about device pointers, which says nothing about them. It now uses device_alignment, via a new CodeGen_LLVM::external_buffer_alignment hook. The PTX rewrite of 4-wide 32-bit loads and stores into 128-bit accesses also only considered the alignment of the index, so a device crop offset by a non-multiple of 16 bytes (e.g. one element of a float buffer) failed with CUDA_ERROR_MISALIGNED_ADDRESS when the buffer's min was constrained. That rewrite now requires a 16-byte-aligned base pointer. A requested device alignment is checked at runtime by a new halide_device_check_alignment, injected after each copy_to_device or device_malloc the pipeline does for the buffer. External buffers start in an unknown state, so the first device use always goes through one of these, which covers buffers that arrive with no device allocation. The check asks the device interface for the pointer's alignment through a new device_alignment member of halide_device_interface_impl_t. Only CUDA implements it; on other device APIs requesting a device alignment is a runtime error. A misaligned pointer produces the new halide_error_code_unaligned_device_ptr (-50). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Binding constant types in the matcher as full Types made correctness_simplify execute 2.2% more instructions than main, because comparing Types also checks handle and struct metadata, which bound constants never have. Restoring the code+bits+lanes BoundConstType, widened to 32-bit lanes, brings that to +0.2%, and lowering local_laplacian from +0.44% to +0.15%. Type::hash packs the low 16 bits of lanes above code and bits, matching main's hash for any lane count main supports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…le_ir # Conflicts: # src/IRMatch.h # src/Type.h
… into abadams/tile_ir # Conflicts: # src/CodeGen_GPU_Dev.h # src/Func.cpp # src/Func.h # test/correctness/gpu_min_resident_blocks.cpp
The operands only ever live on the device, and PTX codegen now takes pointer alignment from device_alignment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Decomposing by substitution needed the simplifier to prove e == a * var + b, which it can't do for indices like (y * 64 - min) * 1024. Matrix multiplies on buffers with unconstrained mins fell back to a vector reduction, which made the cuda_mat_mul tile IR kernel about 500x slower. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9733 +/- ##
==========================================
- Coverage 73.24% 71.78% -1.47%
==========================================
Files 266 270 +4
Lines 83749 84667 +918
Branches 20573 20937 +364
==========================================
- Hits 61346 60778 -568
- Misses 15859 17305 +1446
- Partials 6544 6584 +40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a prototype cuda backend that passes tile IR kernels to the driver instead of PTX. It gets the same matmul performance as the wmma work, but the schedule is much easier to write because the driver handles a lot of stuff for you (e.g. staging through shared). TileIR is intended to be more portable across nvidia microarchitectures than using PTX directly.
Most of the code is just tileIR bitcode emission. In Halide lowering, the gputhreads dimensions are just treated as vectorized dimensions, and large vectors are passed to the backend.
Opening as draft for discussion.