#include #include #include #include #include #include #include using B=uint8_t; #define C(x) do{auto e=(x);if(e){fprintf(stderr,"%s at %d\n",cudaGetErrorString(e),__LINE__);exit(2);}}while(0) struct Meta{int h,w,a,b,k,reachable;}; struct Case {Meta m;std::vector g,expect;}; #define bit(x,n) (((x)>>(n))&1) __global__ void step(const Meta* meta,const B* grid,const B* src,B* dst,int* alive,int stride) { int i=blockIdx.x*blockDim.x+threadIdx.x, lane=blockIdx.y; const Meta M=meta[lane]; if(i>=M.h*M.w)return; int j=i+lane*stride,y=i/M.w,x=i%M.w; int a0=y?src[j-M.w]:0, a1=x+1 cases(count);int stride=0; for(auto &z:cases){f.read((char*)&z.m,sizeof(Meta));int n=z.m.h*z.m.w;if(!f||n<1||n>11000)return 3;stride=std::max(stride,n);z.g.resize(n);z.expect.resize(n);f.read((char*)z.g.data(),n);f.read((char*)z.expect.data(),n);} if(!f)return 3; B *a,*b,*grid;Meta* meta;int* alive;size_t bytes=2*stride; C(cudaMalloc(&a,bytes));C(cudaMalloc(&b,bytes));C(cudaMalloc(&grid,bytes));C(cudaMalloc(&meta,2*sizeof(Meta)));C(cudaMalloc(&alive,sizeof(int))); for(int lanes: {1,2}){ std::vector samples;int checks=0;int launched=0; for(int trial=0;trial<6;trial++){ double sec=0;checks=0;launched=0; for(int k=0;k init(m*stride,0),g(m*stride,0),out(m*stride,0);Meta d[2]; for(int l=0;l>>(meta,grid,a,b,alive,stride); std::swap(a,b);rounds++; } C(cudaGetLastError()); C(cudaMemcpy(&act,alive,sizeof(int),cudaMemcpyDeviceToHost)); } if(act)return 5; C(cudaMemcpy(out.data(),a,m*stride,cudaMemcpyDeviceToHost)); sec+=std::chrono::duration(std::chrono::steady_clock::now()-begin).count();launched+=rounds; for(int l=0;l