[QUESTION] Does func_native prevent function inlining ?
I used the following code to wrap and invoke a warp-level instruction, but Nsight Compute shows it's being compiled into a function call. Is my understanding incorrect, or is this the intended behavior?
@wp.func_native("""
return __shfl_sync(0xFFFFFFFF, var, src_lane);
""")
def shfl_sync(var: float, src_lane: int) -> float: ...
nsight compute:
IMAD.MOV.U32 R29, RZ, RZ, 0x0
WARPSYNC 0xffffffff
SHFL.IDX PT, R30, R40, RZ, 0x1f
RET.REL.NODEC R28, 0xd00e8f700
I'm not very familiar with reading SASS, but it looks like SHFL.IDX appears twice in the compiled output, even though I only called __shfl_sync once. One occurrence of SHFL.IDX is a direct call (which matches my expectation—it should be inlined); the other is inside a function (as shown above). Could this be related to automatic differentiation? I tried setting enable_backward=False, but that didn't change anything.
It might be useful to check the .cu file that gets generated. You can find it in the kernel cache directory that gets printed at initialization.
It might be useful to check the
.cufile that gets generated. You can find it in the kernel cache directory that gets printed at initialization.
Thanks for the reminder. Here is the .cu file. This function is only called once in the file.
// It seems it's not marked as inline.
static CUDA_CALLABLE wp::float32 shfl_sync_0(
wp::float32 var,
wp::int32 src_lane)
{
return __shfl_sync(0xFFFFFFFF, var, src_lane);
}
Perhaps there's some mechanism I'm not aware of that generates shfl.down or shfl.idx instructions? Maybe I need to learn more about SASS.
On a slightly off-topic note, I came across the following code.
for (size_t _idx = static_cast<size_t>(blockDim.x) * static_cast<size_t>(blockIdx.x) + static_cast<size_t>(threadIdx.x);
_idx < dim.size;
_idx += static_cast<size_t>(blockDim.x) * static_cast<size_t>(gridDim.x))
As I understand it, this is the so-called "grid-stride loop"? But it doesn't seem to be taking effect. Could I remove it to reduce the actual working code and register usage ?
Perhaps there's some mechanism I'm not aware of that generates shfl.down or shfl.idx instructions? Maybe I need to learn more about SASS. On a slightly off-topic note, I came across the following code.
for (size_t _idx = static_cast<size_t>(blockDim.x) * static_cast<size_t>(blockIdx.x) + static_cast<size_t>(threadIdx.x); _idx < dim.size; _idx += static_cast<size_t>(blockDim.x) * static_cast<size_t>(gridDim.x)) As I understand it, this is the so-called "grid-stride loop"? But it doesn't seem to be taking effect. Could I remove it to reduce the actual working code and register usage ?
I noticed in the Warp source code that when max_blocks is set to 0 at launch, the grid-stride loop doesn't actually do anything useful — it just wastes registers. Would it be better to disable the grid-stride loop entirely when max_blocks is 0?