StatMech
Loading...
Searching...
No Matches
Bit_Compare.cu File Reference

Functions

__global__ void Bit_gpu (Integer_t *dResPtr, Integer_t const LD, Integer_t const N, Integer_t const dloc, Integer_t const nTot)
 
int main (int argc, char **argv)
 

Function Documentation

◆ Bit_gpu()

__global__ void Bit_gpu ( Integer_t dResPtr,
Integer_t const  LD,
Integer_t const  N,
Integer_t const  dloc,
Integer_t const  nTot 
)
9 {
10 int idx = blockIdx.x*blockDim.x +threadIdx.x;
11 int idy = blockIdx.y*blockDim.y +threadIdx.y;
12
13 if(idx>=nTot || idy>=N) return;
14 dResPtr[idx+LD*idy] = Bit(idx, idy, dloc, N);
15}

◆ main()

int main ( int  argc,
char **  argv 
)
18 {
19 if(argc != 3) {
20 std::cerr << "Usage: Bit_Compare(Integer_t const N, Integer_t const dloc)" << std::endl;
21 std::exit(EX_USAGE);
22 }
23 Integer_t N = (Integer_t)std::atoi(argv[1]);
24 Integer_t dloc = (Integer_t)std::atoi(argv[2]);
25 Integer_t nTot = (Integer_t)std::pow(dloc, N);
26
27 magma_init();
28 magma_queue_t queue = NULL;
29 magma_int_t dev = 0;
30 magma_getdevice( &dev );
31 magma_queue_create( dev, &queue );
32
33 constexpr Integer_t GPU_UNIT = 32;
34 Integer_t const LDT = magma_roundup(nTot, GPU_UNIT);
35 matrix_gpu<Integer_t> dRes(LDT, N);
36
37 void (*funcPtr)(Integer_t*, Integer_t const, Integer_t const, Integer_t const, Integer_t const);
38 funcPtr = Bit_gpu;
39 struct cudaFuncAttributes attr; cudaFuncGetAttributes(&attr, funcPtr);
40 Integer_t nThread = (Integer_t)sqrt(attr.maxThreadsPerBlock);
42 if(nTot > nBlock*nThread) nBlock += 1;
43 GPUconfig conf(dim3(nBlock,nBlock,1), dim3(nThread,nThread,1),0,queue);
44 Bit_gpuMatrixElementsInSector<<<conf.dimGrid(),conf.dimBlock(),conf.shared(),conf.stream()>>>(dRes.ptr(), dRes.LD(), N, dloc, nTot);
45 cudaDeviceSynchronize();
46
47
48 matrix<Integer_t> Res(nTot, N);
49 magma_getmatrix(nTot, N, sizeof(Integer_t), dRes.ptr(), dRes.LD(), &*Res.begin(), nTot, queue);
50
51 bool flag;
52 for(Integer_t n = 0;n < nTot; ++n) {
53 flag = true;
54 for(Integer_t pos = 0;pos < N; ++pos) {
55 if(Res.at(n,pos) != Bit(n, pos, dloc, N)) { flag = false; break; };
56 }
57 if(flag == false) std::cerr << "Bit(" << n << ") != Bit_gpu" << std::endl;
58 else std::cerr << "(OK, n=" << n << ") Bit = Bit_gpu" << std::endl;
59 }
60
61
62
63
64 cudaDeviceSynchronize();
65 return 0;
66}
__global__ void Bit_gpu(Integer_t *dResPtr, Integer_t const LD, Integer_t const N, Integer_t const dloc, Integer_t const nTot)
Definition Bit_Compare.cu:9
Definition mytypes.hpp:272
struct cudaFuncAttributes attr
Definition getAttributesOfMatrixElementsInSector.cpp:2
Integer_t const nBlock
Definition getAttributesOfMatrixElementsInSector.cpp:5
Integer_t const nThread
Definition getAttributesOfMatrixElementsInSector.cpp:4
MKL_INT Integer_t
Definition mytypes.hpp:359