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

Function main

pocs/vdot/q8dot.cpp:121–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119
120
121int main(int argc, char** argv) {
122
123 int nloop = argc > 1 ? atoi(argv[1]) : 10;
124 int type = argc > 2 ? atoi(argv[2]) : 1;
125
126 std::mt19937 rndm(1234);
127
128 std::vector<block_q4_1> x41;
129 std::vector<block_q4_0> x40;
130 std::vector<block_q8_0> y(kVecSize);
131 if (type == 0) x40.resize(kVecSize);
132 else {
133 x41.resize(kVecSize);
134 for (auto& b : x41) b.m = 1;
135 }
136
137 auto ggml_type = type == 0 ? GGML_TYPE_Q4_0 : GGML_TYPE_Q4_1;
138
139 auto funcs = ggml_internal_get_type_traits(ggml_type);
140
141 Stat simple, ggml;
142
143 for (int iloop=0; iloop<nloop; ++iloop) {
144
145 if (type == 0) fillQ4blocks(x40, rndm);
146 else fillQ4blocks(x41, rndm);
147 fillQ80blocks(y, rndm);
148
149 auto t1 = std::chrono::high_resolution_clock::now();
150 double s = 0;
151 if (type == 0) for (int i=0; i<kVecSize; ++i) s += simpleDot(x40[i], y[i]);
152 else for (int i=0; i<kVecSize; ++i) s += simpleDot(x41[i], y[i]);
153 auto t2 = std::chrono::high_resolution_clock::now();
154 auto t = 1e-3*std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count();
155 if (iloop > 3) simple.addResult(s, t);
156
157 t1 = std::chrono::high_resolution_clock::now();
158 float fs;
159 if (type == 0) funcs.vec_dot(kVecSize * QK4_1, &fs, x40.data(), y.data());
160 else funcs.vec_dot(kVecSize * QK4_1, &fs, x41.data(), y.data());
161 t2 = std::chrono::high_resolution_clock::now();
162 t = 1e-3*std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count();
163 if (iloop > 3) ggml.addResult(fs, t);
164
165 }
166
167 // Report the time (and the average of the dot products so the compiler does not come up with the idea
168 // of optimizing away the function calls after figuring that the result is not used).
169 simple.reportResult("Simple");
170 ggml.reportResult("ggml");
171 return 0;
172}

Callers

nothing calls this directly

Calls 9

fillQ4blocksFunction · 0.70
fillQ80blocksFunction · 0.70
simpleDotFunction · 0.70
resizeMethod · 0.45
countMethod · 0.45
addResultMethod · 0.45
dataMethod · 0.45
reportResultMethod · 0.45

Tested by

no test coverage detected