<<< , >>> <div><br /></div> <div><br /> <div>=== 보다 생각이 나서 적어 봅니다 ㅋ</div> <div>cuda의 확장된 개념으로 사용되는 문법입니다.</div> <div><br /></div> <div><br /></div> <div><br /></div> <div><div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial">void <font color="#801fbf" style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: 돋움, Dotum, AppleGothic, sans-serif"><b style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3">MatMul</b></font>(const Matrix A, const Matrix B, Matrix C) </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial">{ </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> // Load A and B to device memory </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> Matrix d_A; </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> d_A.width = A.width; d_A.height = A.height; </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> size_t size = A.width * A.height * sizeof(float); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMalloc(&d_A.elements, size); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMemcpy(d_A.elements, A.elements, size, </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMemcpyHostToDevice); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> Matrix d_B; </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> d_B.width = B.width; d_B.height = B.height; </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> size = B.width * B.height * sizeof(float); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMalloc(&d_B.elements, size); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMemcpy(d_B.elements, B.elements, size, </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMemcpyHostToDevice); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> // Allocate C in device memory </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> Matrix d_C; </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> d_C.width = C.width; d_C.height = C.height; </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> size = C.width * C.height * sizeof(float); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMalloc(&d_C.elements, size); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> // Invoke kernel </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> dim3 dimGrid(B.width / dimBlock.x, A.height / dimBlock.y); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"><font color="#8a8a8a"> MatMulKernel</font><font color="#ff0000"><b><<<dimgrid, dimblock="">>></dimgrid,></b></font><font color="#8a8a8a">(d_A, d_B, d_C); </font></span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> // Read C from device memory </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMemcpy(C.elements, Cd.elements, size, </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaMemcpyDeviceToHost); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> // Free device memory </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaFree(d_A.elements); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaFree(d_B.elements); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial"> cudaFree(d_C.elements); </span></span></div> <div style="margin: 0px; padding: 0px; border: 0px; line-height: 15px; font-family: 돋움, Dotum, AppleGothic, sans-serif; color: #8a8a8a"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-size: 8pt"><span style="margin: 0px; padding: 0px; border: 0px; line-height: 1.3; font-family: Arial">} </span></span></div></div></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.