Repository navigation
[Tile] tile DeviceTransform port - #9210
Conversation
| auto num_items = ct::assume_bounded_below<0>(ct::assume_divisible<16>(num_items_)); | ||
| auto out = ct::assume_aligned<16>(out_); |
There was a problem hiding this comment.
Suggestion: For a fair comparison, the transform_kernel should support unaligned data as well. This can be just a branch dispatching two an aligned and an unaligned code path.
There was a problem hiding this comment.
Indeed! However, I have observed very bad performance on tile kernels in this case. When the pointer is not aligned, all loads will not be vectorized. CUB does way better with TMA & overcopying.
I am asking compiler people to see if they can add this heuristics, since having this will make a much more informative benchmark
There was a problem hiding this comment.
That is a very good idea! Please help them improve tile!
Unaligned inputs are less common but do appear. Examples are if you want to run a kernel on the output of a previous one, where the previous one also chose the problem size. Like, you partition an array by a predicate and then only transform the elements of the selected partition, etc. Such cases come up frequently in database or dataframe workloads.
|
I am genuinely impressed by the size of the tile kernel! It's really small and expressive. Nice! |
|
NOTE: Not ready to merge due to regular device transform SIMT kernels will fail to compile with This now introduces tile kernels with no call site change for users. To opt in at build time, please compile with The basic idea is, at compile time, eligible First, a SIMT functor that will be called at the API: Second, a tile functor that has the same semantical meaning: And third, the trait specialization that links those two functors: The general idea is that as cutile c++ gets more and more mature and performant, we can correspondingly register more and more cases until it covers all the cases. The dispatch flow is as follows: Those runtime preconditions exist because current bad cutile performance on those cases.
|
fbusato
left a comment
There was a problem hiding this comment.
I did a first pass for the library implementation. The implementation is already great!!
I pointed out some compatibility and stylistic issues.
|
/ok to test b893189 |
This comment has been minimized.
This comment has been minimized.
|
/ok to test 9af44e6 |
This comment has been minimized.
This comment has been minimized.
9af44e6 to
1960f3f
Compare
|
/ok to test 1960f3f |
This comment has been minimized.
This comment has been minimized.
| // Defined as a literal 1/0 (not (_CCCL_CUB_HAS_TILE_TRANSFORM() && defined(...))) so that | ||
| // `#if _CCCL_CUB_TILE_TRANSFORM_DISPATCH_ENABLED()` in non-system code (benches, tests) does not | ||
| // generate `defined` via macro expansion, which is UB and trips -Wexpansion-to-defined under -Werror. | ||
| #if _CCCL_CUB_HAS_TILE_TRANSFORM() && defined(CCCL_ENABLE_TILE_TRANSFORM_DISPATCH) |
There was a problem hiding this comment.
@bernhardmgruber my feeling is that we should have a CUB specific macro to enable or disable Tile for CUB. Per-API macro looks too invasive. Any thought?
There was a problem hiding this comment.
Why not a CCCL-wide macro? But otherwise, this should definitely go into some more common/non-transform specific header. Like cub/detail/tile_support.cuh or something like that. You may also move the tile traits there.
There was a problem hiding this comment.
Why can't we just use _CCCL_TILE_COMPILATION()?
There was a problem hiding this comment.
This existed because we wanted a separate CTK version check. The version check is now redundant since the compiler fixes are back ported to 13.4 and _CCCL_TILE_COMPILATION already checks it.
|
/ok to test 88aeee3 |
…::detail::transform::tile
…RM_DISPATCH; gate on internal _CCCL_ macro
|
/ok to test 00326d7 |
This comment has been minimized.
This comment has been minimized.
fbusato
left a comment
There was a problem hiding this comment.
looks good, approved. Minor comments to address/reply
|
|
||
| #include "../common.h" | ||
|
|
||
| #if _CCCL_CUB_TILE_TRANSFORM_DISPATCH_ENABLED() |
There was a problem hiding this comment.
question. Does it make sense to use _CCCL_CUB_TILE_TRANSFORM_DISPATCH_ENABLED() if the benchmarks are already gated by cmake checks?
There was a problem hiding this comment.
cmake does not skip the tile benches when the option is OFF (it builds the same files without the tile flags), so we still have to gate those code that won't compile without tile flags behind a macro
There was a problem hiding this comment.
what about disabling the compilation when the option is OFF? I don't see much value to compile the code if the benchmark is not really enabled. Or do we want this behavior to get better coverage?
There was a problem hiding this comment.
Yes, I want to still compile those TUs so they have coverage
| // serve directly as the tile_operator for the typed cuda::std::plus<T>/multiplies<T> a user passes. | ||
| # if _CCCL_HAS_NVFP16() | ||
| template <> | ||
| inline constexpr bool tile_eligible_v<::cuda::std::plus<::__half>, ::__half, 2> = true; |
There was a problem hiding this comment.
could you please remember me why we need specializations only for __half/__nv_bfloat16?
(add a comment if it is the case)
There was a problem hiding this comment.
Comment added. It is mainly because we wanted to only specialize on small types since that is the area where we observe most performance benefits.
There was a problem hiding this comment.
ok, but what about int8, int16?
There was a problem hiding this comment.
On comment: It was at line 80 - line 82. (My new commit deleted this comment, reasons see below)
On int8, int16: good point! Also, I forgot one thing: #9481 was merged yesterday, so the performance gap that motivated those specializations no longer exists. So now, I think we should just specialize for all element types the tile kernel supports, so that we can test on newer hardware.
|
/ok to test 6eb116d |
…x in tile hook; rename NIn to NumInputs
|
/ok to test 87001bc |
|
/ok to test 95a222d |
|
/ok to test 0e5f179 |
This comment has been minimized.
This comment has been minimized.
| // mufu_heavy=true tells the policy the functor body has heavy MUFU usage. | ||
| // for small data types, vectorized load will make them arrive packed in | ||
| // registers and the compiler unpacks them and packs them back. reducing the | ||
| // compute work per thread helps here. need profiling to know the exact cause. | ||
| template <typename Out, typename... Ins> | ||
| constexpr int pick_tile_size(bool mufu_heavy = false, ::cuda::compute_capability cc = {10, 0}) |
There was a problem hiding this comment.
Note: this should eventually move into the policy selector
| #define _CCCL_CUB_HAS_TILE_TRANSFORM() _CCCL_TILE_COMPILATION() | ||
|
|
||
| #if _CCCL_CUB_HAS_TILE_TRANSFORM() && defined(_CCCL_ENABLE_EXPERIMENTAL_TILE_TRANSFORM_DISPATCH) | ||
| # define _CCCL_CUB_TILE_TRANSFORM_DISPATCH_ENABLED() 1 | ||
| #else | ||
| # define _CCCL_CUB_TILE_TRANSFORM_DISPATCH_ENABLED() 0 | ||
| #endif |
There was a problem hiding this comment.
Suggestion: I don't fully understand why we need two macros. Can't we just have #define _CCCL_CUB_HAS_TILE_TRANSFORM() _CCCL_TILE_COMPILATION() && defined(_CCCL_ENABLE_EXPERIMENTAL_TILE_TRANSFORM_DISPATCH)?
I don't see why we would want to enable the tile transform headers, but not enable the dispatch at the same time.
There was a problem hiding this comment.
this is UB
#define _CCCL_CUB_HAS_TILE_TRANSFORM() _CCCL_TILE_COMPILATION() && defined(_CCCL_ENABLE_EXPERIMENTAL_TILE_TRANSFORM_DISPATCH)There was a problem hiding this comment.
Then just rephrase as:
#if _CCCL_CUB_HAS_TILE_TRANSFORM() && defined(_CCCL_ENABLE_EXPERIMENTAL_TILE_TRANSFORM_DISPATCH)
# define _CCCL_CUB_HAS_TILE_TRANSFORM() 1
#else
# define _CCCL_CUB_HAS_TILE_TRANSFORM() 0
#endifAnd replace every use of _CCCL_CUB_TILE_TRANSFORM_DISPATCH_ENABLED by _CCCL_CUB_HAS_TILE_TRANSFORM?
| // Unary: v * v. | ||
| struct square_op | ||
| { | ||
| _CCCL_EXEC_CHECK_DISABLE | ||
| template <class T> | ||
| _CCCL_API T operator()(T v) const | ||
| { | ||
| return static_cast<T>(v * v); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Suggestion: use thrust::square_t
There was a problem hiding this comment.
Just checked, thrust::square<>'s operator() is _CCCL_HOST_DEVICE only, so it doesn't work with cutile.
There was a problem hiding this comment.
Why can't we just make it _CCCL_API instead?
There was a problem hiding this comment.
We can! I just tried it and it would work. But is this something we want for thrust?
There was a problem hiding this comment.
Yes, we want that everywhere. Can you file a PR and annotate all Thrust functors with _CCCL_API?
|
@nanan-nvidia please post the latest version of the babelstream benchmark as an nvbench diff. I am curious how tile compares now that we have store vectorization. |
@bernhardmgruber Here it is: Babelstream: pytorch: |
|
/ok to test 02b2180 |
🥳 CI Workflow Results🟩 Finished in 2h 37m: Pass: 100%/287 | Total: 12d 07h | Max: 2h 36m | Hits: 20%/985613See results here. |
Interesting to see that |

This PR is a port of
cub::DeviceTransform(#8087, #9038) onto cutile, and to compare side-by-side with the existing CUB benches.The intention is that we gate all the tile code behind a Macro, so that it is invisible to user when the Macro is disabled (by default). And we can do CI / test performance of cutile with the Macro enabled.
Before the benchmarks, it is important to note that SIMT-Tile interop for TileIR is still work in progress. Thus, right now, the custom function the user passes in must be a
__tile__function, and it must consist of tile operations and must be inlinable.Current B200 benchmark on
pytorchandbabel:pytorch (tile / cub/ delta = tile - cub, BW utilisation %)
babel
copy, grayscale, fill
We did not do benchmarks on
complex,fibandheavy:complex, cutile does not acceptstd::complexas a vaild type to form tiles.fib, with tile semantics, there is no 1-to-1 fair implementation intile. We can get one by abusingct::selectbut it is much slower.heavy, cutile lowers syntax likeT reg[N]to heap allocation.There was a more detailed write up on
fibandheavyhere: #9038 (comment)