|
| 1 | +tilelang.quantize.mxfp |
| 2 | +====================== |
| 3 | + |
| 4 | +.. py:module:: tilelang.quantize.mxfp |
| 5 | +
|
| 6 | +
|
| 7 | +Attributes |
| 8 | +---------- |
| 9 | + |
| 10 | +.. autoapisummary:: |
| 11 | + |
| 12 | + tilelang.quantize.mxfp.decode_f4_to_bf16_twiddling |
| 13 | + |
| 14 | + |
| 15 | +Functions |
| 16 | +--------- |
| 17 | + |
| 18 | +.. autoapisummary:: |
| 19 | + |
| 20 | + tilelang.quantize.mxfp.get_mxfp_intrin_group |
| 21 | + |
| 22 | + |
| 23 | +Module Contents |
| 24 | +--------------- |
| 25 | + |
| 26 | +.. py:data:: decode_f4_to_bf16_twiddling |
| 27 | + :value: Multiline-String |
| 28 | + |
| 29 | + .. raw:: html |
| 30 | + |
| 31 | + <details><summary>Show Value</summary> |
| 32 | + |
| 33 | + .. code-block:: python |
| 34 | +
|
| 35 | + """ |
| 36 | + // N should be the number of elements processed by one thread |
| 37 | + template<typename T1, typename T2> |
| 38 | + __device__ void decode_fp4_to_bf16_twiddling(T1 *B_local, T2 *B_local_decode, const int N = 8) { |
| 39 | + #pragma unroll |
| 40 | + for (int i = 0; i < N; ++i) { |
| 41 | + uint B_dequantize_local_vec[4]; |
| 42 | + uint tmp, bias, d0, d1, d2, d3, d4, d5, d6; |
| 43 | + asm volatile( |
| 44 | + // To handle the endianness issue |
| 45 | + "prmt.b32 %13, %4, 0, 0x0123;" |
| 46 | + "mov.b32 %12, 0x7e807e80;" |
| 47 | + "and.b32 %0, %13, 0b10000001110000001000000111000000;" |
| 48 | + "mul.bf16x2 %0, %0, %12;" |
| 49 | + "shl.b32 %1, %13, 3;" |
| 50 | + "and.b32 %1, %1, 0b10000001110000001000000111000000;" |
| 51 | + "mul.bf16x2 %1, %1, %12;" |
| 52 | + "shl.b32 %2, %13, 6;" |
| 53 | + "and.b32 %2, %2, 0b10000001110000001000000111000000;" |
| 54 | + "mul.bf16x2 %2, %2, %12;" |
| 55 | + "shl.b32 %5, %13, 1;" |
| 56 | + "and.b32 %6, %5, 0b10000000000000001000000000000000;" |
| 57 | + "shr.b32 %7, %13, 3;" |
| 58 | + "and.b32 %8, %7, 0b00000001100000000000000110000000;" |
| 59 | + "or.b32 %9, %6, %8;" |
| 60 | + "shr.b32 %10, %13, 7;" |
| 61 | + "and.b32 %11, %10, 0b00000000010000000000000001000000;" |
| 62 | + "or.b32 %3, %9, %11;" |
| 63 | + "mul.bf16x2 %3, %3, %12;" |
| 64 | + :"=r"(B_dequantize_local_vec[0]) |
| 65 | + ,"=r"(B_dequantize_local_vec[1]) |
| 66 | + ,"=r"(B_dequantize_local_vec[2]) |
| 67 | + ,"=r"(B_dequantize_local_vec[3]) |
| 68 | + :"r"(*(uint*)&B_local[i << 2]), "r"(d0), "r"(d1), "r"(d2), "r"(d3), "r"(d4), "r"(d5), "r"(d6), "r"(bias), "r"(tmp) |
| 69 | + ); |
| 70 | + for (int j = 0; j < 4; ++j) { |
| 71 | + // Pay attention to the big-endianness issue |
| 72 | + B_local_decode[(i << 3) + j] = reinterpret_cast<T2*>(&B_dequantize_local_vec[j])[1]; |
| 73 | + B_local_decode[(i << 3) + j + 4] = reinterpret_cast<T2*>(&B_dequantize_local_vec[j])[0]; |
| 74 | + } |
| 75 | + } |
| 76 | + // Check if the synchronization is needed |
| 77 | + } |
| 78 | + """ |
| 79 | +
|
| 80 | + .. raw:: html |
| 81 | + |
| 82 | + </details> |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +.. py:function:: get_mxfp_intrin_group(out_dtype = 'bfloat16', source_format = 'uint', source_bit = 4, storage_dtype = 'uint8', use_twiddling = False) |
| 87 | +
|
| 88 | + This function is used to get the intrinsic group of the MXFP operation to avoid the overhead of fast decoding. |
| 89 | + MXFP is a type of logic operation that takes three inputs. The intrinsic group refers to the set of |
| 90 | + intrinsic operations that can be performed on these inputs. This function retrieves and returns this group. |
| 91 | + |
| 92 | + |
0 commit comments