// smtest: checks every SM of a card. // All blocks compute the same deterministic chain (uint64 LCG, FP32 fma+sqrt, FP64 fma, shared memory); the result of // every thread of every block is compared with a reference computed on the CPU. There are 16 times more blocks than SMs, // so all SMs are loaded; a mismatch means a faulty SM. The speed per SM is measured as a side effect. // Build: nvcc -O2 -o smtest smtest.cu Run: smtest #include #include #include #include #include #include #include #include #define TPB 256 static inline uint64_t mixbits(uint64_t x, float f, double d){ uint32_t fb; uint64_t db; memcpy(&fb,&f,4); memcpy(&db,&d,8); return x ^ ((uint64_t)fb<<17) ^ db; } #define CHAIN(x,f,d,s) \ x = x*6364136223846793005ULL + 1442695040888963407ULL; x ^= x>>29; \ s = (uint32_t)x; x += s; \ f = fmaf(f, 1.0000001f, (float)(x&255)*1e-7f); f = sqrtf(fmaf(f, f, 1e-3f)); \ d = fma(d, 0.9999999, (double)(x&1023)*1e-9); __global__ void k(uint64_t* out, uint32_t iters, uint64_t seed){ __shared__ uint32_t sh[TPB]; uint32_t t = threadIdx.x; uint64_t x = seed + t*0x9E3779B97F4A7C15ULL; float f = 1.0f + t*1e-3f; double d = 1.0 + t*1e-6; for(uint32_t i=0;i1?atoi(argv[1]):0; double secs = argc>2?atof(argv[2]):30; uint32_t iters = 200000; if(cudaSetDevice(dev)!=cudaSuccess){puts("cudaSetDevice failed");return 2;} cudaDeviceProp p; cudaGetDeviceProperties(&p,dev); int sms = p.multiProcessorCount, blocks = sms*16; size_t n=(size_t)blocks*TPB; uint64_t* dout; cudaMalloc(&dout,n*8); std::vector h(n), ref(TPB); long launches=0, badblocks=0, badlaunch=0; bool refartifact=false; auto t0=std::chrono::steady_clock::now(); double el=0, gput=0; while(el>>(dout,iters,seed); cudaError_t e=cudaDeviceSynchronize(); if(e!=cudaSuccess){printf("dev %d CUDA error: %s\n",dev,cudaGetErrorString(e));return 3;} gput += std::chrono::duration(std::chrono::steady_clock::now()-a).count(); cudaMemcpy(h.data(),dout,n*8,cudaMemcpyDeviceToHost); long bb=0; for(int b=0;b(std::chrono::steady_clock::now()-t0).count(); } double rate = (double)launches*blocks*TPB*iters/gput/1e9; printf("dev %d %s SMs=%d: launches=%ld blocks/launch=%d bad_launches=%ld bad_blocks=%ld rate=%.2f Gstep/s per_SM=%.4f %s%s\n", dev,p.name,sms,launches,blocks,badlaunch,badblocks,rate,rate/sms,badblocks?"FAIL":"PASS",refartifact?" (CPU reference did not match, blocks compared with each other)":""); return badblocks?1:0; }