MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / cublasTester

Function cublasTester

tests/unittests/fp8_gemm_test/worker.cpp:207–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205// public API
206
207int32_t cublasTester(const ProblemDesc& p)
208{
209 // Initialize input A, B and D
210 // A: weight matrix, k * n
211 // B: input matrix, m * k
212 // D: output matrix, m * n
213 float* f_hevAPtr = new float[p.batch * p.k * p.n];
214 float* f_hevBPtr = new float[p.batch * p.m * p.k];
215 float* f_hevDPtr = new float[p.batch * p.m * p.n];
216 float* f_hevAPtr_trans = new float[p.batch * p.n * p.k]; // For TN GEMM, the weight should be transposed
217
218 // const float max_rand_num = 0.01f;
219 for (int b = 0; b < (int)p.batch; b++) {
220 for (int i = 0; i < (int)(p.k); i++) {
221 for (int j = 0; j < (int)(p.n); j++) {
222 // f_hevAPtr[i * p.n + j] = (random() % 1000) / (1000.f / max_rand_num) - (max_rand_num / 2);
223 // f_hevAPtr[i * p.n + j] = (random() % 1000) / 1000.f * 2.0f - 1.0f;
224 // f_hevAPtr[i * p.n + j] = pow(-1, random() % 2) * (1 << (random() % 8)) * ((random() % 4) * 0.25 + 1.f);
225 float exp_num = 1 << (random() % 8);
226 float man_num = random() % 4 * 0.25 + 1.f;
227 exp_num = random() % 2 == 0 ? exp_num * 1.0f : 1.0f / exp_num;
228 man_num = random() % 2 == 0 ? man_num : -1.0f * man_num;
229 f_hevAPtr[b * p.k * p.n + i * p.n + j] = exp_num * man_num;
230 f_hevAPtr_trans[b * p.k * p.n + j * p.k + i] = f_hevAPtr[b * p.k * p.n + i * p.n + j];
231 }
232 }
233 }
234
235 for (int i = 0; i < (int)(p.batch * p.m * p.k); i++) {
236 // f_hevBPtr[i] = (random() % 1000) / 1000.f * 2.0f - 1.0f;
237 f_hevBPtr[i] = 1.0f;
238 }
239 for (int i = 0; i < (int)(p.batch * p.m * p.n); i++) {
240 f_hevDPtr[i] = 0.0f;
241 }
242
243 // Baseline
244 for (int b = 0; b < (int)p.batch; b++) {
245 for (int i = 0; i < (int)p.m; i++) {
246 for (int j = 0; j < (int)p.n; j++) {
247 for (int k = 0; k < (int)p.k; k++) {
248 f_hevDPtr[b * p.m * p.n + i * p.n + j] =
249 f_hevDPtr[b * p.m * p.n + i * p.n + j] + f_hevBPtr[b * p.m * p.k + i * p.k + k] * p.bScale * f_hevAPtr[b * p.k * p.n + k * p.n + j] * p.aScale;
250 }
251 }
252 }
253 }
254
255 printf("[INFO] fp32 input: \n");
256 printMatrix(f_hevBPtr, p.m, p.k);
257 printf("[INFO] fp32 weight: \n");
258 printMatrix(f_hevAPtr, p.k, p.n);
259 printf("[INFO] fp32 output: \n");
260 printMatrix(f_hevDPtr, p.batch * p.m, p.n);
261
262 // Collect amax scalar
263 float* h_input_amax = new float(0.0f); // per tensor
264 float* h_output_scaling = new float[p.n];

Callers 1

mainFunction · 0.70

Calls 6

getAMaxFunction · 0.85
printMatrixFunction · 0.70
checkCudaStatusFunction · 0.70
checkCublasStatusFunction · 0.70
checkMatFunction · 0.70
freeResourcesFunction · 0.70

Tested by

no test coverage detected