From b2edee4693113411e4e0207374048cebf6809547 Mon Sep 17 00:00:00 2001 From: Ronak Chauhan Date: Tue, 16 Jun 2020 02:49:12 -0400 Subject: [PATCH] Support passing macros to hipLaunchKernelGGL This makes hipLaunchKernelGGL take a variable argument list, that will be expanded before being fed to hipLaunchKernelGGLInternal. Change-Id: Id76e2bf91acd5d68f56a24fc39f219f2eeb06d33 [ROCm/hip commit: 961717879dfb46f15510d8c973ac0ab32f866f4e] --- .../hip/include/hip/hcc_detail/hip_runtime.h | 6 ++++-- .../hip/include/hip/nvcc_detail/hip_runtime.h | 6 ++++-- projects/hip/tests/src/kernel/hipLaunchParm.cpp | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/projects/hip/include/hip/hcc_detail/hip_runtime.h b/projects/hip/include/hip/hcc_detail/hip_runtime.h index 117af3e1fa..b022b8fcdb 100644 --- a/projects/hip/include/hip/hcc_detail/hip_runtime.h +++ b/projects/hip/include/hip/hcc_detail/hip_runtime.h @@ -435,10 +435,12 @@ void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks, hipLaunchKernel(k, numBlocks, dimBlocks, _Args, sharedMemBytes, stream); } #else -#define hipLaunchKernelGGL(kernelName, numblocks, numthreads, memperblock, streamId, ...) \ +#define hipLaunchKernelGGLInternal(kernelName, numBlocks, numThreads, memPerBlock, streamId, ...) \ do { \ - kernelName<<<(numblocks), (numthreads), (memperblock), (streamId)>>>(__VA_ARGS__); \ + kernelName<<<(numBlocks), (numThreads), (memPerBlock), (streamId)>>>(__VA_ARGS__); \ } while (0) + +#define hipLaunchKernelGGL(...) hipLaunchKernelGGLInternal(__VA_ARGS__) #endif #include diff --git a/projects/hip/include/hip/nvcc_detail/hip_runtime.h b/projects/hip/include/hip/nvcc_detail/hip_runtime.h index d159e116c0..8443e3eb2a 100644 --- a/projects/hip/include/hip/nvcc_detail/hip_runtime.h +++ b/projects/hip/include/hip/nvcc_detail/hip_runtime.h @@ -31,11 +31,13 @@ THE SOFTWARE. typedef int hipLaunchParm; -#define hipLaunchKernelGGL(kernelName, numblocks, numthreads, memperblock, streamId, ...) \ +#define hipLaunchKernelGGLInternal(kernelName, numBlocks, numThreads, memPerBlock, streamId, ...) \ do { \ - kernelName<<>>(__VA_ARGS__); \ + kernelName<<>>(__VA_ARGS__); \ } while (0) +#define hipLaunchKernelGGL(...) hipLaunchKernelGGLInternal(__VA_ARGS__) + #define hipReadModeElementType cudaReadModeElementType #ifdef __CUDA_ARCH__ diff --git a/projects/hip/tests/src/kernel/hipLaunchParm.cpp b/projects/hip/tests/src/kernel/hipLaunchParm.cpp index 797bc84ced..992ac5a18f 100644 --- a/projects/hip/tests/src/kernel/hipLaunchParm.cpp +++ b/projects/hip/tests/src/kernel/hipLaunchParm.cpp @@ -571,6 +571,10 @@ __global__ void hipLaunchKernelStructFunc21( __global__ void vAdd(float* a) {} +template +__global__ void myKernel(T1 a, T2 b) {} + + //--- // Some wrapper macro for testing: #define WRAP(...) __VA_ARGS__ @@ -913,6 +917,19 @@ int main() { hipLaunchKernelGGL(HIP_KERNEL_NAME(vAdd), dim3(1024), 1, 0, 0, Ad); hipLaunchKernelGGL(HIP_KERNEL_NAME(vAdd), dim3(1024), dim3(1), 0, 0, Ad); + // Test: Passing macro to hipLaunchKernelGGL +#define KERNEL_CONFIG dim3(1024), dim3(1), 0, 0 + hipLaunchKernelGGL(HIP_KERNEL_NAME(vAdd), KERNEL_CONFIG, Ad); + + // Test: Same thing with templates: + // Additional parenthesis required case of templates with multiple type paramters. + int a; + float b; + hipLaunchKernelGGL(HIP_KERNEL_NAME((myKernel)), KERNEL_CONFIG, a, b); + +#define TYPE_PARAM_CONFIG int, float + hipLaunchKernelGGL(HIP_KERNEL_NAME((myKernel)), KERNEL_CONFIG, a, b); + // Test: Passing hipLaunchKernelGGL inside another macro: float e0; MY_LAUNCH_MACRO(hipLaunchKernelGGL(vAdd, dim3(1024),