MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / operator()

Method operator()

csrc/xpu_kernels.cpp:97–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95
96template <typename T, int TILE_SIZE, int NUM_PER_TH, int DATA_TYPE>
97SYCL_EXTERNAL void kDequantizeBlockwise<T, TILE_SIZE, NUM_PER_TH, DATA_TYPE>::operator()(sycl::nd_item<1> item) const {
98 const int64_t base_idx = static_cast<int64_t>(item.get_group(0)) * TILE_SIZE;
99 int64_t local_idx = static_cast<int64_t>(item.get_local_id(0)) * NUM_PER_TH;
100 float local_abs_max = -FLT_MAX;
101 int64_t local_load_idx = 0;
102 int64_t local_store_idx = 0;
103
104 uint8_t qvals[NUM_PER_TH];
105 T vals[NUM_PER_TH * ((DATA_TYPE > 0) ? 2 : 1)];
106
107 if (DATA_TYPE > 0) {
108 // Cast n to int64_t to avoid overflow for large n (same as CUDA)
109 local_load_idx = sycl::min(static_cast<int64_t>(TILE_SIZE), (static_cast<int64_t>(n) + 1) / 2 - base_idx);
110 local_store_idx = sycl::min(static_cast<int64_t>(TILE_SIZE * 2), static_cast<int64_t>(n) - base_idx * 2);
111 } else {
112 local_load_idx = sycl::min(static_cast<int64_t>(TILE_SIZE), static_cast<int64_t>(n) - base_idx);
113 local_store_idx = local_load_idx;
114 }
115
116 // Avoid expensive division by the blocksize (as blocksize will always be a
117 // power-of-2)
118 local_abs_max = absmax[(base_idx + local_idx) >> (31 - std::countl_zero<unsigned int>(blocksize))];
119
120 if (local_idx + NUM_PER_TH < local_load_idx) {
121 reinterpret_cast<sycl::vec<uint8_t, NUM_PER_TH>(&)[NUM_PER_TH]>(qvals)[0] =
122 reinterpret_cast<sycl::vec<uint8_t, NUM_PER_TH>*>(A)[(base_idx + local_idx) / NUM_PER_TH];
123 } else {
124#pragma unroll NUM_PER_TH
125 for (int i = 0; i < NUM_PER_TH; i++) {
126 if (local_idx + i < local_load_idx) {
127 qvals[i] = A[base_idx + local_idx + i];
128 } else {
129 qvals[i] = (uint8_t)0;
130 }
131 }
132 }
133
134 switch (DATA_TYPE) {
135 case General8bit:
136#pragma unroll NUM_PER_TH
137 for (int j = 0; j < NUM_PER_TH; j++)
138 vals[j] = code[qvals[j]] * local_abs_max;
139 break;
140 case FP4:
141#pragma unroll NUM_PER_TH
142 for (int j = 0; j < NUM_PER_TH; j++) {
143 vals[j * 2] = dDequantizeFP4(qvals[j] >> 4) * local_abs_max;
144 vals[j * 2 + 1] = dDequantizeFP4(qvals[j] & 0x0F) * local_abs_max;
145 }
146 break;
147 case NF4:
148#pragma unroll NUM_PER_TH
149 for (int j = 0; j < NUM_PER_TH; j++) {
150 vals[j * 2] = dDequantizeNF4(qvals[j] >> 4) * local_abs_max;
151 vals[j * 2 + 1] = dDequantizeNF4(qvals[j] & 0x0F) * local_abs_max;
152 }
153 break;
154 }

Callers

nothing calls this directly

Calls 2

dDequantizeFP4Function · 0.70
dDequantizeNF4Function · 0.70

Tested by

no test coverage detected