okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c71d0be50
main
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 ) { 7if (error != cudaSuccess ) { 8 std::fprintf (stderr ,"%s\n" ,cudaGetErrorString (error )); 9 std::exit (1 ); 10 } 11} 12 13int main () { 14int devices = 0 ; 15check (cudaGetDeviceCount (& devices )); 16if (devices < 2 ) { 17 std::puts ("requires two CUDA devices" ); 18return 77 ; 19 } 20using strata::core::latent_shared_d ; 21using strata::core::latent_shared_u ; 22uint8_t d [2 ]{},u [2 ]{}; 23for (int device = 0 ;device < 2 ;++ device ) { 24check (cudaSetDevice (device )); 25if (latent_shared_d ()!= nullptr || latent_shared_u ()!= nullptr ) { 26 std::fprintf (stderr ,"device %d inherited another device's tables\n" ,device ); 27return 1 ; 28 } 29latent_shared_d ()= & d [device ]; 30latent_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 } 34for (int device = 0 ;device < 2 ;++ device ) { 35check (cudaSetDevice (device )); 36const auto & shared = strata::core::latent_shared (); 37if (latent_shared_d ()!= & d [device ]|| latent_shared_u ()!= & u [device ]|| 38shared .first_layer != device * 16 || shared .end_layer != (device == 0 ?16 :48 )) { 39 std::fprintf (stderr ,"device %d lost its D/U pointers\n" ,device ); 40return 1 ; 41 } 42 strata::core::latent_shared ()= {}; 43 } 44 std::puts ("latent D/U sharing is device-local" ); 45}