AMD HCC Swizzle 内在

AMD HCC Swizzle Intrinsic

我最近才发现 AMD 相当于 CUDA 的 __byte_perm 内在; amdgcn_ds_swizzle(或者至少我认为它相当于一个字节置换函数)。我的问题是:CUDA 的 byte perm 接受两个无符号 32 位整数,然后根据选择器参数的值(以十六进制值提供)对其进行置换。但是,AMD 的 swizzle 函数只接受一个无符号的 32 位整数和一个名为 "pattern" 的 int。如何使用 AMD 的 Swizzle 内在函数?

ds_swizzle__byte_perm 确实有点不同。一个跨通道置换整个寄存器,后者置换两个 32 位寄存器中的任意四个字节。

AMD 的 ds_swizzle_b32 GCN instruction is actually swapping values with other lanes. You specify the 32-bit register in the lane you want to read and the 32-bit register you want to place it in. There is also a hard-coded value that specifies how these are to be swapped. A great explanation of ds_swizzle_b32 is here 正如 user3528438 指出的那样。

__byte_perm不与其他通道交换数据。它只是从它自己的通道中的两个 32 位寄存器中收集任意 4 个字节,并将其存储到一个寄存器中。没有跨车道交通。

我猜下一个问题是如何在 AMD GCN 硬件上执行 "byte permute"。指令是 v_perm_b32。 (参见第 12-152 页 here)它基本上是从两个指定的 32 位寄存器中选择任意四个字节。