okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

waveringanatrim shared latent projections to each gpu stagec71d0be50

main
1.6 KiB45 linesraw
1#include <cuda_runtime.h>
2#include "strata/core/latent_share.hpp"
3#include <cstdio>
4#include <cstdlib>
5
6static void check(cudaError_t error) {
7    if (error != cudaSuccess) {
8        std::fprintf(stderr, "%s\n", cudaGetErrorString(error));
9        std::exit(1);
10    }
11}
12
13int main() {
14    int devices = 0;
15    check(cudaGetDeviceCount(&devices));
16    if (devices < 2) {
17        std::puts("requires two CUDA devices");
18        return 77;
19    }
20    using strata::core::latent_shared_d;
21    using strata::core::latent_shared_u;
22    uint8_t d[2]{}, u[2]{};
23    for (int device = 0; device < 2; ++device) {
24        check(cudaSetDevice(device));
25        if (latent_shared_d() != nullptr || latent_shared_u() != nullptr) {
26            std::fprintf(stderr, "device %d inherited another device's tables\n", device);
27            return 1;
28        }
29        latent_shared_d() = &d[device];
30        latent_shared_u() = &u[device];
31        strata::core::latent_shared().first_layer = device * 16;
32        strata::core::latent_shared().end_layer = device == 0 ? 16 : 48;
33    }
34    for (int device = 0; device < 2; ++device) {
35        check(cudaSetDevice(device));
36        const auto& shared = strata::core::latent_shared();
37        if (latent_shared_d() != &d[device] || latent_shared_u() != &u[device] ||
38            shared.first_layer != device * 16 || shared.end_layer != (device == 0 ? 16 : 48)) {
39            std::fprintf(stderr, "device %d lost its D/U pointers\n", device);
40            return 1;
41        }
42        strata::core::latent_shared() = {};
43    }
44    std::puts("latent D/U sharing is device-local");
45}