Merge pull request #465 from gargrahul/optimize_memcpy2d
Optimize memcpy2D kernel use
Šī revīzija ir iekļauta:
@@ -1495,10 +1495,16 @@ __global__ void hip_copy2d_n(T* dst, const T* src, size_t width, size_t height,
|
||||
|
||||
size_t idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
size_t idy = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
if((idx < width) && (idy < height)){
|
||||
T *dstPtr = (T *)((uint8_t*) dst + idy * destPitch);
|
||||
T *srcPtr = (T *)((uint8_t*) src + idy * srcPitch);
|
||||
size_t floorWidth = (width/sizeof(T));
|
||||
T *dstPtr = (T *)((uint8_t*) dst + idy * destPitch);
|
||||
T *srcPtr = (T *)((uint8_t*) src + idy * srcPitch);
|
||||
if((idx < floorWidth) && (idy < height)){
|
||||
dstPtr[idx] = srcPtr[idx];
|
||||
} else if((idx < width) && (idy < height)){
|
||||
size_t bytesToCopy = width - (floorWidth * sizeof(T));
|
||||
dstPtr += floorWidth;
|
||||
srcPtr += floorWidth;
|
||||
__builtin_memcpy(reinterpret_cast<uint8_t*>(dstPtr), reinterpret_cast<const uint8_t*>(srcPtr),bytesToCopy);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
@@ -1515,10 +1521,11 @@ void ihipMemsetKernel(hipStream_t stream, T* ptr, T val, size_t sizeBytes) {
|
||||
|
||||
template <typename T>
|
||||
void ihipMemcpy2dKernel(hipStream_t stream, T* dst, const T* src, size_t width, size_t height, size_t destPitch, size_t srcPitch) {
|
||||
size_t threadsPerBlock = 16;
|
||||
uint32_t grid_dim_x = clamp_integer<size_t>( (width+(threadsPerBlock-1)) / threadsPerBlock, 1, UINT32_MAX);
|
||||
uint32_t grid_dim_y = clamp_integer<size_t>( (height+(threadsPerBlock-1)) / threadsPerBlock, 1, UINT32_MAX);
|
||||
hipLaunchKernelGGL(hip_copy2d_n, dim3(grid_dim_x,grid_dim_y), dim3(threadsPerBlock,threadsPerBlock), 0u, stream, dst, src,
|
||||
size_t threadsPerBlock_x = 64;
|
||||
size_t threadsPerBlock_y = 4;
|
||||
uint32_t grid_dim_x = clamp_integer<size_t>( (width+(threadsPerBlock_x*sizeof(T)-1)) / (threadsPerBlock_x*sizeof(T)), 1, UINT32_MAX);
|
||||
uint32_t grid_dim_y = clamp_integer<size_t>( (height+(threadsPerBlock_y-1)) / threadsPerBlock_y, 1, UINT32_MAX);
|
||||
hipLaunchKernelGGL(hip_copy2d_n, dim3(grid_dim_x,grid_dim_y), dim3(threadsPerBlock_x,threadsPerBlock_y), 0u, stream, dst, src,
|
||||
width, height, destPitch, srcPitch);
|
||||
}
|
||||
|
||||
@@ -1622,7 +1629,7 @@ hipError_t ihipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch
|
||||
stream->locked_copySync((unsigned char*)dst + i * dpitch,
|
||||
(unsigned char*)src + i * spitch, width, kind);
|
||||
} else {
|
||||
ihipMemcpy2dKernel<uint8_t> (stream, static_cast<uint8_t*> (dst), static_cast<const uint8_t*> (src), width, height, dpitch, spitch);
|
||||
ihipMemcpy2dKernel<uint32_t> (stream, static_cast<uint32_t*> (dst), static_cast<const uint32_t*> (src), width, height, dpitch, spitch);
|
||||
stream->locked_wait();
|
||||
}
|
||||
} catch (ihipException& ex) {
|
||||
@@ -1661,7 +1668,7 @@ hipError_t hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t sp
|
||||
e = hip_internal::memcpyAsync((unsigned char*)dst + i * dpitch,
|
||||
(unsigned char*)src + i * spitch, width, kind, stream);
|
||||
} else{
|
||||
ihipMemcpy2dKernel<uint8_t> (stream, static_cast<uint8_t*> (dst), static_cast<const uint8_t*> (src), width, height, dpitch, spitch);
|
||||
ihipMemcpy2dKernel<uint32_t> (stream, static_cast<uint32_t*> (dst), static_cast<const uint32_t*> (src), width, height, dpitch, spitch);
|
||||
}
|
||||
} catch (ihipException& ex) {
|
||||
e = ex._code;
|
||||
|
||||
Atsaukties uz šo jaunā problēmā
Block a user