#ifndef HIPSTREAM_H #define HIPSTREAM_H #include #define NUM_STREAMS 4 /* * H2H - 1 * H2D - 2 * KER - 3 * D2D - 4 * D2H - 5 */ template void H2HAsync(T *Dst, T *Src, size_t size, hipStream_t stream){ HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyHostToHost, stream)); } template void H2DAsync(T *Dst, T *Src, size_t size, hipStream_t stream){ HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyHostToDevice, stream)); } template void D2DAsync(T *Dst, T *Src, size_t size, hipStream_t stream){ HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyDeviceToDevice, stream)); } template void D2HAsync(T *Dst, T *Src, size_t size, hipStream_t stream){ HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyDeviceToHost, stream)); } template void H2H(T *Dst, T *Src, size_t size){ HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyHostToHost)); } template void H2D(T *Dst, T *Src, size_t size){ HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyHostToDevice)); } template void D2D(T *Dst, T *Src, size_t size){ HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyDeviceToDevice)); } template void D2H(T *Dst, T *Src, size_t size){ HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyDeviceToHost)); } template __global__ void Inc(hipLaunchParm lp, T *In){ int tx = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x; In[tx] = In[tx] + 1; } template void initArrays(T **Ad, T **Ah, size_t N, bool usePinnedHost=false){ size_t NBytes = N * sizeof(T); if(Ad){ HIPCHECK( hipMalloc(Ad, NBytes)); } if(usePinnedHost){ HIPCHECK( hipMallocHost(Ah, NBytes)); } else{ *Ah = new T[N]; HIPASSERT(*Ah != NULL); } } template void initArrays(T **Ad, size_t N, bool deviceMemory = false, bool usePinnedHost = false){ size_t NBytes = N * sizeof(T); if(deviceMemory){ HIPCHECK( hipMalloc(Ad, NBytes)); }else{ if(usePinnedHost){ HIPCHECK(hipMallocHost(Ad, NBytes)); }else{ *Ad = new T[N]; HIPASSERT(*Ad != NULL); } } } template void setArray(T* Array, int N, T val){ for(int i=0;i