MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / main

Function main

pocs/vdot/vdot.cpp:222–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222int main(int argc, char** argv) {
223
224 int nloop = argc > 1 ? atoi(argv[1]) : 10;
225 bool scalar = argc > 2 ? atoi(argv[2]) : false;
226 bool useQ4_1 = argc > 3 ? atoi(argv[3]) : false;
227
228 if (scalar && useQ4_1) {
229 printf("It is not possible to use Q4_1 quantization and scalar implementations\n");
230 return 1;
231 }
232
233 std::mt19937 rndm(1234);
234
235 std::vector<float> x1(kVecSize), y1(kVecSize);
236 int n4 = useQ4_1 ? kVecSize / QK4_1 : kVecSize / QK4_0; n4 = 64*((n4 + 63)/64);
237 int n8 = kVecSize / QK8_0; n8 = 64*((n8 + 63)/64);
238
239 auto funcs = useQ4_1 ? ggml_internal_get_type_traits(GGML_TYPE_Q4_1) : ggml_internal_get_type_traits(GGML_TYPE_Q4_0);
240
241 std::vector<block_q4_0> q40;
242 std::vector<block_q4_1> q41;
243 if (useQ4_1) q41.resize(n4);
244 else q40.resize(n4);
245 std::vector<block_q8_0> q8(n8);
246 std::vector<int64_t> H(16, 0);
247 double sumt = 0, sumt2 = 0, maxt = 0;
248 double sumqt = 0, sumqt2 = 0, maxqt = 0;
249 double sum = 0, sumq = 0, exactSum = 0;
250 for (int iloop=0; iloop<nloop; ++iloop) {
251
252 // Fill vector x with random numbers
253 fillRandomGaussianFloats(x1, rndm);
254
255 // Fill vector y with random numbers
256 fillRandomGaussianFloats(y1, rndm);
257
258 // Compute the exact dot product
259 for (int k=0; k<kVecSize; ++k) exactSum += x1[k]*y1[k];
260
261 // quantize x.
262 // Note, we do not include this in the timing as in practical application
263 // we already have the quantized model weights.
264 if (useQ4_1) {
265 funcs.from_float(x1.data(), q41.data(), kVecSize);
266 } else {
267 funcs.from_float(x1.data(), q40.data(), kVecSize);
268 }
269
270 // Now measure time the dot product needs using the "scalar" version above
271 auto t1 = std::chrono::high_resolution_clock::now();
272 if (useQ4_1) sum += dot41(kVecSize / QK4_1, q41.data(), y1.data());
273 else sum += dot(kVecSize / QK4_0, q40.data(), y1.data());
274 auto t2 = std::chrono::high_resolution_clock::now();
275 auto t = 1e-3*std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count();
276 sumt += t; sumt2 += t*t; maxt = std::max(maxt, t);
277
278 // And now measure the time needed to quantize y and perform the dot product with the quantized y
279 t1 = std::chrono::high_resolution_clock::now();

Callers

nothing calls this directly

Calls 12

printfFunction · 0.85
maxFunction · 0.85
sqrtFunction · 0.85
fillRandomGaussianFloatsFunction · 0.70
dot41Function · 0.70
dotFunction · 0.70
dot_q4_q8Function · 0.70
resizeMethod · 0.45
dataMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected