| 227 | std::map<Key, std::array<double, 3>> g_times; |
| 228 | |
| 229 | bool run_device(int dev, const K::NativeExpertExpdecParams& dev_params, int reps, int groups_req, |
| 230 | const std::vector<uint8_t>& pool, size_t P, size_t stride, const std::vector<float>& xh, |
| 231 | const K::NativeExpertLayout& L, const Pair& pair, const std::vector<Choice>& choices, |
| 232 | const std::vector<std::string>& shapes, long long& bad) { |
| 233 | if (!ck(cudaSetDevice(dev), "set device")) return false; |
| 234 | cudaDeviceProp pr{}; |
| 235 | cudaGetDeviceProperties(&pr, dev); |
| 236 | std::printf("# device %d: %s (sm_%d%d, %d SMs, L2 %d KB), %d reps x 5 rounds, <= %d groups, pool %d blobs x %.2f MB\n", dev, |
| 237 | pr.name, pr.major, pr.minor, pr.multiProcessorCount, pr.l2CacheSize / 1024, reps, groups_req, (int) P, |
| 238 | (double) L.bytes / 1e6); |
| 239 | int mclk_khz = 0, bus_bits = 0; |
| 240 | cudaDeviceGetAttribute(&mclk_khz, cudaDevAttrMemoryClockRate, dev); |
| 241 | cudaDeviceGetAttribute(&bus_bits, cudaDevAttrGlobalMemoryBusWidth, dev); |
| 242 | const double peak = 2.0 * (double) mclk_khz * 1e3 * (double) bus_bits / 8.0; // bytes / s |
| 243 | std::printf("# device %d peak DRAM bandwidth %.1f GB/s (memory clock %d kHz, bus %d bit)\n", dev, peak / 1e9, mclk_khz, bus_bits); |
| 244 | const int gmax = kMaxEntries; |
| 245 | DevMem mem; |
| 246 | auto* dpool = (uint8_t*) mem.alloc(pool.size()); |
| 247 | auto* dx = (float*) mem.alloc(xh.size() * sizeof(float)); |
| 248 | void* dxq = mem.alloc((size_t) kMaxT * kEmbd / 32 * 36); |
| 249 | void* dscr = mem.alloc(K::native_expert_scratch_bytes(kMaxEntries, kFf)); |
| 250 | auto* dout = (float*) mem.alloc((size_t) kMaxEntries * kEmbd * sizeof(float)); |
| 251 | auto* dptr = (unsigned long long*) mem.alloc(P * (size_t) gmax * sizeof(unsigned long long)); |
| 252 | auto* dstart = (int32_t*) mem.alloc((size_t) (gmax + 1) * sizeof(int32_t)); |
| 253 | auto* dn = (int32_t*) mem.alloc(sizeof(int32_t)); |
| 254 | auto* ddst = (int32_t*) mem.alloc((size_t) kMaxEntries * sizeof(int32_t)); |
| 255 | auto* dtok = (int32_t*) mem.alloc((size_t) kMaxEntries * sizeof(int32_t)); |
| 256 | if (!dpool || !dx || !dxq || !dscr || !dout || !dptr || !dstart || !dn || !ddst || !dtok) return false; |
| 257 | StreamEvents se; |
| 258 | if (!ck(cudaStreamCreate(&se.s), "stream") || !ck(cudaEventCreate(&se.a), "event") || |
| 259 | !ck(cudaEventCreate(&se.b), "event")) |
| 260 | return false; |
| 261 | void* stream = (void*) se.s; |
| 262 | if (!ck(cudaMemcpy(dpool, pool.data(), pool.size(), cudaMemcpyHostToDevice), "copy pool") || |
| 263 | !ck(cudaMemcpy(dx, xh.data(), xh.size() * sizeof(float), cudaMemcpyHostToDevice), "copy x")) |
| 264 | return false; |
| 265 | K::quantize_q8_1_rows(dx, kMaxT, kEmbd, dxq, stream); |
| 266 | if (!ck(cudaStreamSynchronize(se.s), "quantize")) return false; |
| 267 | |
| 268 | std::mt19937 rng(20261012u); |
| 269 | bool ok = true; |
| 270 | for (int T = 1; T <= kMaxT && ok; ++T) { |
| 271 | for (const std::string& shape : shapes) { |
| 272 | if (!ok) break; |
| 273 | const Window w = shape == "single" ? build_single(T) : build_real(T, groups_req, rng); |
| 274 | const int G = w.groups, NE = w.entries; |
| 275 | // call i reads G experts starting at blob (i * G) % P: a fresh set until the pool wraps (>= 96 MB later) |
| 276 | std::vector<unsigned long long> hp(P * (size_t) G); |
| 277 | for (size_t i = 0; i < P; ++i) |
| 278 | for (int g = 0; g < G; ++g) |
| 279 | hp[i * (size_t) G + (size_t) g] = (unsigned long long) (dpool + ((i * (size_t) G + (size_t) g) % P) * stride); |
| 280 | ok = ck(cudaMemcpy(dptr, hp.data(), hp.size() * sizeof(unsigned long long), cudaMemcpyHostToDevice), "copy ptrs") && |
| 281 | ck(cudaMemcpy(dstart, w.start.data(), w.start.size() * sizeof(int32_t), cudaMemcpyHostToDevice), "copy start") && |
| 282 | ck(cudaMemcpy(dn, &G, sizeof(int32_t), cudaMemcpyHostToDevice), "copy n") && |
| 283 | ck(cudaMemcpy(ddst, w.dst.data(), w.dst.size() * sizeof(int32_t), cudaMemcpyHostToDevice), "copy dst") && |
| 284 | ck(cudaMemcpy(dtok, w.tok.data(), w.tok.size() * sizeof(int32_t), cudaMemcpyHostToDevice), "copy tok"); |
| 285 | if (!ok) break; |
| 286 | std::printf("# T=%d %s: %d groups, %d entries, %.1f MB of weights per call\n", T, shape.c_str(), G, NE, |
no test coverage detected