From ff4621af4ece46360a2388a0e36ff8a959470af2 Mon Sep 17 00:00:00 2001 From: Siu Chi Chan Date: Wed, 15 Mar 2017 12:26:13 -0400 Subject: [PATCH 01/56] replace code names with gfx names Change-Id: I5e0b96a0b474b16cfa92077a30a5b80b7230254b [ROCm/clr commit: c6efbc1f258e62ac857bf1b4e549c23105bc93fd] --- projects/clr/hipamd/bin/hccgenco.sh | 7 ++++--- projects/clr/hipamd/bin/hipcc | 2 +- projects/clr/hipamd/docs/markdown/hip_kernel_language.md | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/projects/clr/hipamd/bin/hccgenco.sh b/projects/clr/hipamd/bin/hccgenco.sh index a7b4177624..7f90cce83d 100755 --- a/projects/clr/hipamd/bin/hccgenco.sh +++ b/projects/clr/hipamd/bin/hccgenco.sh @@ -10,7 +10,7 @@ if [ $# = 0 ]; then fi : ${ROCM_PATH:=/opt/rocm} -: ${ROCM_TARGET:=fiji} +: ${ROCM_TARGET:=gfx803} INPUT_FILES="" OUTPUT_FILE="" @@ -48,13 +48,14 @@ printf "\nint main(){}\n" >> $hipgenisa_main $HIP_PATH/bin/hipcc $hipgenisa_files -o $hipgenisa_dir/a.out mv dump* $hipgenisa_dir +hsaco_file="dump-$ROCM_TARGET.hsaco" map_sym="" -kernels=$(objdump -t $hipgenisa_dir/dump-fiji.hsaco | grep grid_launch_parm | sed 's/ \+/ /g; s/\t/ /g' | cut -d" " -f6) +kernels=$(objdump -t $hipgenisa_dir/$hsaco_file | grep grid_launch_parm | sed 's/ \+/ /g; s/\t/ /g' | cut -d" " -f6) for mangled_sym in $kernels; do real_sym=$(c++filt $(c++filt $mangled_sym | cut -d: -f3 | sed 's/_functor//g') | cut -d\( -f1) map_sym="--redefine-sym $mangled_sym=$real_sym $map_sym" done -objcopy -F elf64-little $map_sym $hipgenisa_dir/dump-fiji.hsaco $OUTPUT_FILE +objcopy -F elf64-little $map_sym $hipgenisa_dir/$hsaco_file $OUTPUT_FILE rm $hipgenisa_files rm -r $hipgenisa_dir diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index 381c774c94..361517d551 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/bin/hipcc @@ -92,7 +92,7 @@ if ($HIP_PLATFORM eq "hcc") { $HIP_ATP_MARKER=$ENV{'HIP_ATP_MARKER'} // 1; $marker_path = "$ROCM_PATH/profiler/CXLActivityLogger"; - $ROCM_TARGET=$ENV{'ROCM_TARGET'} // "fiji"; + $ROCM_TARGET=$ENV{'ROCM_TARGET'} // "gfx803"; # HCC* may be used to compile src/hip_hcc.o (and also feed the HIPCXXFLAGS below) $HCC = "$HCC_HOME/bin/hcc"; diff --git a/projects/clr/hipamd/docs/markdown/hip_kernel_language.md b/projects/clr/hipamd/docs/markdown/hip_kernel_language.md index 3fd4ea9aca..0c7f3c8d25 100644 --- a/projects/clr/hipamd/docs/markdown/hip_kernel_language.md +++ b/projects/clr/hipamd/docs/markdown/hip_kernel_language.md @@ -680,7 +680,7 @@ The user can specify the target for which the binary can be generated. HIP/HCC d The file format for binary is `.co` which means Code Object. The following command builds the code object using `hipcc`. `hipcc --genco --target-isa=[TARGET GPU] [INPUT FILE] -o [OUTPUT FILE]` -```[TARGET GPU] = fiji/hawaii +```[TARGET GPU] = gfx803/gfx701 [INPUT FILE] = Name of the file containing kernels [OUTPUT FILE] = Name of the generated code object file``` From 151612e1848c0a93c680149f35cda21f4ae20649 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Thu, 16 Mar 2017 14:39:28 +0300 Subject: [PATCH 02/56] [HIP] [DOC] Update hip_porting_driver_api.md + Fix typos, formatting, update CUDA Driver API support. [ROCm/clr commit: c6de5b92b55de7202ef4cb8cfdf82c797f1e7bbc] --- .../docs/markdown/hip_porting_driver_api.md | 147 +++++++----------- 1 file changed, 57 insertions(+), 90 deletions(-) diff --git a/projects/clr/hipamd/docs/markdown/hip_porting_driver_api.md b/projects/clr/hipamd/docs/markdown/hip_porting_driver_api.md index f51f53a092..dd3b9c3e86 100644 --- a/projects/clr/hipamd/docs/markdown/hip_porting_driver_api.md +++ b/projects/clr/hipamd/docs/markdown/hip_porting_driver_api.md @@ -1,151 +1,119 @@ # Porting CUDA Driver API ## Introduction to the CUDA Driver and Runtime APIs -CUDA provides a separate CUDA Driver and Runtime APIs. The two APIs have significant overlap in functionality: +CUDA provides a separate CUDA Driver and Runtime APIs. The two APIs have significant overlap in functionality: - Both APIs support events, streams, memory management, memory copy, and error handling. -- Both APIs deliver similar performance. -- Driver APIs calls begin with the prefix `cu` while Runtime APIs begin with the prefix `cuda`. For example, the Driver API API contains `cuEventCreate` while the Runtime API contains `cudaEventCreate`, with similar functionality. -- The Driver API defines a different but largely overlapping error code code space than the Runtime API, and uses a different coding convention. For example, Driver API defines `CUDA_ERROR_INVALID_VALUE` while the Runtime API defines `cudaErrorInvalidValue` +- Both APIs deliver similar performance. +- Driver APIs calls begin with the prefix `cu` while Runtime APIs begin with the prefix `cuda`. For example, the Driver API API contains `cuEventCreate` while the Runtime API contains `cudaEventCreate`, with similar functionality. +- The Driver API defines a different but largely overlapping error code space than the Runtime API, and uses a different coding convention. For example, Driver API defines `CUDA_ERROR_INVALID_VALUE` while the Runtime API defines `cudaErrorInvalidValue` The Driver API offers two additional pieces of functionality not provided by the Runtime API: cuModule and cuCtx APIs. ### cuModule API -The Module section of the Driver API provides additional control over how and when accelerator - code objects are loaded. +The Module section of the Driver API provides additional control over how and when accelerator code objects are loaded. For example, the driver API allows code objects to be loaded from files or memory pointers. Symbols for kernels or global data can be extracted from the loaded code objects. -In contrast, the Runtime API automatically loads and (if necessary) compiles all of the -kernels from a executable binary when run. +In contrast, the Runtime API automatically loads and (if necessary) compiles all of the kernels from an executable binary when run. In this mode, NVCC must be used to compile kernel code so the automatic loading can function correctly. Both Driver and Runtime APIs define a function for launching kernels (called `cuLaunchKernel` or `cudaLaunchKernel`. The kernel arguments and the execution configuration (grid dimensions, group dimensions, dynamic shared memory, and stream) are passed as arguments to the launch function. -The Runtime additionally provides the `<<< >>>` syntax for launching kernels, which resembles -a special function call and is easier to use than explicit launch API (in particular with respect to -handling of kernel arguments). -However, this syntax is not standard C++ and is available only when NVCC is used to compile the host code. +The Runtime additionally provides the `<<< >>>` syntax for launching kernels, which resembles a special function call and is easier to use than explicit launch API (in particular with respect to handling of kernel arguments). +However, this syntax is not standard C++ and is available only when NVCC is used to compile the host code. -The Module features are useful in an environment which generate the code objects directly, such as a new -accelerator language front-end. Here, NVCC is not used. Instead, the environment may have a -different kernel language or different compilation flow. +The Module features are useful in an environment which generates the code objects directly, such as a new accelerator language front-end. +Here, NVCC is not used. Instead, the environment may have a different kernel language or different compilation flow. Other environments have many kernels and do not want them to be all loaded automatically. The Module functions can be used to load the generated code objects and launch kernels. -As we will see below, HIP defines a Module API which provides similar explicit control over code -object management. +As we will see below, HIP defines a Module API which provides similar explicit control over code object management. ### cuCtx API -The Driver API defines "Context" and "Devices" as separate entities. -Contexts contain a single device, and a device can theoretically have multiple contexts. -Each context contains a set of streams and events specific to the context. -Historically contexts also defined a unique address space for the GPU, though this may not longer be the case in Unified Memory platforms (since the CPU and all the devices in the same process share a single unified address space). -The Context APIs also provide a mechanism to switch between devices, which allowed -a single CPU thread to send commands to different GPUs. HIP as well as a recent versions -of CUDA Runtime provide other mechanisms to accomplish this feat - for example using streams or -`cudaSetDevice`. +The Driver API defines "Context" and "Devices" as separate entities. +Contexts contain a single device, and a device can theoretically have multiple contexts. +Each context contains a set of streams and events specific to the context. +Historically contexts also defined a unique address space for the GPU, though this may no longer be the case in Unified Memory platforms (since the CPU and all the devices in the same process share a single unified address space). +The Context APIs also provide a mechanism to switch between devices, which allowed a single CPU thread to send commands to different GPUs. +HIP as well as a recent versions of CUDA Runtime provide other mechanisms to accomplish this feat - for example using streams or `cudaSetDevice`. -The CUDA Runtime API unifies the Context API with the Device API. This simplifies the APIs -and has little loss of functionality since each Context can contain a single device, -and the benefits of multiple contexts has been replaced with other interfaces. HIP provides -a context API to facilitate easy porting from existing Driver codes. -In HIP, the Ctx functions largely provide an alternate syntax for changing the active device. +The CUDA Runtime API unifies the Context API with the Device API. This simplifies the APIs and has little loss of functionality since each Context can contain a single device, and the benefits of multiple contexts has been replaced with other interfaces. +HIP provides a context API to facilitate easy porting from existing Driver codes. +In HIP, the Ctx functions largely provide an alternate syntax for changing the active device. Most new applications will prefer to use `hipSetDevice` or the stream APIs. ## HIP Module and Ctx APIs -Rather than present two separate APIs, HIP extends the HIP API with new APIs for Modules -and Ctx control. +Rather than present two separate APIs, HIP extends the HIP API with new APIs for Modules and Ctx control. ### hipModule API -Like the CUDA Driver API, the Module API provides additional control -over how code is loaded, including options to load code from files or from in-memory pointers. -NVCC and HCC target different architectures and use different code object formats : NVCC -is `cubin` or `ptx` files, while the HCC path is the `hsaco` format. The external -compilers which generate these code objects are responsible for generating and loading -the correct code object for each platform. Notably, there is not a fat binary format that -can contain code for both NVCC and HCC platforms. The following table summarizes the -formats used on each platform: +Like the CUDA Driver API, the Module API provides additional control over how code is loaded, including options to load code from files or from in-memory pointers. +NVCC and HCC target different architectures and use different code object formats: NVCC is `cubin` or `ptx` files, while the HCC path is the `hsaco` format. +The external compilers which generate these code objects are responsible for generating and loading the correct code object for each platform. +Notably, there is not a fat binary format that can contain code for both NVCC and HCC platforms. The following table summarizes the formats used on each platform: -| Format | APIs | NVCC | HCC | -| --- | --- | --- | --- | +| Format | APIs | NVCC | HCC | +| --- | --- | --- | --- | | Code Object | hipModuleLoad, hipModuleLoadData | .cubin or PTX text | .hsaco | -| Fat Binary | hipModuleLoadFatBin | .fatbin | Under Development | +| Fat Binary | hipModuleLoadFatBin | .fatbin | Under Development | -hipcc uses NVCC and HCC to compile host codes. Both of these may embed code objects -into the final executable, and these code objects will be automatically loaded when -the application starts. -The hipModule API can be used to load additional code objects, and in this way -provides an extended capability to the automatically loaded code objects. HCC allows -both of these capabilities to be used together, if desired. Of course it is possible -to create a program with no kernels and thus no automatic loading. +`hipcc` uses NVCC and HCC to compile host codes. Both of these may embed code objects into the final executable, and these code objects will be automatically loaded when the application starts. +The hipModule API can be used to load additional code objects, and in this way provides an extended capability to the automatically loaded code objects. +HCC allows both of these capabilities to be used together, if desired. Of course it is possible to create a program with no kernels and thus no automatic loading. ### hipCtx API -HIP provides a `Ctx` API as a thin layer over the existing Device functions. This Ctx API -can be used to set the current context, or to query properties of the device associated with -the context. The current context is implicitly used by other APIs such as `hipStreamCreate`. +HIP provides a `Ctx` API as a thin layer over the existing Device functions. This Ctx API can be used to set the current context, or to query properties of the device associated with the context. +The current context is implicitly used by other APIs such as `hipStreamCreate`. ### hipify translation of CUDA Driver API -The hipify tool will convert CUDA Driver APIs for streams, events, memory management to -the equivalent HIP driver calls. For example, `cuEventCreate` will be translated to -`hipEventCreate`. Hipify also converts error code from the Driver namespace and coding -convention to the equivalent HIP error code. Thus, HIP unifies the APIs for these common functions. -[hipify support for translating driver API is Under Development] +The hipify tool converts CUDA Driver APIs for streams, events, modules, devices, memory management, context, profiler to the equivalent HIP driver calls. For example, `cuEventCreate` will be translated to `hipEventCreate`. +Hipify also converts error code from the Driver namespace and coding convention to the equivalent HIP error code. Thus, HIP unifies the APIs for these common functions. -The memory copy APIs require additional explanation. The CUDA driver includes the memory -direction in the name of the API (ie `cuMemcpyH2D`) while the CUDA driver API provides -a single memory copy API with a parameter that specifies the direction and additionally -supports a "default" direction where the runtime determines the direction automatically. +The memory copy API requires additional explanation. The CUDA driver includes the memory direction in the name of the API (ie `cuMemcpyH2D`) while the CUDA driver API provides a single memory copy API with a parameter that specifies the direction and additionally supports a "default" direction where the runtime determines the direction automatically. HIP provides APIs with both styles: for example, `hipMemcpyH2D` as well as `hipMemcpy`. -The first flavor may be faster in some cases since they avoid host overhead to detect the -different memory directions. +The first flavor may be faster in some cases since they avoid host overhead to detect the different memory directions. -HIP defines a single error space, and uses camel-case for all errors (i.e. `hipErrorInvalidValue`). +HIP defines a single error space, and uses camel-case for all errors (i.e. `hipErrorInvalidValue`). ### HCC Implementation Notes #### .hsaco The .hsaco format used by HCC is described in more detail [here](https://github.com/RadeonOpenCompute/ROCm-ComputeABI-Doc). -An example and blog that show how to use the format is [here](http://gpuopen.com/rocm-with-harmony-combining-opencl-hcc-hsa-in-a-single-program). hsaco can be generated by hcc + extractkernel tool, -cloc, the GCN assembler, or other tools. +An example and blog that show how to use the format is [here](http://gpuopen.com/rocm-with-harmony-combining-opencl-hcc-hsa-in-a-single-program). hsaco can be generated by hcc + extractkernel tool, cloc, the GCN assembler, or other tools. #### Address Spaces -HCC defines a process-wide address space where the CPU and all devices allocate -addresses from a single unified pool. Thus addresses may be shared between contexts, and -unlike the original CUDA definition a new context does not create a new address space for -the device. +HCC defines a process-wide address space where the CPU and all devices allocate addresses from a single unified pool. +Thus addresses may be shared between contexts, and unlike the original CUDA definition a new context does not create a new address space for the device. #### Using hipModuleLaunchKernel `hipModuleLaunchKernel` is `cuLaunchKernel` in HIP world. It takes the same arguments as `cuLaunchKernel`. The argument `kernelParams` is not fully implemented for HCC. The workaround for it is, to use platform specific macros for each target. Or, `extra` argument can be used which works on both the platforms. #### Additional Information - HCC allocates staging buffers (used for unpinned copies) on a per-device basis. -- HCC creates a primary context when the HIP API is called. So in a pure driver API code, HIP/HCC will create a primary context while HIP/NVCC will have empty context stack. HIP/HCC will push primary context to context stack when it is empty. This can have subtle differences on applications which mix the runtime and driver APIs. +- HCC creates a primary context when the HIP API is called. So in a pure driver API code, HIP/HCC will create a primary context while HIP/NVCC will have empty context stack. +HIP/HCC will push primary context to context stack when it is empty. This can have subtle differences on applications which mix the runtime and driver APIs. ### NVCC Implementation Notes #### Interoperation between HIP and CUDA Driver -CUDA applications may want to mix CUDA driver code with HIP code (see example below). This -table shows the type equivalence to enable this interaction. - -|**HIP Type** |**CU Driver Type**| **CUDA Runtime Type** | -| ---- | ---- | ---- | -| hipModule | CUmodule | | -| hipFunction | CUfunction | | -| hipCtx_t | CUcontext | | -| hipDevice_t | CUdevice | | -| hipStream_t | CUstream | cudaStream_t | -| hipEvent_t | CUevent | cudaEvent_t | -| hipArray | CUarray | cudaArray | - +CUDA applications may want to mix CUDA driver code with HIP code (see example below). This table shows the type equivalence to enable this interaction. +|**HIP Type** |**CU Driver Type**|**CUDA Runtime Type**| +| ---- | ---- | ---- | +| hipModule | CUmodule | | +| hipFunction | CUfunction | | +| hipCtx_t | CUcontext | | +| hipDevice_t | CUdevice | | +| hipStream_t | CUstream | cudaStream_t | +| hipEvent_t | CUevent | cudaEvent_t | +| hipArray | CUarray | cudaArray | #### Compilation Flags -The hipModule interface does not support the hipModuleLoadEx function, which is used to control PTX compilaton options. +The hipModule interface does not support the `cuModuleLoadDataEx` function, which is used to control PTX compilation options. HCC does not use PTX and does not support the same compilation options. In fact, HCC code objects always contain fully compiled ISA and do not require additional compilation as part of the load step. -Code which requires this functionally should use platform-specific coding, calling `cuModuleLoadEx` -on the NVCC path and hipModuleLoad on the hcc path. For example: +Code which requires this functionally should use platform-specific coding, calling `cuModuleLoadDataEx` on the NVCC path and `hipModuleLoadData` on the hcc path. +For example: ``` hipModule module; @@ -240,7 +208,7 @@ int main(){ HIP_LAUNCH_PARAM_END }; - hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, 0, NULL, (void**)&con fig); + hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, 0, NULL, (void**)&config); hipMemcpyDtoH(B, Bd, SIZE); for(uint32_t i=0;i Date: Fri, 17 Mar 2017 10:25:56 -0500 Subject: [PATCH 03/56] Add simple device-side assert macro Currently swallows asserts but will compile. [ROCm/clr commit: c9f64bbd2d06bbc7c348aee66bdebd09620bebc7] --- .../clr/hipamd/include/hip/hcc_detail/hip_runtime.h | 11 +++++++++++ .../tests/src/deviceLib/hipIntegerIntrinsics.cpp | 2 ++ 2 files changed, 13 insertions(+) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 332e9bab46..673463635f 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -77,6 +77,17 @@ extern int HIP_TRACE_API; #define __HCC_ACCELERATOR__ __KALMAR_ACCELERATOR__ #endif + + + +// TODO-HCC add a dummy implementation of assert, need to replace with a proper kernel exit call. +#if __HIP_DEVICE_COMPILE__ == 1 + #undef assert + #define assert(COND) { if (COND) {} } +#endif + + + // Feature tests: #if defined(__HCC_ACCELERATOR__) && (__HCC_ACCELERATOR__ != 0) // Device compile and not host compile: diff --git a/projects/clr/hipamd/tests/src/deviceLib/hipIntegerIntrinsics.cpp b/projects/clr/hipamd/tests/src/deviceLib/hipIntegerIntrinsics.cpp index 6bf13a0809..27af03ced3 100644 --- a/projects/clr/hipamd/tests/src/deviceLib/hipIntegerIntrinsics.cpp +++ b/projects/clr/hipamd/tests/src/deviceLib/hipIntegerIntrinsics.cpp @@ -59,6 +59,8 @@ __device__ void integer_intrinsics() __umulhi((unsigned int)1, (unsigned int)2); __urhadd((unsigned int)1, (unsigned int)2); __usad((unsigned int)1, (unsigned int)2, 0); + + assert(1); } __global__ void compileIntegerIntrinsics(hipLaunchParm lp, int ignored) From 572be5449dac233c553f8d68cbe641927e036fe1 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Fri, 17 Mar 2017 11:04:39 -0500 Subject: [PATCH 04/56] Add USE_PROMOTE_FREE_HCC for smooth transition to new HCC caps. ADDRESS_SPACE_1 defines [ROCm/clr commit: f4256cb57c5206f0f34b54efc76ceafaea71e096] --- .../include/hip/hcc_detail/hip_runtime.h | 19 ++++++++++++++----- .../include/hip/hcc_detail/host_defines.h | 6 +++++- projects/clr/hipamd/src/device_util.cpp | 6 +++--- .../src/deviceLib/hipTestDeviceSymbol.cpp | 5 +++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 673463635f..06ce7c84df 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -47,7 +47,16 @@ THE SOFTWARE. #include -//#include "hip/hcc_detail/hip_hcc.h" +#define USE_PROMOTE_FREE_HCC 0 + +#if USE_PROMOTE_FREE_HCC == 1 +#define ADDRESS_SPACE_1 +#define ADDRESS_SPACE_3 +#else +#define ADDRESS_SPACE_1 __attribute__((address_space(1))) +#define ADDRESS_SPACE_3 __attribute__((address_space(3))) +#endif + //--- // Remainder of this file only compiles with HCC #ifdef __HCC__ @@ -275,7 +284,7 @@ __device__ int __hip_move_dpp(int src, int dpp_ctrl, int row_mask, int bank_mask __host__ __device__ int min(int arg1, int arg2); __host__ __device__ int max(int arg1, int arg2); -__device__ __attribute__((address_space(3))) void* __get_dynamicgroupbaseptr(); +__device__ ADDRESS_SPACE_3 void* __get_dynamicgroupbaseptr(); /** @@ -433,10 +442,10 @@ do {\ // Macro to replace extern __shared__ declarations // to local variable definitions #define HIP_DYNAMIC_SHARED(type, var) \ - __attribute__((address_space(3))) type* var = \ - (__attribute__((address_space(3))) type*)__get_dynamicgroupbaseptr(); \ + ADDRESS_SPACE_3 type* var = \ + ADDRESS_SPACE_3 type*)__get_dynamicgroupbaseptr(); \ -#define HIP_DYNAMIC_SHARED_ATTRIBUTE __attribute__((address_space(3))) +#define HIP_DYNAMIC_SHARED_ATTRIBUTE ADDRESS_SPACE_3 #endif // __HCC__ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index e401cb24f3..0e10d0075c 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -47,7 +47,11 @@ THE SOFTWARE. */ // _restrict is supported by the compiler #define __shared__ tile_static -#define __constant__ __attribute__((address_space(1))) +#if USE_PROMOTE_FREE_HCC==1 +#define __constant__ __attribute__((hc)) +#else +#define __constant__ ADDRESS_SPACE_1 +#endif #else // Non-HCC compiler diff --git a/projects/clr/hipamd/src/device_util.cpp b/projects/clr/hipamd/src/device_util.cpp index 4b0e7efefd..6e2652449f 100644 --- a/projects/clr/hipamd/src/device_util.cpp +++ b/projects/clr/hipamd/src/device_util.cpp @@ -34,8 +34,8 @@ THE SOFTWARE. This is the best place to put them because the device global variables need to be initialized at the start. */ -__attribute__((address_space(1))) char gpuHeap[SIZE_OF_HEAP]; -__attribute__((address_space(1))) uint32_t gpuFlags[NUM_PAGES]; +ADDRESS_SPACE_1 char gpuHeap[SIZE_OF_HEAP]; +ADDRESS_SPACE_1 uint32_t gpuFlags[NUM_PAGES]; __device__ void *__hip_hc_malloc(size_t size) { @@ -1083,7 +1083,7 @@ __host__ __device__ int max(int arg1, int arg2) return (int)(hc::precise_math::fmax((float)arg1, (float)arg2)); } -__device__ __attribute__((address_space(3))) void* __get_dynamicgroupbaseptr() +__device__ ADDRESS_SPACE_3 void* __get_dynamicgroupbaseptr() { return hc::get_dynamic_group_segment_base_pointer(); } diff --git a/projects/clr/hipamd/tests/src/deviceLib/hipTestDeviceSymbol.cpp b/projects/clr/hipamd/tests/src/deviceLib/hipTestDeviceSymbol.cpp index 9e188e9f17..6ffaedf659 100644 --- a/projects/clr/hipamd/tests/src/deviceLib/hipTestDeviceSymbol.cpp +++ b/projects/clr/hipamd/tests/src/deviceLib/hipTestDeviceSymbol.cpp @@ -31,9 +31,10 @@ THE SOFTWARE. #define NUM 1024 #define SIZE 1024*4 +// TODO - collapse: #ifdef __HIP_PLATFORM_HCC__ -__attribute__((address_space(1))) int globalIn[NUM]; -__attribute__((address_space(1))) int globalOut[NUM]; +__device__ ADDRESS_SPACE_1 int globalIn[NUM]; +__device__ ADDRESS_SPACE_1 int globalOut[NUM]; #endif #ifdef __HIP_PLATFORM_NVCC__ From e0171505b4ce4dee0a57d28aceb917dc148e5073 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Fri, 17 Mar 2017 11:19:48 -0500 Subject: [PATCH 05/56] Add __device__ to needful functions for promote-free. [ROCm/clr commit: 92fd4c8f10f1d0c0782dde380102088cb82aac61] --- projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h | 2 +- projects/clr/hipamd/src/device_functions.cpp | 4 ++-- projects/clr/hipamd/src/device_util.cpp | 4 ++-- projects/clr/hipamd/src/hip_fp16.cpp | 2 +- projects/clr/hipamd/src/math_functions.cpp | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 06ce7c84df..6fc68abb3a 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -443,7 +443,7 @@ do {\ // to local variable definitions #define HIP_DYNAMIC_SHARED(type, var) \ ADDRESS_SPACE_3 type* var = \ - ADDRESS_SPACE_3 type*)__get_dynamicgroupbaseptr(); \ + (ADDRESS_SPACE_3 type*)__get_dynamicgroupbaseptr(); \ #define HIP_DYNAMIC_SHARED_ATTRIBUTE ADDRESS_SPACE_3 diff --git a/projects/clr/hipamd/src/device_functions.cpp b/projects/clr/hipamd/src/device_functions.cpp index abc9db570e..10d8d3ab89 100644 --- a/projects/clr/hipamd/src/device_functions.cpp +++ b/projects/clr/hipamd/src/device_functions.cpp @@ -41,8 +41,8 @@ struct holder32Bit { }; } __attribute__((aligned(4))); -struct holder64Bit hold64; -struct holder32Bit hold32; +__device__ struct holder64Bit hold64; +__device__ struct holder32Bit hold32; __device__ float __double2float_rd(double x) { diff --git a/projects/clr/hipamd/src/device_util.cpp b/projects/clr/hipamd/src/device_util.cpp index 6e2652449f..b0df62f43b 100644 --- a/projects/clr/hipamd/src/device_util.cpp +++ b/projects/clr/hipamd/src/device_util.cpp @@ -34,8 +34,8 @@ THE SOFTWARE. This is the best place to put them because the device global variables need to be initialized at the start. */ -ADDRESS_SPACE_1 char gpuHeap[SIZE_OF_HEAP]; -ADDRESS_SPACE_1 uint32_t gpuFlags[NUM_PAGES]; +__device__ ADDRESS_SPACE_1 char gpuHeap[SIZE_OF_HEAP]; +__device__ ADDRESS_SPACE_1 uint32_t gpuFlags[NUM_PAGES]; __device__ void *__hip_hc_malloc(size_t size) { diff --git a/projects/clr/hipamd/src/hip_fp16.cpp b/projects/clr/hipamd/src/hip_fp16.cpp index b306a9d3de..e7f75844ff 100644 --- a/projects/clr/hipamd/src/hip_fp16.cpp +++ b/projects/clr/hipamd/src/hip_fp16.cpp @@ -31,7 +31,7 @@ struct hipHalfHolder{ #define HINF 65504 -static struct hipHalfHolder __hInfValue = {HINF}; +__device__ static struct hipHalfHolder __hInfValue = {HINF}; __device__ __half __hadd(__half a, __half b) { return a + b; diff --git a/projects/clr/hipamd/src/math_functions.cpp b/projects/clr/hipamd/src/math_functions.cpp index 230eb2aacc..6e919b3926 100644 --- a/projects/clr/hipamd/src/math_functions.cpp +++ b/projects/clr/hipamd/src/math_functions.cpp @@ -202,7 +202,8 @@ __device__ long long int llroundf(float x) int y = hc::precise_math::roundf(x); long long int z = y; return z; -}__device__ float log10f(float x) +} +__device__ float log10f(float x) { return hc::precise_math::log10f(x); } From 7466b4005b9896c16a36b691b9dfc0d9eb1e1717 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Fri, 17 Mar 2017 12:04:13 -0500 Subject: [PATCH 06/56] Move USE_PROMOTE_FREE_HCC [ROCm/clr commit: 20ea5e179f705d154de7a9466c8f43b6edcc666c] --- projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h | 1 - projects/clr/hipamd/include/hip/hcc_detail/host_defines.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 6fc68abb3a..af294cdb53 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -47,7 +47,6 @@ THE SOFTWARE. #include -#define USE_PROMOTE_FREE_HCC 0 #if USE_PROMOTE_FREE_HCC == 1 #define ADDRESS_SPACE_1 diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index 0e10d0075c..93695a0038 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -28,6 +28,8 @@ THE SOFTWARE. #ifndef HOST_DEFINES_H #define HOST_DEFINES_H +#define USE_PROMOTE_FREE_HCC 0 + #ifdef __HCC__ /** * Function and kernel markers From b4b87b8786666d6a36bbaa5bca6052d8c215619f Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Fri, 17 Mar 2017 13:11:34 -0500 Subject: [PATCH 07/56] Added default module launch api functionality 1. As in hipModuleLaunchKernel(..., kernelParams, nullptr); works with this commit 2. Added headers AMDGPUPTNote.h, AMDGPURuntimeMetadata.h to do code object meta data parsing 3. Changed CMake to look at llvm link libraries 4. HIP developer should set env variable LLVM_HOME to remove link errors 5. HIP depends on installed LLVM (not source, not build) 6. Added sample to test out the feature 7. Right now HCC does not support embedding metadata in code object. Use clang opencl 8. Changed HIPCC to read LLVM_HOME env var 9. New argument to CMake should be given -DLLVM_HOME= Change-Id: Iba38194aa872d97cc2c90a8e5ff746c48055c868 [ROCm/clr commit: 9645b0e0dc58084e692e049865497b145d068a00] --- projects/clr/hipamd/CMakeLists.txt | 10 + projects/clr/hipamd/bin/hipcc | 8 +- .../samples/0_Intro/module_api/Makefile | 8 +- .../0_Intro/module_api/defaultDriver.cpp | 89 ++++++ .../samples/0_Intro/module_api/runKernel.cpp | 4 +- .../hipamd/samples/0_Intro/module_api/test.cl | 12 + .../hipamd/samples/0_Intro/module_api/test.co | Bin 0 -> 9824 bytes projects/clr/hipamd/src/AMDGPUPTNote.h | 45 +++ .../clr/hipamd/src/AMDGPURuntimeMetadata.h | 290 ++++++++++++++++++ projects/clr/hipamd/src/hip_module.cpp | 99 +++++- 10 files changed, 553 insertions(+), 12 deletions(-) create mode 100644 projects/clr/hipamd/samples/0_Intro/module_api/defaultDriver.cpp create mode 100644 projects/clr/hipamd/samples/0_Intro/module_api/test.cl create mode 100755 projects/clr/hipamd/samples/0_Intro/module_api/test.co create mode 100644 projects/clr/hipamd/src/AMDGPUPTNote.h create mode 100644 projects/clr/hipamd/src/AMDGPURuntimeMetadata.h diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index 1ba58496f4..a1887d0cb5 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -63,6 +63,14 @@ if(HIP_PLATFORM STREQUAL "hcc") set(HCC_HOME $ENV{HCC_HOME} CACHE PATH "Path to which HCC has been installed") endif() endif() + # Determine LLVM_HOME + if(NOT DEFINED LLVM_HOME) + if(NOT DEFINED ENV{LLVM_HOME}) + set(LLVM_HOME "/opt/rocm/llvm" CACHE PATH "Path to which LLVM has been installed") + else() + set(LLVM_HOME $ENV{LLVM_HOME} CACHE PATH "Path to which LLVM has been installed") + endif() + endif() if(DEFINED ENV{HIP_DEVELOPER}) add_to_config(_buildInfo HCC_HOME) endif() @@ -189,9 +197,11 @@ if(HIP_PLATFORM STREQUAL "hcc") execute_process(COMMAND ${HCC_HOME}/bin/hcc-config --ldflags OUTPUT_VARIABLE HCC_LD_FLAGS) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${HCC_LD_FLAGS} -Wl,-Bsymbolic") + find_package(LLVM HINTS ${LLVM_HOME}) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --amdgpu-target=gfx701 --amdgpu-target=gfx801 --amdgpu-target=gfx802 --amdgpu-target=gfx803 --amdgpu-target=gfx900") add_library(hip_hcc SHARED ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc PRIVATE hc_am) + target_link_libraries(hip_hcc PUBLIC LLVMAMDGPUUtils) add_library(hip_hcc_static STATIC ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc_static PRIVATE hc_am) add_dependencies(hip_hcc_static hip_hcc) diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index 361517d551..4c71347cf7 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/bin/hipcc @@ -103,6 +103,8 @@ if ($HIP_PLATFORM eq "hcc") { $HIPLDFLAGS = `${HCC_HOME}/bin/hcc-config --ldflags`; + $LLVM_HOME = $ENV{'LLVM_HOME'}; + #### GCC system includes workaround #### $HCC_WA_FLAGS = " "; if ($HCC_VERSION_MAJOR eq 1) { @@ -127,7 +129,7 @@ if ($HIP_PLATFORM eq "hcc") { $HIPCXXFLAGS .= " -Wno-deprecated-register"; $HIPLDFLAGS .= " -lsupc++"; - $HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am -lhsakmt"; + $HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am -lhsakmt `${LLVM_HOME}/bin/llvm-config --ldflags --libs`"; # Add trace marker library: # TODO - once we cleanly separate the HIP API headers from HIP library headers this logic should move to CMakebuild option - apps do not need to see the marker library. @@ -402,9 +404,9 @@ if ($setStdLib eq 0 and $HIP_PLATFORM eq 'hcc') if ($needHipHcc) { if ($linkType eq 0) { - substr($HIPLDFLAGS,0,0) = " $HIP_PATH/lib/libhip_hcc_static.a $HIP_PATH/lib/libhip_device.a " ; + substr($HIPLDFLAGS,0,0) = " $HIP_PATH/lib/libhip_hcc_static.a $HIP_PATH/lib/libhip_device.a " ; } else { - substr($HIPLDFLAGS,0,0) = " -Wl,--rpath=$HIP_PATH/lib $HIP_PATH/lib/libhip_hcc.so $HIP_PATH/lib/libhip_device.a "; + substr($HIPLDFLAGS,0,0) = " -Wl,--rpath=$HIP_PATH/lib $HIP_PATH/lib/libhip_hcc.so $HIP_PATH/lib/libhip_device.a "; } } diff --git a/projects/clr/hipamd/samples/0_Intro/module_api/Makefile b/projects/clr/hipamd/samples/0_Intro/module_api/Makefile index f2c0ce555a..632a8d3e70 100644 --- a/projects/clr/hipamd/samples/0_Intro/module_api/Makefile +++ b/projects/clr/hipamd/samples/0_Intro/module_api/Makefile @@ -5,14 +5,16 @@ endif HIPCC=$(HIP_PATH)/bin/hipcc HIP_PLATFORM=$(shell $(HIP_PATH)/bin/hipconfig --compiler) -all: vcpy_kernel.code runKernel.hip.out +all: vcpy_kernel.code runKernel.hip.out defaultDriver.hip.out runKernel.hip.out: runKernel.cpp $(HIPCC) $(HIPCC_FLAGS) $< -o $@ +defaultDriver.hip.out: defaultDriver.cpp + $(HIPCC) $(HIPCC_FLAGS) $< -o $@ + vcpy_kernel.code: vcpy_kernel.cpp - $(HIPCC) --genco $(GENCO_FLAGS) $^ -o $@ + $(HIPCC) --genco $(GENCO_FLAGS) $^ -o $@ clean: rm -f *.code *.out - diff --git a/projects/clr/hipamd/samples/0_Intro/module_api/defaultDriver.cpp b/projects/clr/hipamd/samples/0_Intro/module_api/defaultDriver.cpp new file mode 100644 index 0000000000..a29271a0dc --- /dev/null +++ b/projects/clr/hipamd/samples/0_Intro/module_api/defaultDriver.cpp @@ -0,0 +1,89 @@ +/* +Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "hip/hip_runtime.h" +#include "hip/hip_runtime_api.h" +#include +#include +#include + +#define LEN 64 +#define SIZE LEN<<2 + +#define fileName "test.co" +#define kernel_name "vadd" + +int main(){ + float *A, *B, *C; + hipDeviceptr_t Ad, Bd, Cd; + A = new float[LEN]; + B = new float[LEN]; + C = new float[LEN]; + + for(uint32_t i=0;iH@ikcag#Q!>Xh`B3Zc@Bch`yO`hvZV z8c^LpLG*zK-~;#qzJcbkyp=xZp)W{%;2VH*c4oX@lU6MRTGTy~_spEjoHOT~nZ1l} z950_xGMPCdV1(Q!8En7E33D8g)kC5IXpY!q9IpGw1j#`^8__s_jw9f5*p3DxMB;Hl zM>6U?3@%S_j>OU*)Eh;X@NXF38R2>oOFrtMuY}?SfJWCoUKL%5rJe%xC()DhJNIko zMf0O#;32#!$kGn_hj143B7401*jKa_*+YjBhVX+iPL^249x?ii_Df3(ks7v<{wDk| zoJh}-u}BWOeHzdgmoIYJ?_qo#2W6+Hrzbw6tnTHP7FPUrr`Bu~>4#LGq8hzC6){eA z*r`UfS)^P}bT6?DzuIm#!t=FH{UWuDgmAg(vS7)tH`|+nZ<+-wA#(g;XW4JhUo6t3 z>Jqz#V6$>3okX>R~OsOZi|nutA?ErJHNPmt`r1Kcd^YH-2fcalGZOY zLl&Ir)={uiq_&zgQ}VpF-|4VQ;KxFm3Sq%ei4d&(#Yl1{(gwMRl3lQhSY$ zPXVM2Ao8e!B+eH4rJ%M3brBOz*BV}tikN}G3Jbdah0PWQy03+O?y9@a+I@1#bM>4vFQ~;}Q16q1nEP0f(G_FvEDp zdo-Z)5Dz0CW%36LY=e0o*ZEhoA|si)SgkcMk*J>)*g9D)BtEB_2fZULMh3;u?1Z9iIpA zhh6!I!6n3%-$4kj^8`KZq!CCXkVYVlz%vyA+{gJ3cYN5{#XkQqCrjiLfEcVMCSZnf+KJ%R4w0R2tOC@(z5D$wWS6@Ug44gVlun9{K%iLY{sdMXsioGy-V^ z(g>sxNF$I&AdNs8fiwbX1fJ;#$g}1LFK{;}g}3<5gAkpy16~%d`|_=Sf5a7M&d^pR zL(u!^Tf5VcuNGp1clS53#5wk_3hJ#SjG zOx18bdX(%o%#rmlY;}q=Gi$YQy<5q<&HBta=K0M=bZFVEx4NM}6KUo_glcZZa~$2Q zT2|Gr*sf{m%=dJM`F_PTD_*6l8LDBaN9p5@90VKnXkbG(w1VbY1&>twb`of+XcJoR8-Y44cjz*%hoJI_x&fHhV8hj zrMX^3ovr!>rn_pjU>H`V;5eq~!FhY7QgwYtJxa>8##O&vq~-DgPia5pyEX7T16EV{ zUlPV(!lv(9^Ao8&|P zS{U_Mz2=fU|3gFG?RYF?1Z%18H$VV1LskL2-U-{h#W6W{OuM2*SDg%=d|X-h;7n=h z)O^zUztO|EVT_`$N2o6w0?Yq%APWKiw=oE)i)&h{$#pLANg<4SXbZn>A;|TA0NS_* zNPW4^C8oebkbG%h;#Yx(=S7k)_YsNZK7wN)@H*jbydD%ZxlhS+DvA65^N}h;0~`W6 z>Y@)3&?H_JUFol!zxLu>A%ch8EE~v3t2?>h5knaG;9vrUjf=~`tM<20mLx81J_~wKLJkil%fCt literal 0 HcmV?d00001 diff --git a/projects/clr/hipamd/src/AMDGPUPTNote.h b/projects/clr/hipamd/src/AMDGPUPTNote.h new file mode 100644 index 0000000000..8f8c855a52 --- /dev/null +++ b/projects/clr/hipamd/src/AMDGPUPTNote.h @@ -0,0 +1,45 @@ +//===-- AMDGPUNoteType.h - AMDGPU ELF PT_NOTE section info-------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +/// \file +/// +/// Enums and constants for AMDGPU PT_NOTE sections. +/// +// +//===----------------------------------------------------------------------===// +// +#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUPTNOTE_H +#define LLVM_LIB_TARGET_AMDGPU_AMDGPUPTNOTE_H + +namespace AMDGPU { + +namespace ElfNote { + +const char SectionName[] = ".note"; + +const char NoteName[] = "AMD"; + +// TODO: Move this enum to include/llvm/Support so it can be used in tools? +enum NoteType{ + NT_AMDGPU_HSA_CODE_OBJECT_VERSION = 1, + NT_AMDGPU_HSA_HSAIL = 2, + NT_AMDGPU_HSA_ISA = 3, + NT_AMDGPU_HSA_PRODUCER = 4, + NT_AMDGPU_HSA_PRODUCER_OPTIONS = 5, + NT_AMDGPU_HSA_EXTENSION = 6, + NT_AMDGPU_HSA_RUNTIME_METADATA_V_1 = 7, // deprecated since 12/14/16. + NT_AMDGPU_HSA_RUNTIME_METADATA_V_2 = 8, + NT_AMDGPU_HSA_RUNTIME_METADATA = NT_AMDGPU_HSA_RUNTIME_METADATA_V_2, + NT_AMDGPU_HSA_HLDEBUG_DEBUG = 101, + NT_AMDGPU_HSA_HLDEBUG_TARGET = 102 +}; +} +} + +#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUNOTETYPE_H diff --git a/projects/clr/hipamd/src/AMDGPURuntimeMetadata.h b/projects/clr/hipamd/src/AMDGPURuntimeMetadata.h new file mode 100644 index 0000000000..ed147ff4c4 --- /dev/null +++ b/projects/clr/hipamd/src/AMDGPURuntimeMetadata.h @@ -0,0 +1,290 @@ +//===-- AMDGPURuntimeMetadata.h - AMDGPU Runtime Metadata -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +/// \file +/// +/// Enums and structure types used by runtime metadata. +/// +/// Runtime requests certain information (metadata) about kernels to be able +/// to execute the kernels and answer the queries about the kernels. +/// The metadata is represented as a note element in the .note ELF section of a +/// binary (code object). The desc field of the note element is a YAML string +/// consisting of key-value pairs. Each key is a string. Each value can be +/// an integer, a string, or an YAML sequence. There are 3 levels of YAML maps. +/// At the beginning of the YAML string is the module level YAML map. A +/// kernel-level YAML map is in the amd.Kernels sequence. A +/// kernel-argument-level map is in the amd.Args sequence. +/// +/// The format should be kept backward compatible. New enum values and bit +/// fields should be appended at the end. It is suggested to bump up the +/// revision number whenever the format changes and document the change +/// in the revision in this header. +/// +// +//===----------------------------------------------------------------------===// +// +#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H +#define LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H + +#include +#include +#include + +namespace AMDGPU { +namespace RuntimeMD { + + // Version and revision of runtime metadata + const unsigned char MDVersion = 2; + const unsigned char MDRevision = 1; + + // Name of keys for runtime metadata. + namespace KeyName { + + // Runtime metadata version + const char MDVersion[] = "amd.MDVersion"; + + // Instruction set architecture information + const char IsaInfo[] = "amd.IsaInfo"; + // Wavefront size + const char IsaInfoWavefrontSize[] = "amd.IsaInfoWavefrontSize"; + // Local memory size in bytes + const char IsaInfoLocalMemorySize[] = "amd.IsaInfoLocalMemorySize"; + // Number of execution units per compute unit + const char IsaInfoEUsPerCU[] = "amd.IsaInfoEUsPerCU"; + // Maximum number of waves per execution unit + const char IsaInfoMaxWavesPerEU[] = "amd.IsaInfoMaxWavesPerEU"; + // Maximum flat work group size + const char IsaInfoMaxFlatWorkGroupSize[] = "amd.IsaInfoMaxFlatWorkGroupSize"; + // SGPR allocation granularity + const char IsaInfoSGPRAllocGranule[] = "amd.IsaInfoSGPRAllocGranule"; + // Total number of SGPRs + const char IsaInfoTotalNumSGPRs[] = "amd.IsaInfoTotalNumSGPRs"; + // Addressable number of SGPRs + const char IsaInfoAddressableNumSGPRs[] = "amd.IsaInfoAddressableNumSGPRs"; + // VGPR allocation granularity + const char IsaInfoVGPRAllocGranule[] = "amd.IsaInfoVGPRAllocGranule"; + // Total number of VGPRs + const char IsaInfoTotalNumVGPRs[] = "amd.IsaInfoTotalNumVGPRs"; + // Addressable number of VGPRs + const char IsaInfoAddressableNumVGPRs[] = "amd.IsaInfoAddressableNumVGPRs"; + + // Language + const char Language[] = "amd.Language"; + // Language version + const char LanguageVersion[] = "amd.LanguageVersion"; + + // Kernels + const char Kernels[] = "amd.Kernels"; + // Kernel name + const char KernelName[] = "amd.KernelName"; + // Kernel arguments + const char Args[] = "amd.Args"; + // Kernel argument size in bytes + const char ArgSize[] = "amd.ArgSize"; + // Kernel argument alignment + const char ArgAlign[] = "amd.ArgAlign"; + // Kernel argument type name + const char ArgTypeName[] = "amd.ArgTypeName"; + // Kernel argument name + const char ArgName[] = "amd.ArgName"; + // Kernel argument kind + const char ArgKind[] = "amd.ArgKind"; + // Kernel argument value type + const char ArgValueType[] = "amd.ArgValueType"; + // Kernel argument address qualifier + const char ArgAddrQual[] = "amd.ArgAddrQual"; + // Kernel argument access qualifier + const char ArgAccQual[] = "amd.ArgAccQual"; + // Kernel argument is const qualified + const char ArgIsConst[] = "amd.ArgIsConst"; + // Kernel argument is restrict qualified + const char ArgIsRestrict[] = "amd.ArgIsRestrict"; + // Kernel argument is volatile qualified + const char ArgIsVolatile[] = "amd.ArgIsVolatile"; + // Kernel argument is pipe qualified + const char ArgIsPipe[] = "amd.ArgIsPipe"; + // Required work group size + const char ReqdWorkGroupSize[] = "amd.ReqdWorkGroupSize"; + // Work group size hint + const char WorkGroupSizeHint[] = "amd.WorkGroupSizeHint"; + // Vector type hint + const char VecTypeHint[] = "amd.VecTypeHint"; + // Kernel index for device enqueue + const char KernelIndex[] = "amd.KernelIndex"; + // No partial work groups + const char NoPartialWorkGroups[] = "amd.NoPartialWorkGroups"; + // Prinf function call information + const char PrintfInfo[] = "amd.PrintfInfo"; + // The actual kernel argument access qualifier + const char ArgActualAcc[] = "amd.ArgActualAcc"; + // Alignment of pointee type + const char ArgPointeeAlign[] = "amd.ArgPointeeAlign"; + + } // end namespace KeyName + + namespace KernelArg { + + enum Kind : uint8_t { + ByValue = 0, + GlobalBuffer = 1, + DynamicSharedPointer = 2, + Sampler = 3, + Image = 4, + Pipe = 5, + Queue = 6, + HiddenGlobalOffsetX = 7, + HiddenGlobalOffsetY = 8, + HiddenGlobalOffsetZ = 9, + HiddenNone = 10, + HiddenPrintfBuffer = 11, + HiddenDefaultQueue = 12, + HiddenCompletionAction = 13, + }; + + enum ValueType : uint16_t { + Struct = 0, + I8 = 1, + U8 = 2, + I16 = 3, + U16 = 4, + F16 = 5, + I32 = 6, + U32 = 7, + F32 = 8, + I64 = 9, + U64 = 10, + F64 = 11, + }; + + // Avoid using 'None' since it conflicts with a macro in X11 header file. + enum AccessQualifer : uint8_t { + AccNone = 0, + ReadOnly = 1, + WriteOnly = 2, + ReadWrite = 3, + }; + + enum AddressSpaceQualifer : uint8_t { + Private = 0, + Global = 1, + Constant = 2, + Local = 3, + Generic = 4, + Region = 5, + }; + + } // end namespace KernelArg + + // Invalid values are used to indicate an optional key should not be emitted. + const uint8_t INVALID_ADDR_QUAL = 0xff; + const uint8_t INVALID_ACC_QUAL = 0xff; + const uint32_t INVALID_KERNEL_INDEX = ~0U; + + namespace KernelArg { + + // In-memory representation of kernel argument information. + struct Metadata { + uint32_t Size = 0; + uint32_t Align = 0; + uint32_t PointeeAlign = 0; + uint8_t Kind = 0; + uint16_t ValueType = 0; + std::string TypeName; + std::string Name; + uint8_t AddrQual = INVALID_ADDR_QUAL; + uint8_t AccQual = INVALID_ACC_QUAL; + uint8_t IsVolatile = 0; + uint8_t IsConst = 0; + uint8_t IsRestrict = 0; + uint8_t IsPipe = 0; + + Metadata() = default; + }; + + } // end namespace KernelArg + + namespace Kernel { + + // In-memory representation of kernel information. + struct Metadata { + std::string Name; + std::string Language; + std::vector LanguageVersion; + std::vector ReqdWorkGroupSize; + std::vector WorkGroupSizeHint; + std::string VecTypeHint; + uint32_t KernelIndex = INVALID_KERNEL_INDEX; + uint8_t NoPartialWorkGroups = 0; + std::vector Args; + + Metadata() = default; + }; + + } // end namespace Kernel + + namespace IsaInfo { + + /// \brief In-memory representation of instruction set architecture + /// information. + struct Metadata { + /// \brief Wavefront size. + unsigned WavefrontSize = 0; + /// \brief Local memory size in bytes. + unsigned LocalMemorySize = 0; + /// \brief Number of execution units per compute unit. + unsigned EUsPerCU = 0; + /// \brief Maximum number of waves per execution unit. + unsigned MaxWavesPerEU = 0; + /// \brief Maximum flat work group size. + unsigned MaxFlatWorkGroupSize = 0; + /// \brief SGPR allocation granularity. + unsigned SGPRAllocGranule = 0; + /// \brief Total number of SGPRs. + unsigned TotalNumSGPRs = 0; + /// \brief Addressable number of SGPRs. + unsigned AddressableNumSGPRs = 0; + /// \brief VGPR allocation granularity. + unsigned VGPRAllocGranule = 0; + /// \brief Total number of VGPRs. + unsigned TotalNumVGPRs = 0; + /// \brief Addressable number of VGPRs. + unsigned AddressableNumVGPRs = 0; + + Metadata() = default; + }; + + } // end namespace IsaInfo + + namespace Program { + + // In-memory representation of program information. + struct Metadata { + std::vector MDVersionSeq; + IsaInfo::Metadata IsaInfo; + std::vector PrintfInfo; + std::vector Kernels; + + explicit Metadata() = default; + + // Construct from an YAML string. + explicit Metadata(const std::string &YAML); + + // Convert to YAML string. + std::string toYAML(); + + // Convert from YAML string. + static Metadata fromYAML(const std::string &S); + }; + + } //end namespace Program + +} // end namespace RuntimeMD +} // end namespace AMDGPU + +#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H diff --git a/projects/clr/hipamd/src/hip_module.cpp b/projects/clr/hipamd/src/hip_module.cpp index 1f20a47c13..dc0a681c6d 100644 --- a/projects/clr/hipamd/src/hip_module.cpp +++ b/projects/clr/hipamd/src/hip_module.cpp @@ -23,7 +23,12 @@ THE SOFTWARE. #include #include #include +#include #include +#include +#include +#include "AMDGPUPTNote.h" +#include "AMDGPURuntimeMetadata.h" #include "hsa/hsa.h" #include "hsa/hsa_ext_amd.h" @@ -35,6 +40,30 @@ THE SOFTWARE. //TODO Use Pool APIs from HCC to get memory regions. +#include +inline uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew = 0) { + assert(Align != 0u && "Align can't be 0."); + Skew %= Align; + return (Value + Align - 1 - Skew) / Align * Align + Skew; +} + +struct ihipKernArgInfo{ + std::vector Size; + std::vector Align; + std::vector ArgType; + std::vector ArgName; + uint32_t totalSize; +}; + +std::map kernelArguments; + +struct MyElfNote { + uint32_t n_namesz = 0; + uint32_t n_descsz = 0; + uint32_t n_type = 0; + + MyElfNote() = default; +}; struct ihipModuleSymbol_t{ uint64_t _object; // The kernel object. @@ -172,8 +201,56 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname){ (*module)->ptr = p; (*module)->size = size; in.seekg(0, std::ios::beg); - std::copy(std::istreambuf_iterator(in), - std::istreambuf_iterator(), ptr); + std::copy(std::istreambuf_iterator(in), std::istreambuf_iterator(), ptr); + + Elf *e = elf_memory((char*)p, size); + if(elf_kind(e) != ELF_K_ELF){ + return ihipLogStatus(hipErrorInvalidValue); + } + size_t numpHdrs; + if(elf_getphdrnum(e, &numpHdrs) != 0){ + return ihipLogStatus(hipErrorInvalidValue); + } + for(size_t i=0;i= sizeof(int)){ + char* ptr = (char*) p + pHdr.p_offset; + char* segmentEnd = ptr + pHdr.p_filesz; + while(ptr < segmentEnd){ + MyElfNote *note = (MyElfNote*) ptr; + char *name = (char*) ¬e[1]; + char *desc = name + alignTo(note->n_namesz, sizeof(int)); + if (note->n_type == 8) { + std::string metadatastr((const char*)desc, (size_t)note->n_descsz); + AMDGPU::RuntimeMD::Program::Metadata meta; + meta = meta.fromYAML(metadatastr); + for(int i=0;in_namesz, sizeof(int)) + + alignTo(note->n_descsz, sizeof(int)); + } + } + } status = hsa_code_object_deserialize(ptr, size, NULL, &(*module)->object); @@ -313,7 +390,19 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f, void *config[5] = {0}; size_t kernArgSize; - if(extra != NULL){ + if(kernelParams != NULL){ + std::string name = f->_name; + struct ihipKernArgInfo pl = kernelArguments[name]; + char* argBuf = (char*)malloc(pl.totalSize); + memset(argBuf, 0, pl.totalSize); + int index = 0; + for(int i=0;idispatch_hsa_kernel(&aql, config[1] /* kernarg*/, kernArgSize, nullptr/*completion_future*/); - + if(kernelParams != NULL){ + free(config[1]); + } ihipPostLaunchKernel(f->_name.c_str(), hStream, lp); } From 9c9a9bb3307864fca13b748f3119a52e4f127683 Mon Sep 17 00:00:00 2001 From: pensun Date: Fri, 17 Mar 2017 17:17:12 +0000 Subject: [PATCH 08/56] Initial integration with Alex' Generic Grid Launch Change-Id: I559afb80e9e39ec0d119bb3bf3b85ef9e448caf6 [ROCm/clr commit: ad882222b086ad28adc3c25edeab0c360b1584b0] --- .../include/hip/hcc_detail/concepts.hpp | 11 + .../include/hip/hcc_detail/grid_launch_v2.hpp | 227 ++++++++++++++++++ .../hipamd/include/hip/hcc_detail/helpers.hpp | 96 ++++++++ .../hipamd/include/hip/hcc_detail/hip_ldg.h | 4 +- .../include/hip/hcc_detail/hip_runtime.h | 46 ++-- .../include/hip/hcc_detail/hip_runtime_api.h | 3 +- .../include/hip/hcc_detail/host_defines.h | 7 + .../samples/0_Intro/square/square.hipref.cpp | 2 +- projects/clr/hipamd/src/hip_hcc.cpp | 1 - projects/clr/hipamd/src/trace_helper.h | 4 +- 10 files changed, 376 insertions(+), 25 deletions(-) create mode 100644 projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp create mode 100644 projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp create mode 100644 projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp diff --git a/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp b/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp new file mode 100644 index 0000000000..373ec15411 --- /dev/null +++ b/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp @@ -0,0 +1,11 @@ +// +// Created by alexv on 25/10/16. +// +#pragma once + +namespace glo_tests // Documentation only. +{ + #define requires(...) + + #define FunctionalProcedure typename +} diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp new file mode 100644 index 0000000000..ab11433a5b --- /dev/null +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -0,0 +1,227 @@ +// +// Created by alexv on 25/10/16. +// +#pragma once + +#include "concepts.hpp" +#include "helpers.hpp" + +#include "hc.hpp" +#include "hcc_acc.h" + +//#include +//#include + +#include +#include +#include + + +namespace glo_tests +{ + namespace + { + struct New_grid_launch_tag {}; + struct Old_grid_launch_tag {}; + } + + template + using is_new_grid_launch_t = typename std::conditional< + std::is_callable{}, + New_grid_launch_tag, + Old_grid_launch_tag>::type; + + // TODO: - dispatch rank should be derived from the domain dimensions passed + // in, and not always assumed to be 3; + + template + requires(Domain == {Ts...}) + static + inline + void grid_launch_impl( + New_grid_launch_tag, + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + K k, + Ts&&... args) + { + const auto d = hc::extent<3>{ + num_blocks.z * dim_blocks.z, + num_blocks.y * dim_blocks.y, + num_blocks.x * dim_blocks.x}.tile_with_dynamic( + dim_blocks.z, + dim_blocks.y, + dim_blocks.x, + group_mem_bytes); + hc::accelerator_view* av = nullptr; + + if (hipHccGetAcceleratorView(stream, &av) != HIP_SUCCESS) { + throw std::runtime_error{"Failed to retrieve accelerator_view!"}; + } + + hc::parallel_for_each(*av, d, [=](hc::tiled_index<3> idx) [[hc]] { + k(args...); + }); + } + + template + requires(Domain == {hipLaunchParm, Ts...}) + static + inline + void grid_launch_impl( + Old_grid_launch_tag, + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + K k, + Ts&&... args) + { + grid_launch_impl( + New_grid_launch_tag{}, + std::move(num_blocks), + std::move(dim_blocks), + group_mem_bytes, + std::move(stream), + std::move(k), + hipLaunchParm{}, + std::forward(args)...); + } + + template + requires(Domain == {Ts...}) + static + inline + std::enable_if_t::value> grid_launch( + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + K k, + Ts&& ... args) + { + grid_launch_impl( + is_new_grid_launch_t{}, + std::move(num_blocks), + std::move(dim_blocks), + group_mem_bytes, + std::move(stream), + std::move(k), + std::forward(args)...); + } + + template + requires(Domain == {Ts...}) + static + inline + void grid_launch( + New_grid_launch_tag, + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + Ts&&... args) + { + grid_launch( + std::move(num_blocks), + std::move(dim_blocks), + group_mem_bytes, + std::move(stream), + [](decltype(std::decay_t(args))... f_args) [[hc]] { + k(f_args...); + }, + std::forward(args)...); + } + + template + requires(Domain == {Ts...}) + static + inline + void grid_launch( + Old_grid_launch_tag, + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + Ts&&... args) + { + grid_launch( + New_grid_launch_tag{}, + std::move(num_blocks), + std::move(dim_blocks), + group_mem_bytes, + std::move(stream), + hipLaunchParm{}, + std::forward(args)...); + } + + template + requires(Domain == {Ts...}) + static + inline + std::enable_if_t::value> grid_launch( + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + Ts&&... args) + { + grid_launch( + is_new_grid_launch_t{}, + std::move(num_blocks), + std::move(dim_blocks), + group_mem_bytes, + std::move(stream), + std::forward(args)...); + } + + template struct Wrapper; + + template + struct Wrapper::value>> { + template + requires(Domain == {Ts...}) + void operator()(Ts&&... args) const + { + grid_launch_impl( + is_new_grid_launch_t{}, + std::forward(args)...); + } + }; + + template + struct Wrapper::value>> { + template + void operator()(Ts&&...) const {} + }; +#warning "GGL hipLaunchKernel defined" + #define hipLaunchKernel( \ + kernel_name, \ + num_blocks, \ + dim_blocks, \ + group_mem_bytes, \ + stream, \ + ...) \ + { \ + using F = decltype(kernel_name); \ + if (!std::is_function::value) { \ + glo_tests::Wrapper{}( \ + num_blocks, \ + dim_blocks, \ + group_mem_bytes, \ + stream, \ + kernel_name, \ + ##__VA_ARGS__); \ + } \ + else { \ + glo_tests::grid_launch( \ + num_blocks, \ + dim_blocks, \ + group_mem_bytes, \ + stream, \ + ##__VA_ARGS__); \ + } \ + } +} diff --git a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp new file mode 100644 index 0000000000..ca3864911f --- /dev/null +++ b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp @@ -0,0 +1,96 @@ +// +// Created by alexv on 08/11/16. +// +#pragma once + +#include // For std::conditional, std::decay, std::enable_if, + // std::false_type, std result_of and std::true_type. +#include // For std::declval. + +namespace std +{ + #if (__cplusplus < 201406L) + template + using void_t = void; + + #if (__cplusplus < 201402L) + template + using enable_if_t = typename enable_if::type; + template + using conditional_t = typename conditional::type; + template + using decay_t = typename decay::type; + template + using result_of_t = typename result_of::type; + + template< + FunctionalProcedure F, + unsigned int n = 0u, + typename = void> + struct is_callable_impl : is_callable_impl {}; + + // Pointer to member function, call through non-pointer. + template + struct is_callable_impl< + F(C, Ts...), + 0u, + void_t().*declval())(declval()...))> + > : true_type { + }; + + // Pointer to member function, call through pointer. + template + struct is_callable_impl< + F(C, Ts...), + 1u, + void_t()).*declval())(declval()...))> + > : std::true_type { + }; + + // Pointer to member data, call through non-pointer, no args. + template + struct is_callable_impl< + F(C), + 2u, + void_t().*declval())> + > : true_type { + }; + + // Pointer to member data, call through pointer, no args. + template + struct is_callable_impl< + F(C), + 3u, + void_t().*declval())> + > : true_type { + }; + + // General call, n args. + template + struct is_callable_impl< + F(Ts...), + 4u, + void_t()(declval()...))> + > : true_type { + }; + + // Not callable. + template + struct is_callable_impl : false_type {}; + + template + struct is_callable : is_callable_impl {}; + #else + template + struct is_callable_impl : false_type {}; + + template + struct is_callable_impl< + F(Ts...), + void_t>> : true_type {}; + + template + struct is_callable : is_callable_impl {}; + #endif + #endif +} diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h index 65292951f0..6bf7a618d0 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h @@ -23,11 +23,11 @@ THE SOFTWARE. #ifndef HIP_LDG_H #define HIP_LDG_H -#if __HCC__ +#if defined __HCC__ #if __hcc_workweek__ >= 16164 #include "hip_vector_types.h" #include "host_defines.h" - +#warning "LDG header included" __device__ char __ldg(const char* ); __device__ char2 __ldg(const char2* ); diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index af294cdb53..9d0a43b1df 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -32,7 +32,6 @@ THE SOFTWARE. //--- // Top part of file can be compiled with any compiler - //#include #if __cplusplus #include @@ -40,7 +39,8 @@ THE SOFTWARE. #include #include #include -#endif +#endif//__cplusplus + // Define NVCC_COMPAT for CUDA compatibility #define NVCC_COMPAT #define CUDA_SUCCESS hipSuccess @@ -58,20 +58,30 @@ THE SOFTWARE. //--- // Remainder of this file only compiles with HCC -#ifdef __HCC__ +#if defined __HCC__ #include - -#if defined (GRID_LAUNCH_VERSION) and (GRID_LAUNCH_VERSION >= 20) -// Use field names for grid_launch 2.0 structure, if HCC supports GL 2.0. +//TODO-HCC-GL - change this to typedef. +//typedef grid_launch_parm hipLaunchParm ; +struct EmptyLaunchParm{}; +#ifndef GENERIC_GRID_LAUNCH + #define hipLaunchParm grid_launch_parm #else + #define hipLaunchParm EmptyLaunchParm +#endif //GENERIC_GRID_LAUNCH + +#if defined (GRID_LAUNCH_VERSION) and (GRID_LAUNCH_VERSION >= 20) || defined GENERIC_GRID_LAUNCH +#else // Use field names for grid_launch 2.0 structure, if HCC supports GL 2.0. #error (HCC must support GRID_LAUNCH_20) -#endif +#endif //GRID_LAUNCH_VERSION + +#endif //HCC + +#if defined GENERIC_GRID_LAUNCH && defined __HCC__ +#include "grid_launch_v2.hpp" +#endif//GENERIC_GRID_LAUNCH extern int HIP_TRACE_API; -//TODO-HCC-GL - change this to typedef. -//typedef grid_launch_parm hipLaunchParm ; -#define hipLaunchParm grid_launch_parm #ifdef __cplusplus //#include #include @@ -266,7 +276,7 @@ __device__ float __shfl(float input, int lane, int width); __device__ float __shfl_up(float input, unsigned int lane_delta, int width); __device__ float __shfl_down(float input, unsigned int lane_delta, int width); __device__ float __shfl_xor(float input, int lane_mask, int width); -#endif +#endif //__cplusplus __device__ unsigned __hip_ds_bpermute(int index, unsigned src); __device__ float __hip_ds_bpermutef(int index, float src); @@ -278,7 +288,7 @@ __device__ float __hip_ds_swizzlef(float src, int pattern); __device__ int __hip_move_dpp(int src, int dpp_ctrl, int row_mask, int bank_mask, bool bound_ctrl); -#endif +#endif //__HIP_ARCH_GFX803__ == 1 __host__ __device__ int min(int arg1, int arg2); __host__ __device__ int max(int arg1, int arg2); @@ -409,14 +419,15 @@ static inline __device__ void* memset(void* ptr, int val, size_t size) #define HIP_KERNEL_NAME(...) __VA_ARGS__ #define HIP_SYMBOL(X) #X -#ifdef __HCC_CPP__ +#if defined __HCC_CPP__ extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, dim3 grid, dim3 block, grid_launch_parm *lp, const char *kernelNameStr); extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, dim3 grid, size_t block, grid_launch_parm *lp, const char *kernelNameStr); extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, dim3 block, grid_launch_parm *lp, const char *kernelNameStr); extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, size_t block, grid_launch_parm *lp, const char *kernelNameStr); extern void ihipPostLaunchKernel(const char *kernelName, hipStream_t stream, grid_launch_parm &lp); - +#ifndef GENERIC_GRID_LAUNCH +#warning "Original hipLaunchKernel defined" // Due to multiple overloaded versions of ihipPreLaunchKernel, the numBlocks3D and blockDim3D can be either size_t or dim3 types #define hipLaunchKernel(_kernelName, _numBlocks3D, _blockDim3D, _groupMemBytes, _stream, ...) \ do {\ @@ -426,13 +437,13 @@ do {\ _kernelName (lp, ##__VA_ARGS__);\ ihipPostLaunchKernel(#_kernelName, trueStream, lp);\ } while(0) - +#endif //GENERIC_GRID_LAUNCH #elif defined (__HCC_C__) //TODO - develop C interface. -#endif +#endif //__HCC_CPP__ /** * extern __shared__ @@ -446,7 +457,6 @@ do {\ #define HIP_DYNAMIC_SHARED_ATTRIBUTE ADDRESS_SPACE_3 -#endif // __HCC__ /** @@ -470,4 +480,4 @@ do {\ -#endif +#endif//HIP_HCC_DETAIL_RUNTIME_H diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index 0d3ecc6613..c769548214 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -27,7 +27,8 @@ THE SOFTWARE. * @file hcc_detail/hip_runtime_api.h * @brief Contains C function APIs for HIP runtime. This file does not use any HCC builtin or special language extensions (-hc mode) ; those functions in hip_runtime.h. */ - +// guard for grid_launch_v2 +#define GENERIC_GRID_LAUNCH #include #include #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index 93695a0038..d7128d6fab 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -37,7 +37,14 @@ THE SOFTWARE. #define __host__ __attribute__((cpu)) #define __device__ __attribute__((hc)) +#warning "HOST DEFINE header included" +#ifndef GENERIC_GRID_LAUNCH +#warning "original global define reached" #define __global__ __attribute__((hc_grid_launch)) __attribute__((used)) +#else +#warning "GGL global define reached" +#define __global__ [[hc]] __attribute__((weak)) +#endif //GENERIC_GRID_LAUNCH #define __noinline__ __attribute__((noinline)) #define __forceinline__ __attribute__((always_inline)) diff --git a/projects/clr/hipamd/samples/0_Intro/square/square.hipref.cpp b/projects/clr/hipamd/samples/0_Intro/square/square.hipref.cpp index e694bfb8a4..118f8acf13 100644 --- a/projects/clr/hipamd/samples/0_Intro/square/square.hipref.cpp +++ b/projects/clr/hipamd/samples/0_Intro/square/square.hipref.cpp @@ -83,7 +83,7 @@ int main(int argc, char *argv[]) const unsigned threadsPerBlock = 256; printf ("info: launch 'vector_square' kernel\n"); - hipLaunchKernel(vector_square, dim3(blocks), dim3(threadsPerBlock), 0, 0, C_d, A_d, N); + hipLaunchKernel(vector_square, dim3(blocks), dim3(threadsPerBlock), 0, nullptr, C_d, A_d, N); printf ("info: copy Device2Host\n"); CHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost)); diff --git a/projects/clr/hipamd/src/hip_hcc.cpp b/projects/clr/hipamd/src/hip_hcc.cpp index 760f46046a..4d922e65e7 100644 --- a/projects/clr/hipamd/src/hip_hcc.cpp +++ b/projects/clr/hipamd/src/hip_hcc.cpp @@ -1556,7 +1556,6 @@ void ihipPostLaunchKernel(const char *kernelName, hipStream_t stream, grid_launc MARKER_END(); } - //================================================================================================= // HIP API Implementation // diff --git a/projects/clr/hipamd/src/trace_helper.h b/projects/clr/hipamd/src/trace_helper.h index 3bf2857c3a..abff491916 100644 --- a/projects/clr/hipamd/src/trace_helper.h +++ b/projects/clr/hipamd/src/trace_helper.h @@ -28,7 +28,6 @@ THE SOFTWARE. #include #include #include - //--- // Helper functions to convert HIP function arguments into strings. // Handles POD data types as well as enumerations (ie hipMemcpyKind). @@ -71,7 +70,7 @@ inline std::string ToString(hipEvent_t v) ss << v; return ss.str(); }; - +#ifndef GENERIC_GRID_LAUNCH // hipStream_t template <> inline std::string ToString(hipStream_t v) @@ -85,6 +84,7 @@ inline std::string ToString(hipStream_t v) return ss.str(); }; +#endif //GENERIC_GRID_LAUNCH // hipMemcpyKind specialization template <> From a8c91ca37970385aa9b73343c647254ab48bd44d Mon Sep 17 00:00:00 2001 From: pensun Date: Fri, 17 Mar 2017 19:57:20 +0000 Subject: [PATCH 09/56] Change the #define of GENERIC_GRID_LAUNCH to take valueat compilation, disable warning messages Change-Id: Ic6c011529e26de359bcda1e7083727e7ee52887b [ROCm/clr commit: faf0fbebe9d21671435f4c24be076fd4445ee945] --- .../include/hip/hcc_detail/grid_launch_v2.hpp | 2 +- .../clr/hipamd/include/hip/hcc_detail/hip_ldg.h | 1 - .../clr/hipamd/include/hip/hcc_detail/hip_runtime.h | 8 ++++---- .../hipamd/include/hip/hcc_detail/hip_runtime_api.h | 6 ++++-- .../hipamd/include/hip/hcc_detail/host_defines.h | 13 +++++++++---- projects/clr/hipamd/src/trace_helper.h | 2 -- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index ab11433a5b..9f7492b4d5 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -196,7 +196,7 @@ namespace glo_tests template void operator()(Ts&&...) const {} }; -#warning "GGL hipLaunchKernel defined" +//#warning "GGL hipLaunchKernel defined" #define hipLaunchKernel( \ kernel_name, \ num_blocks, \ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h index 6bf7a618d0..5c33ee773f 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h @@ -27,7 +27,6 @@ THE SOFTWARE. #if __hcc_workweek__ >= 16164 #include "hip_vector_types.h" #include "host_defines.h" -#warning "LDG header included" __device__ char __ldg(const char* ); __device__ char2 __ldg(const char2* ); diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 9d0a43b1df..673807fcd2 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -63,20 +63,20 @@ THE SOFTWARE. //TODO-HCC-GL - change this to typedef. //typedef grid_launch_parm hipLaunchParm ; struct EmptyLaunchParm{}; -#ifndef GENERIC_GRID_LAUNCH +#if GENERIC_GRID_LAUNCH == 0 #define hipLaunchParm grid_launch_parm #else #define hipLaunchParm EmptyLaunchParm #endif //GENERIC_GRID_LAUNCH -#if defined (GRID_LAUNCH_VERSION) and (GRID_LAUNCH_VERSION >= 20) || defined GENERIC_GRID_LAUNCH +#if defined (GRID_LAUNCH_VERSION) and (GRID_LAUNCH_VERSION >= 20) || GENERIC_GRID_LAUNCH == 1 #else // Use field names for grid_launch 2.0 structure, if HCC supports GL 2.0. #error (HCC must support GRID_LAUNCH_20) #endif //GRID_LAUNCH_VERSION #endif //HCC -#if defined GENERIC_GRID_LAUNCH && defined __HCC__ +#if GENERIC_GRID_LAUNCH==1 && defined __HCC__ #include "grid_launch_v2.hpp" #endif//GENERIC_GRID_LAUNCH @@ -426,7 +426,7 @@ extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, dim3 blo extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, size_t block, grid_launch_parm *lp, const char *kernelNameStr); extern void ihipPostLaunchKernel(const char *kernelName, hipStream_t stream, grid_launch_parm &lp); -#ifndef GENERIC_GRID_LAUNCH +#if GENERIC_GRID_LAUNCH == 0 #warning "Original hipLaunchKernel defined" // Due to multiple overloaded versions of ihipPreLaunchKernel, the numBlocks3D and blockDim3D can be either size_t or dim3 types #define hipLaunchKernel(_kernelName, _numBlocks3D, _blockDim3D, _groupMemBytes, _stream, ...) \ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index c769548214..01fea548b8 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -27,12 +27,14 @@ THE SOFTWARE. * @file hcc_detail/hip_runtime_api.h * @brief Contains C function APIs for HIP runtime. This file does not use any HCC builtin or special language extensions (-hc mode) ; those functions in hip_runtime.h. */ -// guard for grid_launch_v2 -#define GENERIC_GRID_LAUNCH #include #include #include +#ifndef GENERIC_GRID_LAUNCH +#define GENERIC_GRID_LAUNCH 0 +#endif + #include #include #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index d7128d6fab..6804ba464b 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -30,6 +30,11 @@ THE SOFTWARE. #define USE_PROMOTE_FREE_HCC 0 +// Add guard to Generic Grid Launch method +#ifndef GENERIC_GRID_LAUNCH +#define GENERIC_GRID_LAUNCH 0 +#endif + #ifdef __HCC__ /** * Function and kernel markers @@ -37,12 +42,12 @@ THE SOFTWARE. #define __host__ __attribute__((cpu)) #define __device__ __attribute__((hc)) -#warning "HOST DEFINE header included" -#ifndef GENERIC_GRID_LAUNCH -#warning "original global define reached" +//#warning "HOST DEFINE header included" +#if GENERIC_GRID_LAUNCH == 0 +//#warning "original global define reached" #define __global__ __attribute__((hc_grid_launch)) __attribute__((used)) #else -#warning "GGL global define reached" +//#warning "GGL global define reached" #define __global__ [[hc]] __attribute__((weak)) #endif //GENERIC_GRID_LAUNCH diff --git a/projects/clr/hipamd/src/trace_helper.h b/projects/clr/hipamd/src/trace_helper.h index abff491916..d49cb67be0 100644 --- a/projects/clr/hipamd/src/trace_helper.h +++ b/projects/clr/hipamd/src/trace_helper.h @@ -70,7 +70,6 @@ inline std::string ToString(hipEvent_t v) ss << v; return ss.str(); }; -#ifndef GENERIC_GRID_LAUNCH // hipStream_t template <> inline std::string ToString(hipStream_t v) @@ -84,7 +83,6 @@ inline std::string ToString(hipStream_t v) return ss.str(); }; -#endif //GENERIC_GRID_LAUNCH // hipMemcpyKind specialization template <> From d5f632f2716354a12a415fb51efd8a1c0f76cc7d Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Fri, 17 Mar 2017 15:03:03 -0500 Subject: [PATCH 10/56] Disable additional debug warning message Change-Id: Ic5c374589bfad387a7c4c5346430a490e2c6e2a7 [ROCm/clr commit: 2585812fba9c59670fb10d43acef5661f9662e5d] --- .../hipamd/include/hip/hcc_detail/hip_runtime.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 673807fcd2..870dcd0b34 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -49,8 +49,8 @@ THE SOFTWARE. #if USE_PROMOTE_FREE_HCC == 1 -#define ADDRESS_SPACE_1 -#define ADDRESS_SPACE_3 +#define ADDRESS_SPACE_1 +#define ADDRESS_SPACE_3 #else #define ADDRESS_SPACE_1 __attribute__((address_space(1))) #define ADDRESS_SPACE_3 __attribute__((address_space(3))) @@ -58,7 +58,7 @@ THE SOFTWARE. //--- // Remainder of this file only compiles with HCC -#if defined __HCC__ +#if defined __HCC__ #include //TODO-HCC-GL - change this to typedef. //typedef grid_launch_parm hipLaunchParm ; @@ -74,7 +74,7 @@ struct EmptyLaunchParm{}; #error (HCC must support GRID_LAUNCH_20) #endif //GRID_LAUNCH_VERSION -#endif //HCC +#endif //HCC #if GENERIC_GRID_LAUNCH==1 && defined __HCC__ #include "grid_launch_v2.hpp" @@ -419,7 +419,7 @@ static inline __device__ void* memset(void* ptr, int val, size_t size) #define HIP_KERNEL_NAME(...) __VA_ARGS__ #define HIP_SYMBOL(X) #X -#if defined __HCC_CPP__ +#if defined __HCC_CPP__ extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, dim3 grid, dim3 block, grid_launch_parm *lp, const char *kernelNameStr); extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, dim3 grid, size_t block, grid_launch_parm *lp, const char *kernelNameStr); extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, dim3 block, grid_launch_parm *lp, const char *kernelNameStr); @@ -427,7 +427,7 @@ extern hipStream_t ihipPreLaunchKernel(hipStream_t stream, size_t grid, size_t b extern void ihipPostLaunchKernel(const char *kernelName, hipStream_t stream, grid_launch_parm &lp); #if GENERIC_GRID_LAUNCH == 0 -#warning "Original hipLaunchKernel defined" +//#warning "Original hipLaunchKernel defined" // Due to multiple overloaded versions of ihipPreLaunchKernel, the numBlocks3D and blockDim3D can be either size_t or dim3 types #define hipLaunchKernel(_kernelName, _numBlocks3D, _blockDim3D, _groupMemBytes, _stream, ...) \ do {\ @@ -437,13 +437,13 @@ do {\ _kernelName (lp, ##__VA_ARGS__);\ ihipPostLaunchKernel(#_kernelName, trueStream, lp);\ } while(0) -#endif //GENERIC_GRID_LAUNCH +#endif //GENERIC_GRID_LAUNCH #elif defined (__HCC_C__) //TODO - develop C interface. -#endif //__HCC_CPP__ +#endif //__HCC_CPP__ /** * extern __shared__ From 35d829773d2667fa93e514c53121269f03f31a72 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Fri, 17 Mar 2017 18:26:10 -0500 Subject: [PATCH 11/56] added support for lgammaf and lgamma 1. Implementation inside HIP Change-Id: I657263b7276a57c56081d3336fef816b5f204eff [ROCm/clr commit: 52859a8a40e64ae310286e8d1eb2f4c468c7d6fd] --- .../include/hip/hcc_detail/math_functions.h | 2 +- projects/clr/hipamd/src/math_functions.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/math_functions.h b/projects/clr/hipamd/include/hip/hcc_detail/math_functions.h index 2cc4ef81bd..8455509732 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/math_functions.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/math_functions.h @@ -66,7 +66,7 @@ __device__ float j0f(float x); __device__ float j1f(float x); __device__ float jnf(int n, float x); __device__ float ldexpf(float x, int exp); -//__device__ float lgammaf(float x); +__device__ float lgammaf(float x); __device__ long long int llrintf(float x); __device__ long long int llroundf(float x); __device__ float log10f(float x); diff --git a/projects/clr/hipamd/src/math_functions.cpp b/projects/clr/hipamd/src/math_functions.cpp index 6e919b3926..92cc8689fc 100644 --- a/projects/clr/hipamd/src/math_functions.cpp +++ b/projects/clr/hipamd/src/math_functions.cpp @@ -188,8 +188,12 @@ __device__ float ldexpf(float x, int exp) } __device__ float lgammaf(float x) { - int sign; - return hc::precise_math::lgammaf(x, &sign); + float val = 0.0f; + float y = x - 1; + while(y > 0){ + val += logf(y--); + } + return val; } __device__ long long int llrintf(float x) { @@ -570,8 +574,12 @@ __device__ double ldexp(double x, int exp) } __device__ double lgamma(double x) { - int sign; - return hc::precise_math::lgamma(x, &sign); + double val = 0.0; + double y = x - 1; + while(y > 0){ + val += log(y--); + } + return val; } __device__ long long int llrint(double x) { From bd348f5248bd1812a4ceba74d5b0bb27f174e0ef Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Mon, 20 Mar 2017 21:03:18 +0300 Subject: [PATCH 12/56] [HIP] [FIX] Fix GCC build. [ROCm/clr commit: 70ed1014ad04463f46be189fe8b2ba62d447666f] --- projects/clr/hipamd/hipify-clang/src/Cuda2Hip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/hipify-clang/src/Cuda2Hip.cpp b/projects/clr/hipamd/hipify-clang/src/Cuda2Hip.cpp index 8caac787e8..6c24fbf288 100644 --- a/projects/clr/hipamd/hipify-clang/src/Cuda2Hip.cpp +++ b/projects/clr/hipamd/hipify-clang/src/Cuda2Hip.cpp @@ -2271,7 +2271,7 @@ public: StringRef repName = found->second.hipName; DEBUG(dbgs() << "Identifier " << name << " found as an actual argument in expansion of macro " - << macroName << "\n" + << MacroNameTok.getIdentifierInfo()->getName() << "\n" << "will be replaced with: " << repName << "\n"); size_t length = name.size(); SourceLocation sl = tok.getLocation(); From 5c284999b238754ddf9de840ede70ca174ba88b9 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Mon, 20 Mar 2017 15:44:28 -0500 Subject: [PATCH 13/56] Add document for switching to GGL in hip_faq.md Change-Id: I83d9fd3e76d21ab572949c3a446ac3898acb3ded [ROCm/clr commit: 3bd73d6280709a6c02eeef080e33ee53699cae69] --- projects/clr/hipamd/docs/markdown/hip_faq.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/projects/clr/hipamd/docs/markdown/hip_faq.md b/projects/clr/hipamd/docs/markdown/hip_faq.md index d7235c4ebc..1543241f6d 100644 --- a/projects/clr/hipamd/docs/markdown/hip_faq.md +++ b/projects/clr/hipamd/docs/markdown/hip_faq.md @@ -235,3 +235,18 @@ Unlike CUDA, in HCC, for functions defined in the header files, the keyword of " Thus, if failed to define "static" keyword, you might see a lot of "symbol multiply defined!" errors at compilation. The workaround is to explicitly add the keyword of "static" before any functions that were defined as "__forceinline__". + +### How do I enable HIP Generic Grid Launch option? +Generic Grid Launch(GGL) provide a second choice for kernel launch. +To enable it, either change the default value of GENERIC_GRID_LAUNCH to 1 in the following to header files and rebuild HIP: +$HIP/include/hip/hcc_detail/hip_runtime_api.h +$HIP/include/hip/hcc_detail/host_defines.h +Or pass "-DGENERIC_GRID_LAUNCH=1" to hipcc at application compilation time. + +There are some limitation/assumptions of GGL implementation right now: +1. GGL was only tested with Ubuntu16.04, assuming HCC and HIP only link against libstdc++ but not libc++. +2. GGL currently requires templated kernel fucntions passed to hipLaunchKernel to be specialized. e.g.: + +``` +hipLaunchKernel(vector_square, dim3(blocks), dim3(threadsPerBlock), 0, nullptr, C_d, A_d, N); +``` From 4dbdf4e7eb66871b135cfb46d9108cf6259f181d Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Mon, 20 Mar 2017 15:50:10 -0500 Subject: [PATCH 14/56] Add link to GGL document in hip_faq.md Change-Id: I9f7f0200a06976d580be334c21640c816f812ebb [ROCm/clr commit: 1fd2e281d0aec55beb72b593835ded5e05673232] --- projects/clr/hipamd/docs/markdown/hip_faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/docs/markdown/hip_faq.md b/projects/clr/hipamd/docs/markdown/hip_faq.md index 1543241f6d..01b05ed223 100644 --- a/projects/clr/hipamd/docs/markdown/hip_faq.md +++ b/projects/clr/hipamd/docs/markdown/hip_faq.md @@ -26,6 +26,7 @@ - [How do I trace HIP application flow?](#how-do-i-trace-hip-application-flow) * [Using CodeXL markers for HIP Functions](#using-codexl-markers-for-hip-functions) * [Using HIP_TRACE_API](#using-hip_trace_api) +- [How do I enable HIP Generic Grid Launch option?](#how-do-i-enable-hip-generic-grid-launch-option) @@ -235,7 +236,6 @@ Unlike CUDA, in HCC, for functions defined in the header files, the keyword of " Thus, if failed to define "static" keyword, you might see a lot of "symbol multiply defined!" errors at compilation. The workaround is to explicitly add the keyword of "static" before any functions that were defined as "__forceinline__". - ### How do I enable HIP Generic Grid Launch option? Generic Grid Launch(GGL) provide a second choice for kernel launch. To enable it, either change the default value of GENERIC_GRID_LAUNCH to 1 in the following to header files and rebuild HIP: From cb31fbab620e401ae4876e5d686180679fed410f Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Mon, 20 Mar 2017 16:34:24 -0500 Subject: [PATCH 15/56] merge Alex' GGL fix for non-specialized kernel function launch Change-Id: Idbf7ca669c38ee5c0f654bcabdd1b498abb29f69 [ROCm/clr commit: e21d4f03f1c094699abc0b21cbbd6bd7bd2c5718] --- .../include/hip/hcc_detail/concepts.hpp | 22 ++ .../include/hip/hcc_detail/grid_launch_v2.hpp | 203 ++++++++++++++---- .../hipamd/include/hip/hcc_detail/helpers.hpp | 46 +++- 3 files changed, 227 insertions(+), 44 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp b/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp index 373ec15411..c746c1cfe6 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + // // Created by alexv on 25/10/16. // diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index 9f7492b4d5..02f214bd67 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + // // Created by alexv on 25/10/16. // @@ -9,14 +31,10 @@ #include "hc.hpp" #include "hcc_acc.h" -//#include -//#include - #include #include #include - namespace glo_tests { namespace @@ -112,6 +130,26 @@ namespace glo_tests std::forward(args)...); } + namespace + { + template + constexpr + inline + T&& forward(std::remove_reference_t& x) [[hc]] + { + return static_cast(x); + } + + template + struct Forwarder { + template + void operator()(Ts&&...args) const [[hc]] + { + k(forward(args)...); + } + }; + } + template requires(Domain == {Ts...}) static @@ -124,14 +162,13 @@ namespace glo_tests hipStream_t stream, Ts&&... args) { - grid_launch( + grid_launch_impl( + New_grid_launch_tag{}, std::move(num_blocks), std::move(dim_blocks), group_mem_bytes, std::move(stream), - [](decltype(std::decay_t(args))... f_args) [[hc]] { - k(f_args...); - }, + Forwarder{}, std::forward(args)...); } @@ -177,26 +214,116 @@ namespace glo_tests std::forward(args)...); } - template struct Wrapper; + namespace + { + template struct Wrapper; - template - struct Wrapper::value>> { - template - requires(Domain == {Ts...}) - void operator()(Ts&&... args) const - { - grid_launch_impl( - is_new_grid_launch_t{}, - std::forward(args)...); + template + struct Wrapper::value>> { + template + requires(Domain == {Ts...}) + void operator()(Ts&&... args) const + { + grid_launch(std::forward(args)...); + } + }; + + template + struct Wrapper::value>> { + template + void operator()(Ts&&...) const {} + }; + } + + #define make_lambda_wrapper9(kernel_name, p0, p1, p2, p3, p4, p5, p6, p7) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_) [[hc]] { \ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_); \ } - }; + #define make_lambda_wrapper8(kernel_name, p0, p1, p2, p3, p4, p5, p6) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_) [[hc]] { \ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_); \ + } + #define make_lambda_wrapper7(kernel_name, p0, p1, p2, p3, p4, p5) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_) [[hc]] { \ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_); \ + } + #define make_lambda_wrapper6(kernel_name, p0, p1, p2, p3, p4) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_) [[hc]] { \ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_); \ + } + #define make_lambda_wrapper5(kernel_name, p0, p1, p2, p3) \ + [](std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_) [[hc]] { \ + kernel_name(_p0_, _p1_, _p2_, _p3_); \ + } + #define make_lambda_wrapper4(kernel_name, p0, p1, p2) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_) [[hc]] { \ + kernel_name(_p0_, _p1_, _p2_); \ + } + #define make_lambda_wrapper3(kernel_name, p0, p1) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_) [[hc]] { \ + kernel_name(_p0_, _p1_); \ + } + #define make_lambda_wrapper2(kernel_name, p0) \ + [](std::decay_t _p0_) [[hc]] { \ + kernel_name(_p0_); \ + } + #define make_lambda_wrapper1(kernel_name) \ + []() [[hc]] { kernel_name(lp); } - template - struct Wrapper::value>> { - template - void operator()(Ts&&...) const {} - }; -//#warning "GGL hipLaunchKernel defined" + #define make_lambda_wrapper(...) \ + overload_macro(make_lambda_wrapper, __VA_ARGS__) + + #define hipLaunchKernelV3( \ + kernel_name, \ + num_blocks, \ + dim_blocks, \ + group_mem_bytes, \ + stream, \ + ...) \ + { \ + glo_tests::grid_launch( \ + num_blocks, \ + dim_blocks, \ + group_mem_bytes, \ + stream, \ + make_lambda_wrapper(kernel_name, __VA_ARGS__), \ + ##__VA_ARGS__); \ + } +#warning "GGL hipLaunchKernel Reached" #define hipLaunchKernel( \ kernel_name, \ num_blocks, \ @@ -205,23 +332,13 @@ namespace glo_tests stream, \ ...) \ { \ - using F = decltype(kernel_name); \ - if (!std::is_function::value) { \ - glo_tests::Wrapper{}( \ - num_blocks, \ - dim_blocks, \ - group_mem_bytes, \ - stream, \ - kernel_name, \ - ##__VA_ARGS__); \ - } \ - else { \ - glo_tests::grid_launch( \ - num_blocks, \ - dim_blocks, \ - group_mem_bytes, \ - stream, \ - ##__VA_ARGS__); \ - } \ + hipLaunchKernelV3( \ + kernel_name, \ + num_blocks, \ + dim_blocks, \ + group_mem_bytes, \ + stream, \ + hipLaunchParm{}, \ + ##__VA_ARGS__); \ } } diff --git a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp index ca3864911f..ea9217977b 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + // // Created by alexv on 08/11/16. // @@ -22,7 +44,8 @@ namespace std using decay_t = typename decay::type; template using result_of_t = typename result_of::type; - + template + using remove_reference_t = typename remove_reference::type; template< FunctionalProcedure F, unsigned int n = 0u, @@ -92,5 +115,26 @@ namespace std template struct is_callable : is_callable_impl {}; #endif + template + struct disjunction : false_type {}; + template + struct disjunction : B1 {}; + template + struct disjunction + : conditional_t> + {}; #endif } + +namespace glo_tests // Only for documentation, macros ignore namespaces. +{ + #define count_macro_args_impl(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _n, ...) _n + #define count_macro_args(...) \ + count_macro_args_impl(,##__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) + + #define overloaded_macro_expand(macro, arg_cnt) macro##arg_cnt + #define overload_macro_impl(macro, arg_cnt) \ + overloaded_macro_expand(macro, arg_cnt) + #define overload_macro(macro, ...) \ + overload_macro_impl(macro, count_macro_args(__VA_ARGS__)) (__VA_ARGS__) +} From db4bedeafc3596d5284a69e8fafc2d6cb8ae4923 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Mon, 20 Mar 2017 17:03:21 -0500 Subject: [PATCH 16/56] revert workaround for square sample and update doc on GGL Change-Id: I731c68ca4111e7dc2e45bef51c4cad2c23fc81f8 [ROCm/clr commit: 14f8c7cf74b560657e5401899d3c2322ac7dd7bf] --- projects/clr/hipamd/docs/markdown/hip_faq.md | 8 +------- .../clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp | 1 - .../clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h | 2 +- projects/clr/hipamd/include/hip/hcc_detail/host_defines.h | 2 +- .../clr/hipamd/samples/0_Intro/square/square.hipref.cpp | 2 +- 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/projects/clr/hipamd/docs/markdown/hip_faq.md b/projects/clr/hipamd/docs/markdown/hip_faq.md index 01b05ed223..5ad8d9e8a9 100644 --- a/projects/clr/hipamd/docs/markdown/hip_faq.md +++ b/projects/clr/hipamd/docs/markdown/hip_faq.md @@ -243,10 +243,4 @@ $HIP/include/hip/hcc_detail/hip_runtime_api.h $HIP/include/hip/hcc_detail/host_defines.h Or pass "-DGENERIC_GRID_LAUNCH=1" to hipcc at application compilation time. -There are some limitation/assumptions of GGL implementation right now: -1. GGL was only tested with Ubuntu16.04, assuming HCC and HIP only link against libstdc++ but not libc++. -2. GGL currently requires templated kernel fucntions passed to hipLaunchKernel to be specialized. e.g.: - -``` -hipLaunchKernel(vector_square, dim3(blocks), dim3(threadsPerBlock), 0, nullptr, C_d, A_d, N); -``` +GGL was only tested with Ubuntu16.04, assuming HCC and HIP only link against libstdc++ but not libc++. diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index 02f214bd67..9ce0722496 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -323,7 +323,6 @@ namespace glo_tests make_lambda_wrapper(kernel_name, __VA_ARGS__), \ ##__VA_ARGS__); \ } -#warning "GGL hipLaunchKernel Reached" #define hipLaunchKernel( \ kernel_name, \ num_blocks, \ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index 01fea548b8..2ff4a70802 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -32,7 +32,7 @@ THE SOFTWARE. #include #ifndef GENERIC_GRID_LAUNCH -#define GENERIC_GRID_LAUNCH 0 +#define GENERIC_GRID_LAUNCH 0 #endif #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index 6804ba464b..28c9268f59 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -32,7 +32,7 @@ THE SOFTWARE. // Add guard to Generic Grid Launch method #ifndef GENERIC_GRID_LAUNCH -#define GENERIC_GRID_LAUNCH 0 +#define GENERIC_GRID_LAUNCH 0 #endif #ifdef __HCC__ diff --git a/projects/clr/hipamd/samples/0_Intro/square/square.hipref.cpp b/projects/clr/hipamd/samples/0_Intro/square/square.hipref.cpp index 118f8acf13..963ab63260 100644 --- a/projects/clr/hipamd/samples/0_Intro/square/square.hipref.cpp +++ b/projects/clr/hipamd/samples/0_Intro/square/square.hipref.cpp @@ -83,7 +83,7 @@ int main(int argc, char *argv[]) const unsigned threadsPerBlock = 256; printf ("info: launch 'vector_square' kernel\n"); - hipLaunchKernel(vector_square, dim3(blocks), dim3(threadsPerBlock), 0, nullptr, C_d, A_d, N); + hipLaunchKernel(vector_square, dim3(blocks), dim3(threadsPerBlock), 0, nullptr, C_d, A_d, N); printf ("info: copy Device2Host\n"); CHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost)); From 02c7cb1c3d0a71124c45ba7ebc80542061b32f92 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Tue, 21 Mar 2017 21:01:05 +0300 Subject: [PATCH 17/56] [HIPIFY] Switch building from gcc to clang 3.8. [ROCm/clr commit: 3cd0e53a22f0bed47b7c34bffee69e2375ab83a8] --- projects/clr/hipamd/hipify-clang/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/clr/hipamd/hipify-clang/CMakeLists.txt b/projects/clr/hipamd/hipify-clang/CMakeLists.txt index 14dc9c5d17..a02b91407f 100644 --- a/projects/clr/hipamd/hipify-clang/CMakeLists.txt +++ b/projects/clr/hipamd/hipify-clang/CMakeLists.txt @@ -19,6 +19,9 @@ else() add_llvm_executable(hipify-clang src/Cuda2Hip.cpp) find_program(LIT_COMMAND lit) + set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++) + set(CMAKE_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang) + # Link against LLVM and CLANG tools libraries target_link_libraries(hipify-clang clangASTMatchers From 130545d322986192105f09c4e07a385474578948 Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Tue, 21 Mar 2017 23:48:04 +0530 Subject: [PATCH 18/56] Fix for hipMemcpyFromSymbol (sync) Change-Id: I66afec5443ce904a63ced1fafece5144ca59393e [ROCm/clr commit: e22044de36dd76d53b460cf126227a0d26aa3e1b] --- projects/clr/hipamd/src/hip_hcc.cpp | 10 +++++----- projects/clr/hipamd/src/hip_hcc.h | 2 +- projects/clr/hipamd/src/hip_memory.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/clr/hipamd/src/hip_hcc.cpp b/projects/clr/hipamd/src/hip_hcc.cpp index 4d922e65e7..17cffbc013 100644 --- a/projects/clr/hipamd/src/hip_hcc.cpp +++ b/projects/clr/hipamd/src/hip_hcc.cpp @@ -1872,19 +1872,19 @@ void ihipStream_t::addSymbolPtrToTracker(hc::accelerator& acc, void* ptr, size_t hc::am_memtracker_add(ptr, ptrInfo); } -void ihipStream_t::lockedSymbolCopySync(hc::accelerator &acc, void* dst, void* src, size_t sizeBytes, unsigned kind) +void ihipStream_t::lockedSymbolCopySync(hc::accelerator &acc, void* dst, void* src, size_t sizeBytes, size_t offset, unsigned kind) { if(kind == hipMemcpyHostToHost){ - acc.memcpy_symbol(dst, (void*)src, sizeBytes, Kalmar::hcMemcpyHostToHost); + acc.memcpy_symbol(dst, (void*)src, sizeBytes, offset, Kalmar::hcMemcpyHostToHost); } if(kind == hipMemcpyHostToDevice){ - acc.memcpy_symbol(dst, (void*)src, sizeBytes); + acc.memcpy_symbol(dst, (void*)src, sizeBytes, offset); } if(kind == hipMemcpyDeviceToDevice){ - acc.memcpy_symbol(dst, (void*)src, sizeBytes, Kalmar::hcMemcpyDeviceToDevice); + acc.memcpy_symbol(dst, (void*)src, sizeBytes, offset, Kalmar::hcMemcpyDeviceToDevice); } if(kind == hipMemcpyDeviceToHost){ - acc.memcpy_symbol(dst, (void*)src, sizeBytes, Kalmar::hcMemcpyDeviceToHost); + acc.memcpy_symbol((void*) src, (void*)dst, sizeBytes, offset, Kalmar::hcMemcpyDeviceToHost); } } diff --git a/projects/clr/hipamd/src/hip_hcc.h b/projects/clr/hipamd/src/hip_hcc.h index b23aead072..1c287bfc44 100644 --- a/projects/clr/hipamd/src/hip_hcc.h +++ b/projects/clr/hipamd/src/hip_hcc.h @@ -503,7 +503,7 @@ public: void locked_copySync (void* dst, const void* src, size_t sizeBytes, unsigned kind, bool resolveOn = true); void locked_copyAsync(void* dst, const void* src, size_t sizeBytes, unsigned kind); - void lockedSymbolCopySync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, unsigned kind); + void lockedSymbolCopySync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, size_t offset, unsigned kind); void lockedSymbolCopyAsync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, unsigned kind); //--- diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index a92d11b847..b888c5054c 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -497,7 +497,7 @@ hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t cou if(kind == hipMemcpyHostToDevice || kind == hipMemcpyDeviceToHost || kind == hipMemcpyDeviceToDevice || kind == hipMemcpyHostToHost) { - stream->lockedSymbolCopySync(acc, dst, (void*)src, count + offset, kind); + stream->lockedSymbolCopySync(acc, dst, (void*)src, count, offset, kind); // acc.memcpy_symbol(dst, (void*)src, count+offset); } else { return ihipLogStatus(hipErrorInvalidValue); @@ -532,7 +532,7 @@ hipError_t hipMemcpyFromSymbol(void* dst, const char* symbolName, size_t count, if(kind == hipMemcpyHostToDevice || kind == hipMemcpyDeviceToHost || kind == hipMemcpyDeviceToDevice || kind == hipMemcpyHostToHost) { - stream->lockedSymbolCopySync(acc, dst, (void*)src, count + offset, kind); + stream->lockedSymbolCopySync(acc, dst, (void*)src, count, offset, kind); } else { return ihipLogStatus(hipErrorInvalidValue); From fa70da22edfef15141ead632db806cbfcde67544 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Tue, 21 Mar 2017 14:22:49 -0500 Subject: [PATCH 19/56] fixed paths to find llvm Change-Id: I0a4af8cea2f44fea011d09fc300e382984746d17 [ROCm/clr commit: a19bce16e4e62cf2511cd02802bfc2517d356ed7] --- projects/clr/hipamd/CMakeLists.txt | 11 ++--------- projects/clr/hipamd/bin/hipcc | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index a1887d0cb5..93f36d97f1 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -63,14 +63,7 @@ if(HIP_PLATFORM STREQUAL "hcc") set(HCC_HOME $ENV{HCC_HOME} CACHE PATH "Path to which HCC has been installed") endif() endif() - # Determine LLVM_HOME - if(NOT DEFINED LLVM_HOME) - if(NOT DEFINED ENV{LLVM_HOME}) - set(LLVM_HOME "/opt/rocm/llvm" CACHE PATH "Path to which LLVM has been installed") - else() - set(LLVM_HOME $ENV{LLVM_HOME} CACHE PATH "Path to which LLVM has been installed") - endif() - endif() + if(DEFINED ENV{HIP_DEVELOPER}) add_to_config(_buildInfo HCC_HOME) endif() @@ -197,7 +190,7 @@ if(HIP_PLATFORM STREQUAL "hcc") execute_process(COMMAND ${HCC_HOME}/bin/hcc-config --ldflags OUTPUT_VARIABLE HCC_LD_FLAGS) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${HCC_LD_FLAGS} -Wl,-Bsymbolic") - find_package(LLVM HINTS ${LLVM_HOME}) + find_package(LLVM HINTS "/opt/rocm/llvm") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --amdgpu-target=gfx701 --amdgpu-target=gfx801 --amdgpu-target=gfx802 --amdgpu-target=gfx803 --amdgpu-target=gfx900") add_library(hip_hcc SHARED ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc PRIVATE hc_am) diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index 4c71347cf7..e99be07ffd 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/bin/hipcc @@ -103,7 +103,7 @@ if ($HIP_PLATFORM eq "hcc") { $HIPLDFLAGS = `${HCC_HOME}/bin/hcc-config --ldflags`; - $LLVM_HOME = $ENV{'LLVM_HOME'}; + $LLVM_HOME = "/opt/rocm/llvm"; #### GCC system includes workaround #### $HCC_WA_FLAGS = " "; From 962ac22fe020a0842e13175b0842f2b27aca8c20 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Tue, 21 Mar 2017 12:26:57 -0500 Subject: [PATCH 20/56] Update GGL implementation to extended overload set for make_lambda_wrapper Change-Id: I949f113671ddf155db8689e8a7f23d415839a7b5 [ROCm/clr commit: 6b9be30b708e1b3c1157d0eb2c37136833206c2e] --- .../include/hip/hcc_detail/grid_launch_v2.hpp | 332 ++++++++++++++++-- .../hipamd/include/hip/hcc_detail/helpers.hpp | 9 +- .../include/hip/hcc_detail/hip_runtime.h | 2 +- 3 files changed, 310 insertions(+), 33 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index 9ce0722496..b1134ee9cc 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -235,7 +235,248 @@ namespace glo_tests }; } - #define make_lambda_wrapper9(kernel_name, p0, p1, p2, p3, p4, p5, p6, p7) \ + // TODO: these are temporary, they need to be uglified and them completely + // removed once we enable C++14 support and can have proper generic, + // variadic lambdas. + #define make_lambda_wrapper21( \ + kernel_name, \ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, \ + p16, p17, p18, p19) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_, \ + std::decay_t _p12_, \ + std::decay_t _p13_, \ + std::decay_t _p14_, \ + std::decay_t _p15_, \ + std::decay_t _p16_, \ + std::decay_t _p17_, \ + std::decay_t _p18_, \ + std::decay_t _p19_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_, \ + _p18_, _p19_); \ + } + #define make_lambda_wrapper20( \ + kernel_name, \ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, \ + p16, p17, p18) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_, \ + std::decay_t _p12_, \ + std::decay_t _p13_, \ + std::decay_t _p14_, \ + std::decay_t _p15_, \ + std::decay_t _p16_, \ + std::decay_t _p17_, \ + std::decay_t _p18_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_, \ + _p18_); \ + } + #define make_lambda_wrapper19( \ + kernel_name, \ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, \ + p16, p17) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_, \ + std::decay_t _p12_, \ + std::decay_t _p13_, \ + std::decay_t _p14_, \ + std::decay_t _p15_, \ + std::decay_t _p16_, \ + std::decay_t _p17_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_); \ + } + #define make_lambda_wrapper18( \ + kernel_name, \ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, \ + p16) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_, \ + std::decay_t _p12_, \ + std::decay_t _p13_, \ + std::decay_t _p14_, \ + std::decay_t _p15_, \ + std::decay_t _p16_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_); \ + } + #define make_lambda_wrapper17( \ + kernel_name, \ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_, \ + std::decay_t _p12_, \ + std::decay_t _p13_, \ + std::decay_t _p14_, \ + std::decay_t _p15_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_); \ + } + #define make_lambda_wrapper16( \ + kernel_name, \ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_, \ + std::decay_t _p12_, \ + std::decay_t _p13_, \ + std::decay_t _p14_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_); \ + } + #define make_lambda_wrapper15( \ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)\ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_, \ + std::decay_t _p12_, \ + std::decay_t _p13_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_, _p12_, _p13_); \ + } + #define make_lambda_wrapper14( \ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_, \ + std::decay_t _p12_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_, _p12_); \ + } + #define make_lambda_wrapper13( \ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_, \ + std::decay_t _p11_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ + _p9_, _p10_, _p11_); \ + } + #define make_lambda_wrapper12( \ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_, \ + std::decay_t _p10_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, _p9_, \ + _p10_); \ + } + #define make_lambda_wrapper11( \ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) \ []( \ std::decay_t _p0_, \ std::decay_t _p1_, \ @@ -244,57 +485,87 @@ namespace glo_tests std::decay_t _p4_, \ std::decay_t _p5_, \ std::decay_t _p6_, \ - std::decay_t _p7_) [[hc]] { \ + std::decay_t _p7_, \ + std::decay_t _p8_, \ + std::decay_t _p9_) [[hc]] { \ + kernel_name( \ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, _p9_); \ + } + #define make_lambda_wrapper10( \ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_, \ + std::decay_t _p8_) [[hc]] { \ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_); \ + } + #define make_lambda_wrapper9(kernel_name, p0, p1, p2, p3, p4, p5, p6, p7) \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_, \ + std::decay_t _p7_) [[hc]] { \ kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_); \ } #define make_lambda_wrapper8(kernel_name, p0, p1, p2, p3, p4, p5, p6) \ []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_) [[hc]] { \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_, \ + std::decay_t _p6_) [[hc]] { \ kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_); \ } #define make_lambda_wrapper7(kernel_name, p0, p1, p2, p3, p4, p5) \ []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_) [[hc]] { \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_, \ + std::decay_t _p5_) [[hc]] { \ kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_); \ } #define make_lambda_wrapper6(kernel_name, p0, p1, p2, p3, p4) \ []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_) [[hc]] { \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_, \ + std::decay_t _p4_) [[hc]] { \ kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_); \ } #define make_lambda_wrapper5(kernel_name, p0, p1, p2, p3) \ - [](std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_) [[hc]] { \ + []( \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_, \ + std::decay_t _p3_) [[hc]] { \ kernel_name(_p0_, _p1_, _p2_, _p3_); \ } #define make_lambda_wrapper4(kernel_name, p0, p1, p2) \ []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_) [[hc]] { \ + std::decay_t _p0_, \ + std::decay_t _p1_, \ + std::decay_t _p2_) [[hc]] { \ kernel_name(_p0_, _p1_, _p2_); \ } #define make_lambda_wrapper3(kernel_name, p0, p1) \ []( \ - std::decay_t _p0_, \ - std::decay_t _p1_) [[hc]] { \ + std::decay_t _p0_, \ + std::decay_t _p1_) [[hc]] { \ kernel_name(_p0_, _p1_); \ } #define make_lambda_wrapper2(kernel_name, p0) \ @@ -323,7 +594,8 @@ namespace glo_tests make_lambda_wrapper(kernel_name, __VA_ARGS__), \ ##__VA_ARGS__); \ } - #define hipLaunchKernel( \ + + #define hipLaunchKernelV2( \ kernel_name, \ num_blocks, \ dim_blocks, \ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp index ea9217977b..301d740066 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp @@ -128,9 +128,14 @@ namespace std namespace glo_tests // Only for documentation, macros ignore namespaces. { - #define count_macro_args_impl(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _n, ...) _n + #define count_macro_args_impl( \ + _0, _1, _2, _3, _4, _5, _6, _7, \ + _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _n, ...) _n #define count_macro_args(...) \ - count_macro_args_impl(,##__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) + count_macro_args_impl( \ + , ##__VA_ARGS__, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9,\ + 8, 7, 6, 5, 4, 3, 2, 1, 0) #define overloaded_macro_expand(macro, arg_cnt) macro##arg_cnt #define overload_macro_impl(macro, arg_cnt) \ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 870dcd0b34..590cc33bd1 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -416,7 +416,7 @@ static inline __device__ void* memset(void* ptr, int val, size_t size) #define __syncthreads() hc_barrier(CLK_LOCAL_MEM_FENCE) -#define HIP_KERNEL_NAME(...) __VA_ARGS__ +#define HIP_KERNEL_NAME(...) (__VA_ARGS__) #define HIP_SYMBOL(X) #X #if defined __HCC_CPP__ From feae5cda6b4308d07c7766728cc345524e621526 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Tue, 21 Mar 2017 12:38:40 -0500 Subject: [PATCH 21/56] update GGL implementation to use hipLaunchKernel Change-Id: Ibc08185c814bb07d54f3e68016b10eb7b9f2bf4b [ROCm/clr commit: 4ca09e977dee33577705b7312b7559a0cdd57828] --- projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index b1134ee9cc..c59c69ffd9 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -595,7 +595,7 @@ namespace glo_tests ##__VA_ARGS__); \ } - #define hipLaunchKernelV2( \ + #define hipLaunchKernel( \ kernel_name, \ num_blocks, \ dim_blocks, \ From a47a674e375b6b7f6102d636ee7d797a34867246 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Thu, 23 Mar 2017 16:25:53 +0530 Subject: [PATCH 22/56] Mark hcc_LIBRARIES as PRIVATE Change-Id: Ia0f8f12148b69c9de78378d117e3561ce20cd827 [ROCm/clr commit: 89623f748d9a80cb8ddc34630afa099084b69eeb] --- projects/clr/hipamd/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index 93f36d97f1..369b6528a6 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -205,7 +205,7 @@ if(HIP_PLATFORM STREQUAL "hcc") foreach(TARGET hip_hcc hip_hcc_static hip_device) target_include_directories(${TARGET} SYSTEM INTERFACE $/include>;${HSA_PATH}/include) endforeach() - target_link_libraries(hip_hcc INTERFACE hcc::hccrt;hcc::hc_am) + target_link_libraries(hip_hcc PRIVATE hcc::hccrt;hcc::hc_am) # Generate hcc_version.txt add_custom_target(query_hcc_version COMMAND ${HCC_HOME}/bin/hcc --version > ${PROJECT_BINARY_DIR}/hcc_version.tmp) From 478eb4e3503b199bfd29f128c3936099dd3674a5 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Thu, 23 Mar 2017 10:16:37 -0500 Subject: [PATCH 23/56] removed llvm dependency and metadata functionality Change-Id: Ib9783b75d326559ed29c5aa2218aed40d20ad0fb [ROCm/clr commit: 5a0685c1372aca06f1f8c4b08869d62d8ac04946] --- projects/clr/hipamd/CMakeLists.txt | 4 ++-- projects/clr/hipamd/bin/hipcc | 2 +- projects/clr/hipamd/src/hip_module.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index 369b6528a6..cb950fe5b0 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -190,11 +190,11 @@ if(HIP_PLATFORM STREQUAL "hcc") execute_process(COMMAND ${HCC_HOME}/bin/hcc-config --ldflags OUTPUT_VARIABLE HCC_LD_FLAGS) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${HCC_LD_FLAGS} -Wl,-Bsymbolic") - find_package(LLVM HINTS "/opt/rocm/llvm") +# find_package(LLVM HINTS "/opt/rocm/llvm") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --amdgpu-target=gfx701 --amdgpu-target=gfx801 --amdgpu-target=gfx802 --amdgpu-target=gfx803 --amdgpu-target=gfx900") add_library(hip_hcc SHARED ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc PRIVATE hc_am) - target_link_libraries(hip_hcc PUBLIC LLVMAMDGPUUtils) +# target_link_libraries(hip_hcc PUBLIC LLVMAMDGPUUtils) add_library(hip_hcc_static STATIC ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc_static PRIVATE hc_am) add_dependencies(hip_hcc_static hip_hcc) diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index e99be07ffd..34ea6f8a8e 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/bin/hipcc @@ -129,7 +129,7 @@ if ($HIP_PLATFORM eq "hcc") { $HIPCXXFLAGS .= " -Wno-deprecated-register"; $HIPLDFLAGS .= " -lsupc++"; - $HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am -lhsakmt `${LLVM_HOME}/bin/llvm-config --ldflags --libs`"; + $HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am -lhsakmt";# `${LLVM_HOME}/bin/llvm-config --ldflags --libs`"; # Add trace marker library: # TODO - once we cleanly separate the HIP API headers from HIP library headers this logic should move to CMakebuild option - apps do not need to see the marker library. diff --git a/projects/clr/hipamd/src/hip_module.cpp b/projects/clr/hipamd/src/hip_module.cpp index dc0a681c6d..3bca2090ff 100644 --- a/projects/clr/hipamd/src/hip_module.cpp +++ b/projects/clr/hipamd/src/hip_module.cpp @@ -202,7 +202,7 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname){ (*module)->size = size; in.seekg(0, std::ios::beg); std::copy(std::istreambuf_iterator(in), std::istreambuf_iterator(), ptr); - +/* Enable for metadata implementation Elf *e = elf_memory((char*)p, size); if(elf_kind(e) != ELF_K_ELF){ return ihipLogStatus(hipErrorInvalidValue); @@ -251,7 +251,7 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname){ } } } - +*/ status = hsa_code_object_deserialize(ptr, size, NULL, &(*module)->object); if(status != HSA_STATUS_SUCCESS){ From 620bbbc58348ee3f98c7f28a7b0b39e104f09d27 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Thu, 23 Mar 2017 11:08:19 -0500 Subject: [PATCH 24/56] removed LLVM_HOME from hipcc Change-Id: Ic3dfdde9d28f08bf54b12dfc38ab1f25884bcfab [ROCm/clr commit: 9aef93f03e4f23418da83c4a95c3bcb9f89eb223] --- projects/clr/hipamd/bin/hipcc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index 34ea6f8a8e..a08d5c952b 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/bin/hipcc @@ -103,7 +103,7 @@ if ($HIP_PLATFORM eq "hcc") { $HIPLDFLAGS = `${HCC_HOME}/bin/hcc-config --ldflags`; - $LLVM_HOME = "/opt/rocm/llvm"; +# $LLVM_HOME = "/opt/rocm/llvm"; #### GCC system includes workaround #### $HCC_WA_FLAGS = " "; From 28427bdbea17daa59718b724d50f061e52434fc6 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Thu, 23 Mar 2017 22:02:52 +0530 Subject: [PATCH 25/56] Revert "Mark hcc_LIBRARIES as PRIVATE" This reverts commit a47a674e375b6b7f6102d636ee7d797a34867246. [ROCm/clr commit: 84cb55da9b0bd5334d133dc8e11f977c511b062b] --- projects/clr/hipamd/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index cb950fe5b0..16f43d38c5 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -205,7 +205,7 @@ if(HIP_PLATFORM STREQUAL "hcc") foreach(TARGET hip_hcc hip_hcc_static hip_device) target_include_directories(${TARGET} SYSTEM INTERFACE $/include>;${HSA_PATH}/include) endforeach() - target_link_libraries(hip_hcc PRIVATE hcc::hccrt;hcc::hc_am) + target_link_libraries(hip_hcc INTERFACE hcc::hccrt;hcc::hc_am) # Generate hcc_version.txt add_custom_target(query_hcc_version COMMAND ${HCC_HOME}/bin/hcc --version > ${PROJECT_BINARY_DIR}/hcc_version.tmp) From 62c3bd71416ac94e7761eca1d20bcce6ca7bb08b Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Fri, 24 Mar 2017 10:30:33 +0530 Subject: [PATCH 26/56] Fix for hipMemcpyFromSymbolAsync Change-Id: I449c669c8f0ef041deaf0a1bc812a71b2f0cc5a6 [ROCm/clr commit: dfa516f80432dada86167ce8c00626d364dc208b] --- projects/clr/hipamd/src/hip_hcc.cpp | 26 +++++++++++++++++++++----- projects/clr/hipamd/src/hip_hcc.h | 2 +- projects/clr/hipamd/src/hip_memory.cpp | 5 +++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/projects/clr/hipamd/src/hip_hcc.cpp b/projects/clr/hipamd/src/hip_hcc.cpp index 17cffbc013..e422a6d4db 100644 --- a/projects/clr/hipamd/src/hip_hcc.cpp +++ b/projects/clr/hipamd/src/hip_hcc.cpp @@ -1888,15 +1888,31 @@ void ihipStream_t::lockedSymbolCopySync(hc::accelerator &acc, void* dst, void* s } } -void ihipStream_t::lockedSymbolCopyAsync(hc::accelerator &acc, void* dst, void* src, size_t sizeBytes, unsigned kind) +void ihipStream_t::lockedSymbolCopyAsync(hc::accelerator &acc, void* dst, void* src, size_t sizeBytes, size_t offset, unsigned kind) { if(kind == hipMemcpyHostToDevice) { - addSymbolPtrToTracker(acc, dst, sizeBytes); - locked_getAv()->copy_async((void*)src, dst, sizeBytes); + hc::AmPointerInfo srcPtrInfo(NULL, NULL, 0, acc, 0, 0); + bool srcTracked = (hc::am_memtracker_getinfo(&srcPtrInfo, src) == AM_SUCCESS); + if(srcTracked) { + addSymbolPtrToTracker(acc, dst, sizeBytes); + locked_getAv()->copy_async((void*)src, dst, sizeBytes); + } else { + LockedAccessor_StreamCrit_t crit(_criticalData); + this->wait(crit); + acc.memcpy_symbol(dst, (void*)src, sizeBytes, offset); + } } if(kind == hipMemcpyDeviceToHost) { - addSymbolPtrToTracker(acc, src, sizeBytes); - locked_getAv()->copy_async((void*)src, dst, sizeBytes); + hc::AmPointerInfo dstPtrInfo(NULL, NULL, 0, acc, 0, 0); + bool dstTracked = (hc::am_memtracker_getinfo(&dstPtrInfo, dst) == AM_SUCCESS); + if(dstTracked) { + addSymbolPtrToTracker(acc, src, sizeBytes); + locked_getAv()->copy_async((void*)src, dst, sizeBytes); + } else { + LockedAccessor_StreamCrit_t crit(_criticalData); + this->wait(crit); + acc.memcpy_symbol((void*)src, (void*)dst, sizeBytes, offset, Kalmar::hcMemcpyDeviceToHost); + } } } diff --git a/projects/clr/hipamd/src/hip_hcc.h b/projects/clr/hipamd/src/hip_hcc.h index 1c287bfc44..245f154305 100644 --- a/projects/clr/hipamd/src/hip_hcc.h +++ b/projects/clr/hipamd/src/hip_hcc.h @@ -504,7 +504,7 @@ public: void locked_copyAsync(void* dst, const void* src, size_t sizeBytes, unsigned kind); void lockedSymbolCopySync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, size_t offset, unsigned kind); - void lockedSymbolCopyAsync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, unsigned kind); + void lockedSymbolCopyAsync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, size_t offset, unsigned kind); //--- // Member functions that begin with locked_ are thread-safe accessors - these acquire / release the critical mutex. diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index b888c5054c..94121838fd 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -567,7 +567,7 @@ hipError_t hipMemcpyToSymbolAsync(const char* symbolName, const void *src, size_ if (stream) { try { - stream->lockedSymbolCopyAsync(acc, dst, (void*)src, count + offset, kind); + stream->lockedSymbolCopyAsync(acc, dst, (void*)src, count, offset, kind); } catch (ihipException ex) { e = ex._code; @@ -603,9 +603,10 @@ hipError_t hipMemcpyFromSymbolAsync(void* dst, const char* symbolName, size_t co return ihipLogStatus(hipErrorInvalidSymbol); } + stream = ihipSyncAndResolveStream(stream); if (stream) { try { - stream->lockedSymbolCopyAsync(acc, dst, src, count + offset, kind); + stream->lockedSymbolCopyAsync(acc, dst, src, count, offset, kind); } catch (ihipException ex) { e = ex._code; From a9a6b5e8a68b11d5bd4ffc16c17c7f57d6b024ac Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Fri, 24 Mar 2017 10:39:11 +0530 Subject: [PATCH 27/56] Update hipTestDeviceSymbol sample Change-Id: If5ba99c60cd30c4491ca3a4856764224163d3ddf [ROCm/clr commit: c33c58d6871135e0a324d5123647f78d24554d3b] --- .../src/deviceLib/hipTestDeviceSymbol.cpp | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/projects/clr/hipamd/tests/src/deviceLib/hipTestDeviceSymbol.cpp b/projects/clr/hipamd/tests/src/deviceLib/hipTestDeviceSymbol.cpp index 6ffaedf659..c2ffb5ce7d 100644 --- a/projects/clr/hipamd/tests/src/deviceLib/hipTestDeviceSymbol.cpp +++ b/projects/clr/hipamd/tests/src/deviceLib/hipTestDeviceSymbol.cpp @@ -93,8 +93,29 @@ int main() hipMemcpyFromSymbol(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost); for(unsigned i=0;i Date: Sun, 26 Mar 2017 23:45:54 +0530 Subject: [PATCH 28/56] Added support for Primary Context Management APIs Change-Id: I70f91b4492e112dd8e12ecf511fdc18a27944a06 [ROCm/clr commit: 33a8cdc6d32b64213e00316cee4f09f26e7ba9fc] --- .../include/hip/hcc_detail/hip_runtime_api.h | 60 +++++++++++++++ .../include/hip/nvcc_detail/hip_runtime_api.h | 25 ++++++ projects/clr/hipamd/src/hip_context.cpp | 76 +++++++++++++++++++ 3 files changed, 161 insertions(+) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index 2ff4a70802..da94ad5e5e 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -1696,6 +1696,66 @@ hipError_t hipCtxEnablePeerAccess (hipCtx_t peerCtx, unsigned int flags); */ hipError_t hipCtxDisablePeerAccess (hipCtx_t peerCtx); +/** + * @brief Get the state of the primary context. + * + * @param [in] Device to get primary context flags for + * @param [out] Pointer to store flags + * @param [out] Pointer to store context state; 0 = inactive, 1 = active + * + * @returns #hipSuccess + * + * @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice + */ +hipError_t hipDevicePrimaryCtxGetState ( hipDevice_t dev, unsigned int* flags, int* active ); + +/** + * @brief Release the primary context on the GPU. + * + * @param [in] Device which primary context is released + * + * @returns #hipSuccess + * + * @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice + * @warning This function return #hipSuccess though doesn't release the primaryCtx by design on HIP/HCC path. + */ +hipError_t hipDevicePrimaryCtxRelease ( hipDevice_t dev); + +/** + * @brief Retain the primary context on the GPU. + * + * @param [out] Returned context handle of the new context + * @param [in] Device which primary context is released + * + * @returns #hipSuccess + * + * @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice + */ +hipError_t hipDevicePrimaryCtxRetain ( hipCtx_t* pctx, hipDevice_t dev ); + +/** + * @brief Resets the primary context on the GPU. + * + * @param [in] Device which primary context is reset + * + * @returns #hipSuccess + * + * @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice + */ +hipError_t hipDevicePrimaryCtxReset ( hipDevice_t dev ); + +/** + * @brief Set flags for the primary context. + * + * @param [in] Device for which the primary context flags are set + * @param [in] New flags for the device + * + * @returns #hipSuccess, #hipErrorContextAlreadyInUse + * + * @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice + */ +hipError_t hipDevicePrimaryCtxSetFlags ( hipDevice_t dev, unsigned int flags ); + // doxygen end Context Management /** * @} diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h index 8c3e0da639..a9963fdfe3 100644 --- a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h @@ -670,6 +670,31 @@ inline static hipError_t hipCtxEnablePeerAccess ( hipCtx_t peerCtx, unsigned in return hipCUResultTohipError(cuCtxEnablePeerAccess(peerCtx, flags)); } +inline static hipError_t hipDevicePrimaryCtxGetState ( hipDevice_t dev, unsigned int* flags, int* active ) +{ + return hipCUResultTohipError(cuDevicePrimaryCtxGetState(dev, flags, active)); +} + +inline static hipError_t hipDevicePrimaryCtxRelease ( hipDevice_t dev) +{ + return hipCUResultTohipError(cuDevicePrimaryCtxRelease(dev)); +} + +inline static hipError_t hipDevicePrimaryCtxRetain ( hipCtx_t* pctx, hipDevice_t dev ) +{ + return hipCUResultTohipError(cuDevicePrimaryCtxRetain(pctx, dev)); +} + +inline static hipError_t hipDevicePrimaryCtxReset ( hipDevice_t dev ) +{ + return hipCUResultTohipError(cuDevicePrimaryCtxReset(dev)); +} + +inline static hipError_t hipDevicePrimaryCtxSetFlags ( hipDevice_t dev, unsigned int flags ) +{ + return hipCUResultTohipError(cuDevicePrimaryCtxSetFlags(dev, flags)); +} + inline static hipError_t hipMemGetAddressRange ( hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr ) { return hipCUResultTohipError(cuMemGetAddressRange( pbase , psize , dptr)); diff --git a/projects/clr/hipamd/src/hip_context.cpp b/projects/clr/hipamd/src/hip_context.cpp index 835cf6e795..4c39abb738 100644 --- a/projects/clr/hipamd/src/hip_context.cpp +++ b/projects/clr/hipamd/src/hip_context.cpp @@ -283,3 +283,79 @@ hipError_t hipCtxGetFlags ( unsigned int* flags ) *flags = tempCtx->_ctxFlags; return ihipLogStatus(e); } + +hipError_t hipDevicePrimaryCtxGetState ( hipDevice_t dev, unsigned int* flags, int* active ) +{ + HIP_INIT_API(dev, flags, active); + hipError_t e = hipSuccess; + auto deviceHandle = ihipGetDevice(dev); + + if (deviceHandle == NULL) { + e = hipErrorInvalidDevice; + } + + ihipCtx_t* tempCtx; + tempCtx = ihipGetTlsDefaultCtx(); + ihipCtx_t* primaryCtx = deviceHandle->_primaryCtx; + if(tempCtx == primaryCtx) { + *active = 1; + *flags = tempCtx->_ctxFlags; + } else { + *active = 0; + *flags = primaryCtx->_ctxFlags; + } + return ihipLogStatus(e); +} + +hipError_t hipDevicePrimaryCtxRelease ( hipDevice_t dev) +{ + HIP_INIT_API(dev); + hipError_t e = hipSuccess; + auto deviceHandle = ihipGetDevice(dev); + + if (deviceHandle == NULL) { + e = hipErrorInvalidDevice; + } + return ihipLogStatus(e); +} + +hipError_t hipDevicePrimaryCtxRetain ( hipCtx_t* pctx, hipDevice_t dev ) +{ + HIP_INIT_API(pctx, dev); + hipError_t e = hipSuccess; + auto deviceHandle = ihipGetDevice(dev); + + if (deviceHandle == NULL) { + e = hipErrorInvalidDevice; + } + *pctx = deviceHandle->_primaryCtx; + return ihipLogStatus(e); +} + +hipError_t hipDevicePrimaryCtxReset ( hipDevice_t dev ) +{ + HIP_INIT_API(dev); + hipError_t e = hipSuccess; + auto deviceHandle = ihipGetDevice(dev); + + if (deviceHandle == NULL) { + e = hipErrorInvalidDevice; + } + ihipCtx_t* primaryCtx = deviceHandle->_primaryCtx; + primaryCtx->locked_reset(); + return ihipLogStatus(e); +} + +hipError_t hipDevicePrimaryCtxSetFlags ( hipDevice_t dev, unsigned int flags ) +{ + HIP_INIT_API(dev, flags); + hipError_t e = hipSuccess; + auto deviceHandle = ihipGetDevice(dev); + + if (deviceHandle == NULL) { + e = hipErrorInvalidDevice; + } else { + e = hipErrorContextAlreadyInUse; + } + return ihipLogStatus(e); +} From 30eb97392ab32270a9c45f3932dd4a22762a76ac Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Mon, 27 Mar 2017 00:35:10 +0530 Subject: [PATCH 29/56] Fix for MemcpyFromSymbol on HIP/NVCC path Change-Id: Ice38307f72870ae468cbf0861e104f0fa46dfd56 [ROCm/clr commit: 41f0ebebf0be180adeb46b954d195f4e39e1383e] --- .../include/hip/hcc_detail/hip_runtime_api.h | 8 ++++---- .../include/hip/nvcc_detail/hip_runtime_api.h | 10 ++++++++++ projects/clr/hipamd/src/hip_memory.cpp | 16 ++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index da94ad5e5e..cba6f01d49 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -1156,7 +1156,7 @@ hipError_t hipMemcpyDtoDAsync(hipDeviceptr_t dst, hipDeviceptr_t src, size_t siz * * @see hipMemcpy, hipMemcpy2D, hipMemcpyToArray, hipMemcpy2DToArray, hipMemcpyFromArray, hipMemcpy2DFromArray, hipMemcpyArrayToArray, hipMemcpy2DArrayToArray, hipMemcpyFromSymbol, hipMemcpyAsync, hipMemcpy2DAsync, hipMemcpyToArrayAsync, hipMemcpy2DToArrayAsync, hipMemcpyFromArrayAsync, hipMemcpy2DFromArrayAsync, hipMemcpyToSymbolAsync, hipMemcpyFromSymbolAsync */ -hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind); +hipError_t hipMemcpyToSymbol(const void* symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind); /** @@ -1176,11 +1176,11 @@ hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t siz * * @see hipMemcpy, hipMemcpy2D, hipMemcpyToArray, hipMemcpy2DToArray, hipMemcpyFromArray, hipMemcpy2DFromArray, hipMemcpyArrayToArray, hipMemcpy2DArrayToArray, hipMemcpyFromSymbol, hipMemcpyAsync, hipMemcpy2DAsync, hipMemcpyToArrayAsync, hipMemcpy2DToArrayAsync, hipMemcpyFromArrayAsync, hipMemcpy2DFromArrayAsync, hipMemcpyToSymbolAsync, hipMemcpyFromSymbolAsync */ -hipError_t hipMemcpyToSymbolAsync(const char* symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind, hipStream_t stream); +hipError_t hipMemcpyToSymbolAsync(const void* symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind, hipStream_t stream); -hipError_t hipMemcpyFromSymbol(void *dst, const char* symbolName, size_t sizeBytes, size_t offset, hipMemcpyKind kind); +hipError_t hipMemcpyFromSymbol(void *dst, const void* symbolName, size_t sizeBytes, size_t offset, hipMemcpyKind kind); -hipError_t hipMemcpyFromSymbolAsync(void *dst, const char* symbolName, size_t sizeBytes, size_t offset, hipMemcpyKind kind, hipStream_t stream); +hipError_t hipMemcpyFromSymbolAsync(void *dst, const void* symbolName, size_t sizeBytes, size_t offset, hipMemcpyKind kind, hipStream_t stream); /** * @brief Copy data from src to dst asynchronously. diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h index a9963fdfe3..758ef064bd 100644 --- a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h @@ -333,6 +333,16 @@ inline static hipError_t hipMemcpyToSymbolAsync(const void* symbol, const void* return hipCUDAErrorTohipError(cudaMemcpyToSymbolAsync(symbol, src, sizeBytes, offset, hipMemcpyKindToCudaMemcpyKind(copyType))); } +inline static hipError_t hipMemcpyFromSymbol(void *dst, const void* symbolName, size_t sizeBytes, size_t offset, hipMemcpyKind kind) +{ + return hipCUDAErrorTohipError(cudaMemcpyFromSymbol(dst, symbolName, sizeBytes, offset, hipMemcpyKindToCudaMemcpyKind(kind))); +} + +inline static hipError_t hipMemcpyFromSymbolAsync(void *dst, const void* symbolName, size_t sizeBytes, size_t offset, hipMemcpyKind kind, hipStream_t stream) +{ + return hipCUDAErrorTohipError(cudaMemcpyFromSymbolAsync(dst, symbolName, sizeBytes, offset, hipMemcpyKindToCudaMemcpyKind(kind), stream)); +} + inline static hipError_t hipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width, size_t height, hipMemcpyKind kind){ return hipCUDAErrorTohipError(cudaMemcpy2D(dst, dpitch, src, spitch, width, height, hipMemcpyKindToCudaMemcpyKind(kind))); } diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 94121838fd..4684287076 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -472,7 +472,7 @@ hipError_t hipHostUnregister(void *hostPtr) return ihipLogStatus(hip_status); } -hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t count, size_t offset, hipMemcpyKind kind) +hipError_t hipMemcpyToSymbol(const void* symbolName, const void *src, size_t count, size_t offset, hipMemcpyKind kind) { HIP_INIT_CMD_API(symbolName, src, count, offset, kind); @@ -485,7 +485,7 @@ hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t cou hc::accelerator acc = ctx->getDevice()->_acc; - void *dst = acc.get_symbol_address(symbolName); + void *dst = acc.get_symbol_address((const char*) symbolName); tprintf(DB_MEM, " symbol '%s' resolved to address:%p\n", symbolName, dst); if(dst == nullptr) @@ -507,7 +507,7 @@ hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t cou } -hipError_t hipMemcpyFromSymbol(void* dst, const char* symbolName, size_t count, size_t offset, hipMemcpyKind kind) +hipError_t hipMemcpyFromSymbol(void* dst, const void* symbolName, size_t count, size_t offset, hipMemcpyKind kind) { HIP_INIT_CMD_API(symbolName, dst, count, offset, kind); @@ -520,7 +520,7 @@ hipError_t hipMemcpyFromSymbol(void* dst, const char* symbolName, size_t count, hc::accelerator acc = ctx->getDevice()->_acc; - void *src = acc.get_symbol_address(symbolName); + void *src = acc.get_symbol_address((const char*) symbolName); tprintf(DB_MEM, " symbol '%s' resolved to address:%p\n", symbolName, dst); if(dst == nullptr) @@ -542,7 +542,7 @@ hipError_t hipMemcpyFromSymbol(void* dst, const char* symbolName, size_t count, } -hipError_t hipMemcpyToSymbolAsync(const char* symbolName, const void *src, size_t count, size_t offset, hipMemcpyKind kind, hipStream_t stream) +hipError_t hipMemcpyToSymbolAsync(const void* symbolName, const void *src, size_t count, size_t offset, hipMemcpyKind kind, hipStream_t stream) { HIP_INIT_CMD_API(symbolName, src, count, offset, kind, stream); @@ -557,7 +557,7 @@ hipError_t hipMemcpyToSymbolAsync(const char* symbolName, const void *src, size_ hc::accelerator acc = ctx->getDevice()->_acc; - void *dst = acc.get_symbol_address(symbolName); + void *dst = acc.get_symbol_address((const char*) symbolName); tprintf(DB_MEM, " symbol '%s' resolved to address:%p\n", symbolName, dst); if(dst == nullptr) @@ -580,7 +580,7 @@ hipError_t hipMemcpyToSymbolAsync(const char* symbolName, const void *src, size_ } -hipError_t hipMemcpyFromSymbolAsync(void* dst, const char* symbolName, size_t count, size_t offset, hipMemcpyKind kind, hipStream_t stream) +hipError_t hipMemcpyFromSymbolAsync(void* dst, const void* symbolName, size_t count, size_t offset, hipMemcpyKind kind, hipStream_t stream) { HIP_INIT_CMD_API(symbolName, dst, count, offset, kind, stream); @@ -595,7 +595,7 @@ hipError_t hipMemcpyFromSymbolAsync(void* dst, const char* symbolName, size_t co hc::accelerator acc = ctx->getDevice()->_acc; - void *src = acc.get_symbol_address(symbolName); + void *src = acc.get_symbol_address((const char*) symbolName); tprintf(DB_MEM, " symbol '%s' resolved to address:%p\n", symbolName, src); if(src == nullptr || dst == nullptr) From c3f1a37c28d30e7330faf1156897ef43a9f64f4f Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Mon, 27 Mar 2017 11:00:39 -0500 Subject: [PATCH 30/56] Re-enabled metadata parsing in HIP Change-Id: If8caa844571cb8581450df9ffdb76e2445c75f13 [ROCm/clr commit: abf369049b35e00d8c10214af43efb47d6cbbd3c] --- projects/clr/hipamd/CMakeLists.txt | 4 ++-- projects/clr/hipamd/bin/hipcc | 3 ++- projects/clr/hipamd/src/hip_module.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index 16f43d38c5..dcecaa8d2f 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -190,11 +190,11 @@ if(HIP_PLATFORM STREQUAL "hcc") execute_process(COMMAND ${HCC_HOME}/bin/hcc-config --ldflags OUTPUT_VARIABLE HCC_LD_FLAGS) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${HCC_LD_FLAGS} -Wl,-Bsymbolic") -# find_package(LLVM HINTS "/opt/rocm/llvm") + find_package(LLVM HINTS ${HCC_HOME}/compiler/lib/cmake) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --amdgpu-target=gfx701 --amdgpu-target=gfx801 --amdgpu-target=gfx802 --amdgpu-target=gfx803 --amdgpu-target=gfx900") add_library(hip_hcc SHARED ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc PRIVATE hc_am) -# target_link_libraries(hip_hcc PUBLIC LLVMAMDGPUUtils) + target_link_libraries(hip_hcc PUBLIC LLVMAMDGPUUtils) add_library(hip_hcc_static STATIC ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc_static PRIVATE hc_am) add_dependencies(hip_hcc_static hip_hcc) diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index a08d5c952b..3dd8c2d60b 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/bin/hipcc @@ -129,7 +129,8 @@ if ($HIP_PLATFORM eq "hcc") { $HIPCXXFLAGS .= " -Wno-deprecated-register"; $HIPLDFLAGS .= " -lsupc++"; - $HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am -lhsakmt";# `${LLVM_HOME}/bin/llvm-config --ldflags --libs`"; + $HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am -lhsakmt "; + $HIPLDFLAGS .= " -L$HCC_HOME/compiler/lib -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMMC -lLLVMCore -lLLVMSupport "; # Add trace marker library: # TODO - once we cleanly separate the HIP API headers from HIP library headers this logic should move to CMakebuild option - apps do not need to see the marker library. diff --git a/projects/clr/hipamd/src/hip_module.cpp b/projects/clr/hipamd/src/hip_module.cpp index 3bca2090ff..dc0a681c6d 100644 --- a/projects/clr/hipamd/src/hip_module.cpp +++ b/projects/clr/hipamd/src/hip_module.cpp @@ -202,7 +202,7 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname){ (*module)->size = size; in.seekg(0, std::ios::beg); std::copy(std::istreambuf_iterator(in), std::istreambuf_iterator(), ptr); -/* Enable for metadata implementation + Elf *e = elf_memory((char*)p, size); if(elf_kind(e) != ELF_K_ELF){ return ihipLogStatus(hipErrorInvalidValue); @@ -251,7 +251,7 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname){ } } } -*/ + status = hsa_code_object_deserialize(ptr, size, NULL, &(*module)->object); if(status != HSA_STATUS_SUCCESS){ From d64768262fb236c99b5dbd96c44d9de829416e28 Mon Sep 17 00:00:00 2001 From: sunway513 Date: Mon, 27 Mar 2017 17:19:09 +0000 Subject: [PATCH 31/56] resolve GGL merge conflicts Change-Id: I7a5ec3696cf2dd1a77b1686536a1cb84cbfed66e [ROCm/clr commit: 6f38d0f55e3fe8394d2850b65b00d4e505fb8622] --- .../include/hip/hcc_detail/grid_launch_v2.hpp | 715 ++++++++---------- .../hipamd/include/hip/hcc_detail/helpers.hpp | 29 +- .../include/hip/hcc_detail/hip_runtime.h | 8 +- .../include/hip/hcc_detail/hip_runtime_api.h | 2 +- .../include/hip/hcc_detail/host_defines.h | 4 +- 5 files changed, 357 insertions(+), 401 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index c59c69ffd9..dfce53bd26 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -35,7 +35,7 @@ THE SOFTWARE. #include #include -namespace glo_tests +namespace hip_impl { namespace { @@ -54,7 +54,6 @@ namespace glo_tests template requires(Domain == {Ts...}) - static inline void grid_launch_impl( New_grid_launch_tag, @@ -79,14 +78,13 @@ namespace glo_tests throw std::runtime_error{"Failed to retrieve accelerator_view!"}; } - hc::parallel_for_each(*av, d, [=](hc::tiled_index<3> idx) [[hc]] { + hc::parallel_for_each(*av, d, [=](const hc::tiled_index<3>& idx) [[hc]] { k(args...); }); } template requires(Domain == {hipLaunchParm, Ts...}) - static inline void grid_launch_impl( Old_grid_launch_tag, @@ -110,7 +108,6 @@ namespace glo_tests template requires(Domain == {Ts...}) - static inline std::enable_if_t::value> grid_launch( dim3 num_blocks, @@ -152,7 +149,6 @@ namespace glo_tests template requires(Domain == {Ts...}) - static inline void grid_launch( New_grid_launch_tag, @@ -174,7 +170,6 @@ namespace glo_tests template requires(Domain == {Ts...}) - static inline void grid_launch( Old_grid_launch_tag, @@ -196,7 +191,6 @@ namespace glo_tests template requires(Domain == {Ts...}) - static inline std::enable_if_t::value> grid_launch( dim3 num_blocks, @@ -214,402 +208,363 @@ namespace glo_tests std::forward(args)...); } - namespace - { - template struct Wrapper; - - template - struct Wrapper::value>> { - template - requires(Domain == {Ts...}) - void operator()(Ts&&... args) const - { - grid_launch(std::forward(args)...); - } - }; - - template - struct Wrapper::value>> { - template - void operator()(Ts&&...) const {} - }; - } - - // TODO: these are temporary, they need to be uglified and them completely - // removed once we enable C++14 support and can have proper generic, - // variadic lambdas. - #define make_lambda_wrapper21( \ - kernel_name, \ - p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, \ - p16, p17, p18, p19) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_, \ - std::decay_t _p12_, \ - std::decay_t _p13_, \ - std::decay_t _p14_, \ - std::decay_t _p15_, \ - std::decay_t _p16_, \ - std::decay_t _p17_, \ - std::decay_t _p18_, \ - std::decay_t _p19_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_, \ - _p18_, _p19_); \ + // TODO: these are temporary, they need to be completely removed once we + // enable C++14 support and can have proper generic, variadic lambdas. + #define make_kernel_lambda_hip_21(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16, p17, p18, p19)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_,\ + const std::decay_t& _p17_,\ + const std::decay_t& _p18_,\ + const std::decay_t& _p19_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ + _p18_, _p19_);\ } - #define make_lambda_wrapper20( \ - kernel_name, \ - p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, \ - p16, p17, p18) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_, \ - std::decay_t _p12_, \ - std::decay_t _p13_, \ - std::decay_t _p14_, \ - std::decay_t _p15_, \ - std::decay_t _p16_, \ - std::decay_t _p17_, \ - std::decay_t _p18_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_, \ - _p18_); \ + #define make_kernel_lambda_hip_20(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16, p17, p18)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_,\ + const std::decay_t& _p17_,\ + const std::decay_t& _p18_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ + _p18_);\ } - #define make_lambda_wrapper19( \ - kernel_name, \ - p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, \ - p16, p17) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_, \ - std::decay_t _p12_, \ - std::decay_t _p13_, \ - std::decay_t _p14_, \ - std::decay_t _p15_, \ - std::decay_t _p16_, \ - std::decay_t _p17_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_); \ + #define make_kernel_lambda_hip_19(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16, p17)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_,\ + const std::decay_t& _p17_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_);\ } - #define make_lambda_wrapper18( \ - kernel_name, \ - p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, \ - p16) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_, \ - std::decay_t _p12_, \ - std::decay_t _p13_, \ - std::decay_t _p14_, \ - std::decay_t _p15_, \ - std::decay_t _p16_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_); \ + #define make_kernel_lambda_hip_18(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_);\ } - #define make_lambda_wrapper17( \ - kernel_name, \ - p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_, \ - std::decay_t _p12_, \ - std::decay_t _p13_, \ - std::decay_t _p14_, \ - std::decay_t _p15_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_); \ + #define make_kernel_lambda_hip_17(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_);\ } - #define make_lambda_wrapper16( \ - kernel_name, \ - p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_, \ - std::decay_t _p12_, \ - std::decay_t _p13_, \ - std::decay_t _p14_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_, _p12_, _p13_, _p14_); \ + #define make_kernel_lambda_hip_16(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_);\ } - #define make_lambda_wrapper15( \ - kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)\ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_, \ - std::decay_t _p12_, \ - std::decay_t _p13_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_, _p12_, _p13_); \ + #define make_kernel_lambda_hip_15(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_);\ } - #define make_lambda_wrapper14( \ - kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_, \ - std::decay_t _p12_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_, _p12_); \ + #define make_kernel_lambda_hip_14(\ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_);\ } - #define make_lambda_wrapper13( \ - kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_, \ - std::decay_t _p11_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, \ - _p9_, _p10_, _p11_); \ + #define make_kernel_lambda_hip_13(\ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_);\ } - #define make_lambda_wrapper12( \ - kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_, \ - std::decay_t _p10_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, _p9_, \ - _p10_); \ + #define make_kernel_lambda_hip_12(\ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, _p9_,\ + _p10_);\ } - #define make_lambda_wrapper11( \ - kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_, \ - std::decay_t _p9_) [[hc]] { \ - kernel_name( \ - _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, _p9_); \ + #define make_kernel_lambda_hip_11(\ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_, _p9_);\ } - #define make_lambda_wrapper10( \ - kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_, \ - std::decay_t _p8_) [[hc]] { \ - kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_); \ + #define make_kernel_lambda_hip_10(\ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_) [[hc]] {\ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_);\ } - #define make_lambda_wrapper9(kernel_name, p0, p1, p2, p3, p4, p5, p6, p7) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_, \ - std::decay_t _p7_) [[hc]] { \ - kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_); \ + #define make_kernel_lambda_hip_9(\ + kernel_name, p0, p1, p2, p3, p4, p5, p6, p7)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_) [[hc]] {\ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_);\ } - #define make_lambda_wrapper8(kernel_name, p0, p1, p2, p3, p4, p5, p6) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_, \ - std::decay_t _p6_) [[hc]] { \ - kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_); \ + #define make_kernel_lambda_hip_8(kernel_name, p0, p1, p2, p3, p4, p5, p6)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_) [[hc]] {\ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_);\ } - #define make_lambda_wrapper7(kernel_name, p0, p1, p2, p3, p4, p5) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_, \ - std::decay_t _p5_) [[hc]] { \ - kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_); \ + #define make_kernel_lambda_hip_7(kernel_name, p0, p1, p2, p3, p4, p5)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_) [[hc]] {\ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_, _p5_);\ } - #define make_lambda_wrapper6(kernel_name, p0, p1, p2, p3, p4) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_, \ - std::decay_t _p4_) [[hc]] { \ - kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_); \ + #define make_kernel_lambda_hip_6(kernel_name, p0, p1, p2, p3, p4)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_) [[hc]] {\ + kernel_name(_p0_, _p1_, _p2_, _p3_, _p4_);\ } - #define make_lambda_wrapper5(kernel_name, p0, p1, p2, p3) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_, \ - std::decay_t _p3_) [[hc]] { \ - kernel_name(_p0_, _p1_, _p2_, _p3_); \ + #define make_kernel_lambda_hip_5(kernel_name, p0, p1, p2, p3)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_) [[hc]] {\ + kernel_name(_p0_, _p1_, _p2_, _p3_);\ } - #define make_lambda_wrapper4(kernel_name, p0, p1, p2) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_, \ - std::decay_t _p2_) [[hc]] { \ - kernel_name(_p0_, _p1_, _p2_); \ + #define make_kernel_lambda_hip_4(kernel_name, p0, p1, p2)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_) [[hc]] {\ + kernel_name(_p0_, _p1_, _p2_);\ } - #define make_lambda_wrapper3(kernel_name, p0, p1) \ - []( \ - std::decay_t _p0_, \ - std::decay_t _p1_) [[hc]] { \ - kernel_name(_p0_, _p1_); \ + #define make_kernel_lambda_hip_3(kernel_name, p0, p1)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_) [[hc]] {\ + kernel_name(_p0_, _p1_);\ } - #define make_lambda_wrapper2(kernel_name, p0) \ - [](std::decay_t _p0_) [[hc]] { \ - kernel_name(_p0_); \ + #define make_kernel_lambda_hip_2(kernel_name, p0)\ + [](const std::decay_t& _p0_) [[hc]] {\ + kernel_name(_p0_);\ } - #define make_lambda_wrapper1(kernel_name) \ + #define make_kernel_lambda_hip_1(kernel_name)\ []() [[hc]] { kernel_name(lp); } - #define make_lambda_wrapper(...) \ - overload_macro(make_lambda_wrapper, __VA_ARGS__) + #define make_kernel_lambda_hip_(...)\ + overload_macro_hip_(make_kernel_lambda_hip_, __VA_ARGS__) - #define hipLaunchKernelV3( \ - kernel_name, \ - num_blocks, \ - dim_blocks, \ - group_mem_bytes, \ - stream, \ - ...) \ - { \ - glo_tests::grid_launch( \ - num_blocks, \ - dim_blocks, \ - group_mem_bytes, \ - stream, \ - make_lambda_wrapper(kernel_name, __VA_ARGS__), \ - ##__VA_ARGS__); \ + #define hipLaunchKernelV3(\ + kernel_name,\ + num_blocks,\ + dim_blocks,\ + group_mem_bytes,\ + stream,\ + ...)\ + {\ + hip_impl::grid_launch(\ + num_blocks,\ + dim_blocks,\ + group_mem_bytes,\ + stream,\ + make_kernel_lambda_hip_(kernel_name, __VA_ARGS__),\ + ##__VA_ARGS__);\ } - #define hipLaunchKernel( \ - kernel_name, \ - num_blocks, \ - dim_blocks, \ - group_mem_bytes, \ - stream, \ - ...) \ - { \ - hipLaunchKernelV3( \ - kernel_name, \ - num_blocks, \ - dim_blocks, \ - group_mem_bytes, \ - stream, \ - hipLaunchParm{}, \ - ##__VA_ARGS__); \ + #define hipLaunchKernel(\ + kernel_name,\ + num_blocks,\ + dim_blocks,\ + group_mem_bytes,\ + stream,\ + ...)\ + {\ + hipLaunchKernelV3(\ + kernel_name,\ + num_blocks,\ + dim_blocks,\ + group_mem_bytes,\ + stream,\ + hipLaunchParm{},\ + ##__VA_ARGS__);\ } } diff --git a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp index 301d740066..566612dce4 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp @@ -20,9 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// -// Created by alexv on 08/11/16. -// #pragma once #include // For std::conditional, std::decay, std::enable_if, @@ -30,7 +27,7 @@ THE SOFTWARE. #include // For std::declval. namespace std -{ +{ // TODO: these should be removed as soon as possible. #if (__cplusplus < 201406L) template using void_t = void; @@ -126,20 +123,20 @@ namespace std #endif } -namespace glo_tests // Only for documentation, macros ignore namespaces. +namespace // Only for documentation, macros ignore namespaces. { - #define count_macro_args_impl( \ - _0, _1, _2, _3, _4, _5, _6, _7, \ - _8, _9, _10, _11, _12, _13, _14, _15, \ - _16, _17, _18, _19, _20, _21, _n, ...) _n - #define count_macro_args(...) \ - count_macro_args_impl( \ + #define count_macro_args_impl_hip_(\ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15,\ + _16, _17, _18, _19, _20, _21, _n, ...) _n + #define count_macro_args_hip_(...)\ + count_macro_args_impl_hip_(\ , ##__VA_ARGS__, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9,\ 8, 7, 6, 5, 4, 3, 2, 1, 0) - #define overloaded_macro_expand(macro, arg_cnt) macro##arg_cnt - #define overload_macro_impl(macro, arg_cnt) \ - overloaded_macro_expand(macro, arg_cnt) - #define overload_macro(macro, ...) \ - overload_macro_impl(macro, count_macro_args(__VA_ARGS__)) (__VA_ARGS__) + #define overloaded_macro_expand_hip_(macro, arg_cnt) macro##arg_cnt + #define overload_macro_impl_hip_(macro, arg_cnt)\ + overloaded_macro_expand_hip_(macro, arg_cnt) + #define overload_macro_hip_(macro, ...)\ + overload_macro_impl_hip_(macro, count_macro_args_hip_(__VA_ARGS__))\ + (__VA_ARGS__) } diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 590cc33bd1..42d80ecb0e 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -62,11 +62,15 @@ THE SOFTWARE. #include //TODO-HCC-GL - change this to typedef. //typedef grid_launch_parm hipLaunchParm ; -struct EmptyLaunchParm{}; + #if GENERIC_GRID_LAUNCH == 0 #define hipLaunchParm grid_launch_parm #else - #define hipLaunchParm EmptyLaunchParm +namespace hip_impl +{ + struct Empty_launch_parm{}; +} +#define hipLaunchParm hip_impl::Empty_launch_parm #endif //GENERIC_GRID_LAUNCH #if defined (GRID_LAUNCH_VERSION) and (GRID_LAUNCH_VERSION >= 20) || GENERIC_GRID_LAUNCH == 1 diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index cba6f01d49..658e3d2f97 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -32,7 +32,7 @@ THE SOFTWARE. #include #ifndef GENERIC_GRID_LAUNCH -#define GENERIC_GRID_LAUNCH 0 +#define GENERIC_GRID_LAUNCH 0 #endif #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index 28c9268f59..ab975dbb2c 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -32,7 +32,7 @@ THE SOFTWARE. // Add guard to Generic Grid Launch method #ifndef GENERIC_GRID_LAUNCH -#define GENERIC_GRID_LAUNCH 0 +#define GENERIC_GRID_LAUNCH 0 #endif #ifdef __HCC__ @@ -46,7 +46,7 @@ THE SOFTWARE. #if GENERIC_GRID_LAUNCH == 0 //#warning "original global define reached" #define __global__ __attribute__((hc_grid_launch)) __attribute__((used)) -#else +#else //#warning "GGL global define reached" #define __global__ [[hc]] __attribute__((weak)) #endif //GENERIC_GRID_LAUNCH From bdaf6a3aaad2cd056c5dbb265b09d306a86ddb7f Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Tue, 28 Mar 2017 10:46:31 -0500 Subject: [PATCH 32/56] disabled metadata apis Change-Id: Ifb8839c581644cccc2afcd18c38a866f649a4144 [ROCm/clr commit: 4e5861df7af38aaa76b875b736ec6f9af9b99c9c] --- projects/clr/hipamd/bin/hipcc | 3 +-- projects/clr/hipamd/src/hip_module.cpp | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index 3dd8c2d60b..de4883fea3 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/bin/hipcc @@ -103,7 +103,6 @@ if ($HIP_PLATFORM eq "hcc") { $HIPLDFLAGS = `${HCC_HOME}/bin/hcc-config --ldflags`; -# $LLVM_HOME = "/opt/rocm/llvm"; #### GCC system includes workaround #### $HCC_WA_FLAGS = " "; @@ -130,7 +129,7 @@ if ($HIP_PLATFORM eq "hcc") { $HIPLDFLAGS .= " -lsupc++"; $HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am -lhsakmt "; - $HIPLDFLAGS .= " -L$HCC_HOME/compiler/lib -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMMC -lLLVMCore -lLLVMSupport "; +# $HIPLDFLAGS .= " -L$HCC_HOME/compiler/lib -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMMC -lLLVMCore -lLLVMSupport "; # Add trace marker library: # TODO - once we cleanly separate the HIP API headers from HIP library headers this logic should move to CMakebuild option - apps do not need to see the marker library. diff --git a/projects/clr/hipamd/src/hip_module.cpp b/projects/clr/hipamd/src/hip_module.cpp index dc0a681c6d..c4b6cb8e08 100644 --- a/projects/clr/hipamd/src/hip_module.cpp +++ b/projects/clr/hipamd/src/hip_module.cpp @@ -202,7 +202,7 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname){ (*module)->size = size; in.seekg(0, std::ios::beg); std::copy(std::istreambuf_iterator(in), std::istreambuf_iterator(), ptr); - +/* Elf *e = elf_memory((char*)p, size); if(elf_kind(e) != ELF_K_ELF){ return ihipLogStatus(hipErrorInvalidValue); @@ -251,7 +251,7 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname){ } } } - +*/ status = hsa_code_object_deserialize(ptr, size, NULL, &(*module)->object); if(status != HSA_STATUS_SUCCESS){ From c48fd0b6eb3a3531d6251070992bb78549090e31 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Wed, 29 Mar 2017 16:36:46 +0300 Subject: [PATCH 33/56] [HIPIFY] Rename bash scripts. [ROCm/clr commit: 941adfc4c50de487faa5c5d2d51acd58358a64b8] --- .../clr/hipamd/bin/hipconvertinplace-perl.sh | 18 +++++++++++++ projects/clr/hipamd/bin/hipconvertinplace.sh | 26 ++++++++++++------- projects/clr/hipamd/bin/hipconvertinplace2.sh | 24 ----------------- projects/clr/hipamd/bin/hipexamine-perl.sh | 12 +++++++++ projects/clr/hipamd/bin/hipexamine.sh | 22 +++++++++++----- projects/clr/hipamd/bin/hipexamine2.sh | 22 ---------------- 6 files changed, 62 insertions(+), 62 deletions(-) create mode 100755 projects/clr/hipamd/bin/hipconvertinplace-perl.sh mode change 100755 => 100644 projects/clr/hipamd/bin/hipconvertinplace.sh delete mode 100644 projects/clr/hipamd/bin/hipconvertinplace2.sh create mode 100755 projects/clr/hipamd/bin/hipexamine-perl.sh mode change 100755 => 100644 projects/clr/hipamd/bin/hipexamine.sh delete mode 100644 projects/clr/hipamd/bin/hipexamine2.sh diff --git a/projects/clr/hipamd/bin/hipconvertinplace-perl.sh b/projects/clr/hipamd/bin/hipconvertinplace-perl.sh new file mode 100755 index 0000000000..a8c8d6d9e8 --- /dev/null +++ b/projects/clr/hipamd/bin/hipconvertinplace-perl.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#usage : hipconvertinplace.sh [DIRNAME] [HIPIFY_OPTIONS] + +#hipify "inplace" all code files in specified directory. +# This can be quite handy when dealing with an existing CUDA code base since the script +# preserves the existing directory structure. + +# For each code file, this script will: +# - If ".prehip file does not exist, copy the original code to a new file with extension ".prehip". Then Hipify the code file. +# - If ".prehip" file exists, this is used as input to hipify. +# (this is useful for testing improvements to the hipify toolset). + + +SCRIPT_DIR=`dirname $0` +SEARCH_DIR=$1 +shift +$SCRIPT_DIR/hipify -inplace -print-stats "$@" `$SCRIPT_DIR/findcode.sh $SEARCH_DIR` diff --git a/projects/clr/hipamd/bin/hipconvertinplace.sh b/projects/clr/hipamd/bin/hipconvertinplace.sh old mode 100755 new mode 100644 index a8c8d6d9e8..a765ab39fa --- a/projects/clr/hipamd/bin/hipconvertinplace.sh +++ b/projects/clr/hipamd/bin/hipconvertinplace.sh @@ -1,18 +1,24 @@ #!/bin/bash -#usage : hipconvertinplace.sh [DIRNAME] [HIPIFY_OPTIONS] +#usage : hipconvertinplace.sh DIRNAME [hipify options] [--] [clang options] -#hipify "inplace" all code files in specified directory. +#hipify "inplace" all code files in specified directory. # This can be quite handy when dealing with an existing CUDA code base since the script # preserves the existing directory structure. -# For each code file, this script will: -# - If ".prehip file does not exist, copy the original code to a new file with extension ".prehip". Then Hipify the code file. -# - If ".prehip" file exists, this is used as input to hipify. -# (this is useful for testing improvements to the hipify toolset). - - SCRIPT_DIR=`dirname $0` SEARCH_DIR=$1 -shift -$SCRIPT_DIR/hipify -inplace -print-stats "$@" `$SCRIPT_DIR/findcode.sh $SEARCH_DIR` + +hipify_args='' +while (( "$#" )); do + shift + if [ "$1" != "--" ]; then + hipify_args="$hipify_args $1" + else + shift + break + fi +done +clang_args="$@" + +$SCRIPT_DIR/hipify-clang -inplace -print-stats $hipify_args `$SCRIPT_DIR/findcode.sh $SEARCH_DIR` -- -x cuda $clang_args diff --git a/projects/clr/hipamd/bin/hipconvertinplace2.sh b/projects/clr/hipamd/bin/hipconvertinplace2.sh deleted file mode 100644 index a765ab39fa..0000000000 --- a/projects/clr/hipamd/bin/hipconvertinplace2.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -#usage : hipconvertinplace.sh DIRNAME [hipify options] [--] [clang options] - -#hipify "inplace" all code files in specified directory. -# This can be quite handy when dealing with an existing CUDA code base since the script -# preserves the existing directory structure. - -SCRIPT_DIR=`dirname $0` -SEARCH_DIR=$1 - -hipify_args='' -while (( "$#" )); do - shift - if [ "$1" != "--" ]; then - hipify_args="$hipify_args $1" - else - shift - break - fi -done -clang_args="$@" - -$SCRIPT_DIR/hipify-clang -inplace -print-stats $hipify_args `$SCRIPT_DIR/findcode.sh $SEARCH_DIR` -- -x cuda $clang_args diff --git a/projects/clr/hipamd/bin/hipexamine-perl.sh b/projects/clr/hipamd/bin/hipexamine-perl.sh new file mode 100755 index 0000000000..40c1bf466d --- /dev/null +++ b/projects/clr/hipamd/bin/hipexamine-perl.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +#usage : hipexamine.sh DIRNAME [hipify.pl options] + +# Generate HIP stats (LOC, CUDA->API conversions, missing functionality) for all the code files +# in the specified directory. + + +SCRIPT_DIR=`dirname $0` +SEARCH_DIR=$1 +shift +$SCRIPT_DIR/hipify -no-output -print-stats "$@" `$SCRIPT_DIR/findcode.sh $SEARCH_DIR` diff --git a/projects/clr/hipamd/bin/hipexamine.sh b/projects/clr/hipamd/bin/hipexamine.sh old mode 100755 new mode 100644 index 40c1bf466d..2a6fab7110 --- a/projects/clr/hipamd/bin/hipexamine.sh +++ b/projects/clr/hipamd/bin/hipexamine.sh @@ -1,12 +1,22 @@ #!/bin/bash -#usage : hipexamine.sh DIRNAME [hipify.pl options] - -# Generate HIP stats (LOC, CUDA->API conversions, missing functionality) for all the code files -# in the specified directory. +#usage : hipexamine2.sh DIRNAME [hipify options] [--] [clang options] +# Generate CUDA->HIP conversion statistics for all the code files in the specified directory. SCRIPT_DIR=`dirname $0` SEARCH_DIR=$1 -shift -$SCRIPT_DIR/hipify -no-output -print-stats "$@" `$SCRIPT_DIR/findcode.sh $SEARCH_DIR` + +hipify_args='' +while (( "$#" )); do + shift + if [ "$1" != "--" ]; then + hipify_args="$hipify_args $1" + else + shift + break + fi +done +clang_args="$@" + +$SCRIPT_DIR/hipify-clang -examine $hipify_args `$SCRIPT_DIR/findcode.sh $SEARCH_DIR` -- -x cuda $clang_args diff --git a/projects/clr/hipamd/bin/hipexamine2.sh b/projects/clr/hipamd/bin/hipexamine2.sh deleted file mode 100644 index 2a6fab7110..0000000000 --- a/projects/clr/hipamd/bin/hipexamine2.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -#usage : hipexamine2.sh DIRNAME [hipify options] [--] [clang options] - -# Generate CUDA->HIP conversion statistics for all the code files in the specified directory. - -SCRIPT_DIR=`dirname $0` -SEARCH_DIR=$1 - -hipify_args='' -while (( "$#" )); do - shift - if [ "$1" != "--" ]; then - hipify_args="$hipify_args $1" - else - shift - break - fi -done -clang_args="$@" - -$SCRIPT_DIR/hipify-clang -examine $hipify_args `$SCRIPT_DIR/findcode.sh $SEARCH_DIR` -- -x cuda $clang_args From bf84371e0d64f6d6d1002d91f07e027791d02d19 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Wed, 29 Mar 2017 09:02:39 -0500 Subject: [PATCH 34/56] Update GGL to fix one Torch build issue Change-Id: I95a2a335902e3c368ed29f075ac72eabbb64c97e [ROCm/clr commit: a32f50b5c7f13889855993534c49db96707f9dd7] --- .../include/hip/hcc_detail/grid_launch_v2.hpp | 164 +++++++++++++++++- .../hipamd/include/hip/hcc_detail/helpers.hpp | 8 +- 2 files changed, 167 insertions(+), 5 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index dfce53bd26..3d5d5c1ffe 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -210,6 +210,166 @@ namespace hip_impl // TODO: these are temporary, they need to be completely removed once we // enable C++14 support and can have proper generic, variadic lambdas. + #define make_kernel_lambda_hip_26(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16, p17, p18, p19, p20, p21, p22, p23, p24)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_,\ + const std::decay_t& _p17_,\ + const std::decay_t& _p18_,\ + const std::decay_t& _p19_,\ + const std::decay_t& _p20_,\ + const std::decay_t& _p21_,\ + const std::decay_t& _p22_,\ + const std::decay_t& _p23_,\ + const std::decay_t& _p24_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ + _p18_, _p19_, _p20_, _p21_, _p22_, _p23_, _p24_);\ + } + #define make_kernel_lambda_hip_25(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16, p17, p18, p19, p20, p21, p22, p23)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_,\ + const std::decay_t& _p17_,\ + const std::decay_t& _p18_,\ + const std::decay_t& _p19_,\ + const std::decay_t& _p20_,\ + const std::decay_t& _p21_,\ + const std::decay_t& _p22_,\ + const std::decay_t& _p23_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ + _p18_, _p19_, _p20_, _p21_, _p22_, _p23_);\ + } + #define make_kernel_lambda_hip_24(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16, p17, p18, p19, p20, p21, p22)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_,\ + const std::decay_t& _p17_,\ + const std::decay_t& _p18_,\ + const std::decay_t& _p19_,\ + const std::decay_t& _p20_,\ + const std::decay_t& _p21_,\ + const std::decay_t& _p22_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ + _p18_, _p19_, _p20_, _p21_, _p22_);\ + } + #define make_kernel_lambda_hip_23(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16, p17, p18, p19, p20, p21)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_,\ + const std::decay_t& _p17_,\ + const std::decay_t& _p18_,\ + const std::decay_t& _p19_,\ + const std::decay_t& _p20_,\ + const std::decay_t& _p21_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ + _p18_, _p19_, _p20_, _p21_);\ + } + #define make_kernel_lambda_hip_22(\ + kernel_name,\ + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ + p16, p17, p18, p19, p20)\ + [](const std::decay_t& _p0_,\ + const std::decay_t& _p1_,\ + const std::decay_t& _p2_,\ + const std::decay_t& _p3_,\ + const std::decay_t& _p4_,\ + const std::decay_t& _p5_,\ + const std::decay_t& _p6_,\ + const std::decay_t& _p7_,\ + const std::decay_t& _p8_,\ + const std::decay_t& _p9_,\ + const std::decay_t& _p10_,\ + const std::decay_t& _p11_,\ + const std::decay_t& _p12_,\ + const std::decay_t& _p13_,\ + const std::decay_t& _p14_,\ + const std::decay_t& _p15_,\ + const std::decay_t& _p16_,\ + const std::decay_t& _p17_,\ + const std::decay_t& _p18_,\ + const std::decay_t& _p19_,\ + const std::decay_t& _p20_) [[hc]] {\ + kernel_name(\ + _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ + _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ + _p18_, _p19_, _p20_);\ + } #define make_kernel_lambda_hip_21(\ kernel_name,\ p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15,\ @@ -237,7 +397,7 @@ namespace hip_impl kernel_name(\ _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ - _p18_, _p19_);\ + _p18_, _p19_);\ } #define make_kernel_lambda_hip_20(\ kernel_name,\ @@ -265,7 +425,7 @@ namespace hip_impl kernel_name(\ _p0_, _p1_, _p2_, _p3_, _p4_, _p5_, _p6_, _p7_, _p8_,\ _p9_, _p10_, _p11_, _p12_, _p13_, _p14_, _p15_, _p16_, _p17_,\ - _p18_);\ + _p18_);\ } #define make_kernel_lambda_hip_19(\ kernel_name,\ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp index 566612dce4..f12087faa9 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp @@ -127,11 +127,13 @@ namespace // Only for documentation, macros ignore namespaces. { #define count_macro_args_impl_hip_(\ _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15,\ - _16, _17, _18, _19, _20, _21, _n, ...) _n + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29,\ + _30, _31, _n, ...)\ + _n #define count_macro_args_hip_(...)\ count_macro_args_impl_hip_(\ - , ##__VA_ARGS__, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9,\ - 8, 7, 6, 5, 4, 3, 2, 1, 0) + , ##__VA_ARGS__, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,\ + 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) #define overloaded_macro_expand_hip_(macro, arg_cnt) macro##arg_cnt #define overload_macro_impl_hip_(macro, arg_cnt)\ From 0cab597d1614c11e26c688435aa3b51e567f1fb7 Mon Sep 17 00:00:00 2001 From: emankov Date: Wed, 29 Mar 2017 17:23:41 +0300 Subject: [PATCH 35/56] [HIPIFY] set execute mode for bash scripts [ROCm/clr commit: fee6eeed51043567fddc8b9d64859f037ca9464f] --- projects/clr/hipamd/bin/hipconvertinplace.sh | 0 projects/clr/hipamd/bin/hipexamine.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 projects/clr/hipamd/bin/hipconvertinplace.sh mode change 100644 => 100755 projects/clr/hipamd/bin/hipexamine.sh diff --git a/projects/clr/hipamd/bin/hipconvertinplace.sh b/projects/clr/hipamd/bin/hipconvertinplace.sh old mode 100644 new mode 100755 diff --git a/projects/clr/hipamd/bin/hipexamine.sh b/projects/clr/hipamd/bin/hipexamine.sh old mode 100644 new mode 100755 From 8b9145407780332487a63f3fd736128f0fe67fc0 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Thu, 30 Mar 2017 13:36:46 -0500 Subject: [PATCH 36/56] Enable GGL as the default kernel launch method Change-Id: I8022d126ee28ff7e4d9a96209e399d4243d39d8b [ROCm/clr commit: c081099de16502dfd1d791a91691b57278134b73] --- projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h | 2 +- projects/clr/hipamd/include/hip/hcc_detail/host_defines.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index 658e3d2f97..87e552a6cf 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -32,7 +32,7 @@ THE SOFTWARE. #include #ifndef GENERIC_GRID_LAUNCH -#define GENERIC_GRID_LAUNCH 0 +#define GENERIC_GRID_LAUNCH 1 #endif #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index ab975dbb2c..d077873797 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -32,7 +32,7 @@ THE SOFTWARE. // Add guard to Generic Grid Launch method #ifndef GENERIC_GRID_LAUNCH -#define GENERIC_GRID_LAUNCH 0 +#define GENERIC_GRID_LAUNCH 1 #endif #ifdef __HCC__ From b602d68f95edd548c891f3b3003eddf8cc9f4177 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Thu, 30 Mar 2017 15:03:09 -0500 Subject: [PATCH 37/56] update hip_faq.md on using GGL as default Change-Id: I6ce1112eedeac3b377fe55ad8445f3c465c2eed4 [ROCm/clr commit: 67e14da511d74e4a6fcf29200f5e772f8e51249a] --- projects/clr/hipamd/docs/markdown/hip_faq.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/projects/clr/hipamd/docs/markdown/hip_faq.md b/projects/clr/hipamd/docs/markdown/hip_faq.md index 5ad8d9e8a9..ee7e5dd347 100644 --- a/projects/clr/hipamd/docs/markdown/hip_faq.md +++ b/projects/clr/hipamd/docs/markdown/hip_faq.md @@ -27,6 +27,7 @@ * [Using CodeXL markers for HIP Functions](#using-codexl-markers-for-hip-functions) * [Using HIP_TRACE_API](#using-hip_trace_api) - [How do I enable HIP Generic Grid Launch option?](#how-do-i-enable-hip-generic-grid-launch-option) +- [What is the current limitation of HIP Generic Grid Launch method?](#what-is-the-current-limitation-of-hip-generic-grid-launch-method) @@ -236,11 +237,13 @@ Unlike CUDA, in HCC, for functions defined in the header files, the keyword of " Thus, if failed to define "static" keyword, you might see a lot of "symbol multiply defined!" errors at compilation. The workaround is to explicitly add the keyword of "static" before any functions that were defined as "__forceinline__". -### How do I enable HIP Generic Grid Launch option? -Generic Grid Launch(GGL) provide a second choice for kernel launch. -To enable it, either change the default value of GENERIC_GRID_LAUNCH to 1 in the following to header files and rebuild HIP: +### How do I disable HIP Generic Grid Launch option? +Generic Grid Launch(GGL) is currently the default method for hip kernel launch. +To disable it and use the legancy grid launch method, please either change the default value of GENERIC_GRID_LAUNCH to 0 in the following to header files and rebuild HIP: $HIP/include/hip/hcc_detail/hip_runtime_api.h $HIP/include/hip/hcc_detail/host_defines.h -Or pass "-DGENERIC_GRID_LAUNCH=1" to hipcc at application compilation time. +Or pass "-DGENERIC_GRID_LAUNCH=0" to hipcc at application compilation time. -GGL was only tested with Ubuntu16.04, assuming HCC and HIP only link against libstdc++ but not libc++. +### What is the current limitation of HIP Generic Grid Launch method? +1. __global__ functions cannot be marked as static or put in an unnamed namespace i.e. they cannot be given internal linkage (this would clash with __attribute__((weak))); +2. using the macro based dispatch mechanism i.e. hipLaunchKernel* only works for functions that take no more than 20 arguments (this limit can be increased up to 126, and is temporary until we can enable C++14 mode and use variadic generic lambdas); no such limitation applies do dispatching directly through grid_launch. \ No newline at end of file From 06684daac1e234dd51527deb8d9a8f18280e7fe1 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Thu, 30 Mar 2017 17:14:55 -0500 Subject: [PATCH 38/56] fix hipVectorTypesDevice direct test with GGL enabled Change-Id: I7a63b87348f08f094cd709e87397d9e0fc24e4c2 [ROCm/clr commit: 38c4331861d2dd43be5a2af01a9b9a605b2cd528] --- .../src/deviceLib/hipVectorTypesDevice.cpp | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/projects/clr/hipamd/tests/src/deviceLib/hipVectorTypesDevice.cpp b/projects/clr/hipamd/tests/src/deviceLib/hipVectorTypesDevice.cpp index 285b3e889e..265cd00b22 100644 --- a/projects/clr/hipamd/tests/src/deviceLib/hipVectorTypesDevice.cpp +++ b/projects/clr/hipamd/tests/src/deviceLib/hipVectorTypesDevice.cpp @@ -3874,7 +3874,22 @@ int main() { assert(sizeof(float2) == 8); assert(sizeof(float3) == 12); assert(sizeof(float4) == 16); - bool *ptr; - hipLaunchKernel(CheckVectorTypes, dim3(1,1,1), dim3(1,1,1), 0, 0, ptr); - passed(); + + bool* ptr = nullptr; + if (hipMalloc(&ptr, sizeof(bool)) != HIP_SUCCESS) return EXIT_FAILURE; + std::unique_ptr correct{ptr, hipFree}; + hipLaunchKernel( + CheckVectorTypes, dim3(1,1,1), dim3(1,1,1), 0, 0, correct.get()); + bool passed = false; + if (hipMemcpyDtoH(&passed, correct.get(), sizeof(bool)) != HIP_SUCCESS) { + return EXIT_FAILURE; + } + + if (passed == true){ + std::cout << "PASSED" << std::endl; + return 0; + } + else + return EXIT_FAILURE; } + From 56b2c7d82ec87e6ac9108e98e5169758c681c62a Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Thu, 30 Mar 2017 18:10:17 -0500 Subject: [PATCH 39/56] Rename hipLaunchKernelV3 to hipLaunchKernelGGL Change-Id: I303daae006db41e9b04eb591e0b09b2717a7cf66 [ROCm/clr commit: 9983fdb9e2367b423e323c75711330abf59f14fb] --- projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index 3d5d5c1ffe..b59cbd01aa 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -693,7 +693,7 @@ namespace hip_impl #define make_kernel_lambda_hip_(...)\ overload_macro_hip_(make_kernel_lambda_hip_, __VA_ARGS__) - #define hipLaunchKernelV3(\ + #define hipLaunchKernelGGL(\ kernel_name,\ num_blocks,\ dim_blocks,\ @@ -718,7 +718,7 @@ namespace hip_impl stream,\ ...)\ {\ - hipLaunchKernelV3(\ + hipLaunchKernelGGL(\ kernel_name,\ num_blocks,\ dim_blocks,\ From ace18c6a57d6d6240f4cd12945606de8fdd7b948 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Thu, 30 Mar 2017 18:16:56 -0500 Subject: [PATCH 40/56] remove extra GGL header info Change-Id: I09f0d1b64a7a31eb2e926f19b69b7bafbacc7787 [ROCm/clr commit: e3a4547703f8ff13d66c76256854c61aefa855f7] --- projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp | 3 --- projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp | 3 --- 2 files changed, 6 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp b/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp index c746c1cfe6..6824ad9bdf 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp @@ -20,9 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// -// Created by alexv on 25/10/16. -// #pragma once namespace glo_tests // Documentation only. diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index b59cbd01aa..b360d4c19d 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -20,9 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// -// Created by alexv on 25/10/16. -// #pragma once #include "concepts.hpp" From 3651cb672ac75523d7204c19d6eea8337fe239db Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Fri, 31 Mar 2017 12:11:34 -0500 Subject: [PATCH 41/56] added new api hipHccModuleLaunchKernel 1. hipHccModuleLaunchKernel is same as hipModuleLaunchKernel with OpenCL workitem model 2. Added copy right 3. Fixed header naming Change-Id: I6a7c35a3566e2f8d3f5056613e34193775d4b236 [ROCm/clr commit: 1cead6a4cd478ab74bdf42a5e2b3e58dfbf066ef] --- .../hipamd/include/hip/channel_descriptor.h | 7 +- .../clr/hipamd/include/hip/device_functions.h | 9 +- .../clr/hipamd/include/hip/driver_types.h | 13 +- .../hip/hcc_detail/channel_descriptor.h | 6 +- .../hipamd/include/hip/hcc_detail/hcc_acc.h | 13 + .../hipamd/include/hip/hcc_detail/hip_hcc.h | 62 ++ projects/clr/hipamd/include/hip/hip_common.h | 7 +- projects/clr/hipamd/include/hip/hip_complex.h | 7 +- projects/clr/hipamd/include/hip/hip_fp16.h | 7 +- .../hipamd/include/hip/{hcc.h => hip_hcc.h} | 8 +- projects/clr/hipamd/include/hip/hip_profile.h | 7 +- projects/clr/hipamd/include/hip/hip_runtime.h | 7 +- .../clr/hipamd/include/hip/hip_runtime_api.h | 5 +- projects/clr/hipamd/include/hip/hip_texture.h | 8 +- .../clr/hipamd/include/hip/hip_vector_types.h | 7 +- .../clr/hipamd/include/hip/math_functions.h | 7 +- .../clr/hipamd/include/hip/texture_types.h | 10 +- .../samples/0_Intro/module_api/runKernel.cpp | 18 +- .../0_Intro/module_api/vcpy_kernel.cpp | 3 +- projects/clr/hipamd/src/env.cpp | 24 +- projects/clr/hipamd/src/hip_context.cpp | 4 +- projects/clr/hipamd/src/hip_device.cpp | 4 +- projects/clr/hipamd/src/hip_error.cpp | 4 +- projects/clr/hipamd/src/hip_event.cpp | 4 +- projects/clr/hipamd/src/hip_hcc.cpp | 8 +- projects/clr/hipamd/src/hip_hcc_internal.h | 885 ++++++++++++++++++ projects/clr/hipamd/src/hip_memory.cpp | 12 +- projects/clr/hipamd/src/hip_module.cpp | 65 +- projects/clr/hipamd/src/hip_peer.cpp | 4 +- projects/clr/hipamd/src/hip_stream.cpp | 4 +- 30 files changed, 1138 insertions(+), 91 deletions(-) create mode 100644 projects/clr/hipamd/include/hip/hcc_detail/hip_hcc.h rename projects/clr/hipamd/include/hip/{hcc.h => hip_hcc.h} (85%) create mode 100644 projects/clr/hipamd/src/hip_hcc_internal.h diff --git a/projects/clr/hipamd/include/hip/channel_descriptor.h b/projects/clr/hipamd/include/hip/channel_descriptor.h index af8875e256..b8e750b079 100644 --- a/projects/clr/hipamd/include/hip/channel_descriptor.h +++ b/projects/clr/hipamd/include/hip/channel_descriptor.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_CHANNEL_DESCRIPTOR_H +#define HIP_INCLUDE_HIP_CHANNEL_DESCRIPTOR_H // Some standard header files, these are included by hc.hpp and so want to make them avail on both // paths to provide a consistent include env and avoid "missing symbol" errors that only appears @@ -34,3 +35,5 @@ THE SOFTWARE. #else #error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__"); #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/device_functions.h b/projects/clr/hipamd/include/hip/device_functions.h index 24211b7d2d..aae6775d48 100644 --- a/projects/clr/hipamd/include/hip/device_functions.h +++ b/projects/clr/hipamd/include/hip/device_functions.h @@ -1,13 +1,16 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -17,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_DEVICE_FUNCTIONS_H -#define HIP_DEVICE_FUNCTIONS_H +#ifndef HIP_INCLUDE_HIP_DEVICE_FUNCTIONS_H +#define HIP_INCLUDE_HIP_DEVICE_FUNCTIONS_H #include diff --git a/projects/clr/hipamd/include/hip/driver_types.h b/projects/clr/hipamd/include/hip/driver_types.h index a4010d6b4e..5d06457dd5 100644 --- a/projects/clr/hipamd/include/hip/driver_types.h +++ b/projects/clr/hipamd/include/hip/driver_types.h @@ -1,22 +1,27 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_DRIVER_TYPES_H +#define HIP_INCLUDE_HIP_DRIVER_TYPES_H #include @@ -27,3 +32,5 @@ THE SOFTWARE. #else #error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__"); #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/hcc_detail/channel_descriptor.h b/projects/clr/hipamd/include/hip/hcc_detail/channel_descriptor.h index 85689438e2..4be023f6ca 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/channel_descriptor.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/channel_descriptor.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_HCC_DETAIL_CHANNEL_DESCRIPTOR_H -#define HIP_HCC_DETAIL_CHANNEL_DESCRIPTOR_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_CHANNEL_DESCRIPTOR_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_CHANNEL_DESCRIPTOR_H #include #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hcc_acc.h b/projects/clr/hipamd/include/hip/hcc_detail/hcc_acc.h index c36acc52f5..962f795d6f 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hcc_acc.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hcc_acc.h @@ -40,6 +40,19 @@ hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc); * @return #hipSuccess */ hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view **av); + + +hipError_t hipHccModuleLaunchKernel(hipFunction_t f, + uint32_t globalWorkSizeX, + uint32_t globalWorkSizeY, + uint32_t globalWorkSizeZ, + uint32_t localWorkSizeX, + uint32_t localWorkSizeY, + uint32_t localWorkSizeZ, + size_t sharedMemBytes, + hipStream_t hStream, + void **kernelParams, + void **extra); #endif #endif diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_hcc.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_hcc.h new file mode 100644 index 0000000000..645e980376 --- /dev/null +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_hcc.h @@ -0,0 +1,62 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_HCC_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_HCC_H + +#include "hip/hip_runtime_api.h" + +#if __cplusplus +#ifdef __HCC__ +#include +/** + * @brief Return hc::accelerator associated with the specified deviceId + * @return #hipSuccess, #hipErrorInvalidDevice + */ +hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc); + +/** + * @brief Return hc::accelerator_view associated with the specified stream + * + * If stream is 0, the accelerator_view for the default stream is returned. + * @return #hipSuccess + */ +hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view **av); + + +#endif // #ifdef __HCC__ + +hipError_t hipHccModuleLaunchKernel(hipFunction_t f, + uint32_t globalWorkSizeX, + uint32_t globalWorkSizeY, + uint32_t globalWorkSizeZ, + uint32_t localWorkSizeX, + uint32_t localWorkSizeY, + uint32_t localWorkSizeZ, + size_t sharedMemBytes, + hipStream_t hStream, + void **kernelParams, + void **extra); + +#endif // #if __cplusplus + +#endif // diff --git a/projects/clr/hipamd/include/hip/hip_common.h b/projects/clr/hipamd/include/hip/hip_common.h index 6317a792ee..da8ec4a55d 100644 --- a/projects/clr/hipamd/include/hip/hip_common.h +++ b/projects/clr/hipamd/include/hip/hip_common.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_HIP_COMMON_H +#define HIP_INCLUDE_HIP_HIP_COMMON_H // Common code included at start of every hip file. // Auto enable __HIP_PLATFORM_HCC__ if compiling with HCC @@ -73,3 +74,5 @@ THE SOFTWARE. #define __HIP_ARCH_HAS_3DGRID__ (0) #define __HIP_ARCH_HAS_DYNAMIC_PARALLEL__ (0) #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/hip_complex.h b/projects/clr/hipamd/include/hip/hip_complex.h index ea15137894..dc691be480 100644 --- a/projects/clr/hipamd/include/hip/hip_complex.h +++ b/projects/clr/hipamd/include/hip/hip_complex.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_HIP_COMPLEX_H +#define HIP_INCLUDE_HIP_HIP_COMPLEX_H #include @@ -31,3 +32,5 @@ THE SOFTWARE. #else #error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__"); #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/hip_fp16.h b/projects/clr/hipamd/include/hip/hip_fp16.h index 2f64c1a143..0e002d9396 100644 --- a/projects/clr/hipamd/include/hip/hip_fp16.h +++ b/projects/clr/hipamd/include/hip/hip_fp16.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifdef HIP_INCLUDE_HIP_HIP_FP16_H +#define HIP_INCLUDE_HIP_HIP_FP16_H #include @@ -31,3 +32,5 @@ THE SOFTWARE. #else #error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__"); #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/hcc.h b/projects/clr/hipamd/include/hip/hip_hcc.h similarity index 85% rename from projects/clr/hipamd/include/hip/hcc.h rename to projects/clr/hipamd/include/hip/hip_hcc.h index 9b8a649412..3407a311bd 100644 --- a/projects/clr/hipamd/include/hip/hcc.h +++ b/projects/clr/hipamd/include/hip/hip_hcc.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,11 +20,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_HCC_H -#define HIP_HCC_H +#ifndef HIP_INCLUDE_HIP_HIP_HCC_H +#define HIP_INCLUDE_HIP_HIP_HCC_H #if defined(__HIP_PLATFORM_HCC__) && !defined (__HIP_PLATFORM_NVCC__) -#include "hip/hcc_detail/hcc_acc.h" +#include "hip/hcc_detail/hip_hcc.h" #endif #endif diff --git a/projects/clr/hipamd/include/hip/hip_profile.h b/projects/clr/hipamd/include/hip/hip_profile.h index e621ae8c79..389f334c74 100644 --- a/projects/clr/hipamd/include/hip/hip_profile.h +++ b/projects/clr/hipamd/include/hip/hip_profile.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_HIP_PROFILE_H +#define HIP_INCLUDE_HIP_HIP_PROFILE_H #if not defined (ENABLE_HIP_PROFILE) #define ENABLE_HIP_PROFILE 1 @@ -36,3 +37,5 @@ THE SOFTWARE. #define HIP_BEGIN_MARKER(markerName, group) #define HIP_END_MARKER() #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/hip_runtime.h b/projects/clr/hipamd/include/hip/hip_runtime.h index 9bc45f300d..fba4d46d8f 100644 --- a/projects/clr/hipamd/include/hip/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hip_runtime.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -33,7 +33,8 @@ THE SOFTWARE. //! hip_runtime.h : includes everything in hip_api.h, plus math builtins and kernel launch macros. //! hip_runtime_api.h : Defines HIP API. This is a C header file and does not use any C++ features. -#pragma once +#ifndef HIP_INCLUDE_HIP_HIP_RUNTIME_H +#define HIP_INCLUDE_HIP_HIP_RUNTIME_H // Some standard header files, these are included by hc.hpp and so want to make them avail on both // paths to provide a consistent include env and avoid "missing symbol" errors that only appears @@ -61,3 +62,5 @@ THE SOFTWARE. #include #include + +#endif diff --git a/projects/clr/hipamd/include/hip/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hip_runtime_api.h index 818c0b7c34..5715be0599 100644 --- a/projects/clr/hipamd/include/hip/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hip_runtime_api.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -27,7 +27,8 @@ THE SOFTWARE. * This file can be compiled with a standard compiler. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_HIP_RUNTIME_API_H +#define HIP_INCLUDE_HIP_HIP_RUNTIME_API_H #include // for getDeviceProp diff --git a/projects/clr/hipamd/include/hip/hip_texture.h b/projects/clr/hipamd/include/hip/hip_texture.h index 66ec4a6ca1..a15c5a1016 100644 --- a/projects/clr/hipamd/include/hip/hip_texture.h +++ b/projects/clr/hipamd/include/hip/hip_texture.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,10 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - - -#ifndef HIP_HIP_TEXTURE_H -#define HIP_HIP_TEXTURE_H +#ifndef HIP_INCLUDE_HIP_HIP_TEXTURE_H +#define HIP_INCLUDE_HIP_HIP_TEXTURE_H #if defined(__HIP_PLATFORM_HCC__) && !defined (__HIP_PLATFORM_NVCC__) #include diff --git a/projects/clr/hipamd/include/hip/hip_vector_types.h b/projects/clr/hipamd/include/hip/hip_vector_types.h index 33827e4d96..1d3d6b92f6 100644 --- a/projects/clr/hipamd/include/hip/hip_vector_types.h +++ b/projects/clr/hipamd/include/hip/hip_vector_types.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,8 @@ THE SOFTWARE. //! hip_vector_types.h : Defines the HIP vector types. -#pragma once +#ifndef HIP_INCLUDE_HIP_HIP_VECTOR_TYPES_H +#define HIP_INCLUDE_HIP_HIP_VECTOR_TYPES_H #include @@ -36,3 +37,5 @@ THE SOFTWARE. #else #error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__"); #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/math_functions.h b/projects/clr/hipamd/include/hip/math_functions.h index ebcdc26749..6f47b5e0e2 100644 --- a/projects/clr/hipamd/include/hip/math_functions.h +++ b/projects/clr/hipamd/include/hip/math_functions.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_MATH_FUNCTIONS_H +#define HIP_INCLUDE_HIP_MATH_FUNCTIONS_H // Some standard header files, these are included by hc.hpp and so want to make them avail on both // paths to provide a consistent include env and avoid "missing symbol" errors that only appears @@ -34,3 +35,5 @@ THE SOFTWARE. #else #error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__"); #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/texture_types.h b/projects/clr/hipamd/include/hip/texture_types.h index 2561e12eb5..ca6101cf79 100644 --- a/projects/clr/hipamd/include/hip/texture_types.h +++ b/projects/clr/hipamd/include/hip/texture_types.h @@ -1,13 +1,16 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -17,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_TEXTURE_TYPES_H +#define HIP_INCLUDE_HIP_TEXTURE_TYPES_H #include @@ -28,3 +32,5 @@ THE SOFTWARE. #else #error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__"); #endif + +#endif diff --git a/projects/clr/hipamd/samples/0_Intro/module_api/runKernel.cpp b/projects/clr/hipamd/samples/0_Intro/module_api/runKernel.cpp index 201892a4a1..e7d54beb54 100644 --- a/projects/clr/hipamd/samples/0_Intro/module_api/runKernel.cpp +++ b/projects/clr/hipamd/samples/0_Intro/module_api/runKernel.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,9 +22,10 @@ THE SOFTWARE. #include "hip/hip_runtime.h" #include "hip/hip_runtime_api.h" -#include -#include -#include +#include +#include +#include +#include #define LEN 64 #define SIZE LEN<<2 @@ -43,10 +44,10 @@ int main(){ B[i] = 0.0f; } - hipInit(0); - hipDevice_t device; - hipCtx_t context; - hipDeviceGet(&device, 0); + hipInit(0); + hipDevice_t device; + hipCtx_t context; + hipDeviceGet(&device, 0); hipCtxCreate(&context, 0, device); hipMalloc((void**)&Ad, SIZE); @@ -101,6 +102,7 @@ int main(){ hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, 0, NULL, (void**)&config); hipMemcpyDtoH(B, Bd, SIZE); + int mismatchCount = 0; for(uint32_t i=0;i #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" // Stack of contexts diff --git a/projects/clr/hipamd/src/hip_device.cpp b/projects/clr/hipamd/src/hip_device.cpp index d3c68e6fdf..88d94411e8 100644 --- a/projects/clr/hipamd/src/hip_device.cpp +++ b/projects/clr/hipamd/src/hip_device.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ THE SOFTWARE. */ #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" #include "device_util.h" diff --git a/projects/clr/hipamd/src/hip_error.cpp b/projects/clr/hipamd/src/hip_error.cpp index 4c14ba4156..21d5b6aa85 100644 --- a/projects/clr/hipamd/src/hip_error.cpp +++ b/projects/clr/hipamd/src/hip_error.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ THE SOFTWARE. */ #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" //------------------------------------------------------------------------------------------------- diff --git a/projects/clr/hipamd/src/hip_event.cpp b/projects/clr/hipamd/src/hip_event.cpp index 5a0ed9d8f8..d44f201db5 100644 --- a/projects/clr/hipamd/src/hip_event.cpp +++ b/projects/clr/hipamd/src/hip_event.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ THE SOFTWARE. */ #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" //------------------------------------------------------------------------------------------------- diff --git a/projects/clr/hipamd/src/hip_hcc.cpp b/projects/clr/hipamd/src/hip_hcc.cpp index e422a6d4db..374840f91f 100644 --- a/projects/clr/hipamd/src/hip_hcc.cpp +++ b/projects/clr/hipamd/src/hip_hcc.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -43,7 +43,7 @@ THE SOFTWARE. #include "hsa/hsa_ext_amd.h" #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" #include "env.h" @@ -762,7 +762,7 @@ hipError_t ihipDevice_t::initProperties(hipDeviceProp_t* prop) err = hsa_agent_get_info(_hsaAgent, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_PRODUCT_NAME, &(prop->name)); char archName[256]; err = hsa_agent_get_info(_hsaAgent, HSA_AGENT_INFO_NAME, &archName); - + if(strcmp(archName,"gfx701")==0){ prop->gcnArch = 701; } @@ -1805,7 +1805,7 @@ void ihipStream_t::resolveHcMemcpyDirection(unsigned hipMemKind, void printPointerInfo(unsigned dbFlag, const char *tag, const void *ptr, const hc::AmPointerInfo &ptrInfo) { tprintf (dbFlag, " %s=%p baseHost=%p baseDev=%p sz=%zu home_dev=%d tracked=%d isDevMem=%d registered=%d\n", - tag, ptr, + tag, ptr, ptrInfo._hostPointer, ptrInfo._devicePointer, ptrInfo._sizeBytes, ptrInfo._appId, ptrInfo._sizeBytes != 0, ptrInfo._isInDeviceMem, !ptrInfo._isAmManaged); } diff --git a/projects/clr/hipamd/src/hip_hcc_internal.h b/projects/clr/hipamd/src/hip_hcc_internal.h new file mode 100644 index 0000000000..245f154305 --- /dev/null +++ b/projects/clr/hipamd/src/hip_hcc_internal.h @@ -0,0 +1,885 @@ +/* +Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef HIP_HCC_H +#define HIP_HCC_H + +#include +#include +#include "hsa/hsa_ext_amd.h" + +#include "hip/hip_runtime.h" +#include "hip_util.h" +#include "env.h" + + +#if defined(__HCC__) && (__hcc_workweek__ < 16354) +#error("This version of HIP requires a newer version of HCC."); +#endif + +#define USE_IPC 1 + +//--- +// Environment variables: + +// Intended to distinguish whether an environment variable should be visible only in debug mode, or in debug+release. +//static const int debug = 0; +extern const int release; + +// TODO - this blocks both kernels and memory ops. Perhaps should have separate env var for kernels? +extern int HIP_LAUNCH_BLOCKING; +extern int HIP_API_BLOCKING; + +extern int HIP_PRINT_ENV; +extern int HIP_PROFILE_API; +//extern int HIP_TRACE_API; +extern int HIP_ATP; +extern int HIP_DB; +extern int HIP_STAGING_SIZE; /* size of staging buffers, in KB */ +extern int HIP_STREAM_SIGNALS; /* number of signals to allocate at stream creation */ +extern int HIP_VISIBLE_DEVICES; /* Contains a comma-separated sequence of GPU identifiers */ +extern int HIP_FORCE_P2P_HOST; + +extern int HIP_COHERENT_HOST_ALLOC; + + +//--- +// Chicken bits for disabling functionality to work around potential issues: +extern int HIP_SYNC_HOST_ALLOC; + +// TODO - remove when this is standard behavior. +extern int HCC_OPT_FLUSH; + + +// Class to assign a short TID to each new thread, for HIP debugging purposes. +class TidInfo { +public: + + TidInfo() ; + + int tid() const { return _shortTid; }; + uint64_t incApiSeqNum() { return ++_apiSeqNum; }; + uint64_t apiSeqNum() const { return _apiSeqNum; }; + +private: + int _shortTid; + + // monotonically increasing API sequence number for this threa. + uint64_t _apiSeqNum; +}; + +struct ProfTrigger { + + static const uint64_t MAX_TRIGGER = std::numeric_limits::max(); + + void print (int tid) { + std::cout << "Enabling tracing for "; + for (auto iter=_profTrigger.begin(); iter != _profTrigger.end(); iter++) { + std::cout << "tid:" << tid << "." << *iter << ","; + } + std::cout << "\n"; + }; + + uint64_t nextTrigger() { return _profTrigger.empty() ? MAX_TRIGGER : _profTrigger.back(); }; + void add(uint64_t trigger) { _profTrigger.push_back(trigger); }; + void sort() { std::sort (_profTrigger.begin(), _profTrigger.end(), std::greater()); }; +private: + std::vector _profTrigger; +}; + + + +//--- +//Extern tls +extern thread_local hipError_t tls_lastHipError; +extern thread_local TidInfo tls_tidInfo; + +extern std::vector g_dbStartTriggers; +extern std::vector g_dbStopTriggers; + +//--- +//Forward defs: +class ihipStream_t; +class ihipDevice_t; +class ihipCtx_t; + +// Color defs for debug messages: +#define KNRM "\x1B[0m" +#define KRED "\x1B[31m" +#define KGRN "\x1B[32m" +#define KYEL "\x1B[33m" +#define KBLU "\x1B[34m" +#define KMAG "\x1B[35m" +#define KCYN "\x1B[36m" +#define KWHT "\x1B[37m" + +extern const char *API_COLOR; +extern const char *API_COLOR_END; + + +// If set, thread-safety is enforced on all stream functions. +// Stream functions will acquire a mutex before entering critical sections. +#define STREAM_THREAD_SAFE 1 + + +#define CTX_THREAD_SAFE 1 + +#define DEVICE_THREAD_SAFE 1 + + +// Compile debug trace mode - this prints debug messages to stderr when env var HIP_DB is set. +// May be set to 0 to remove debug if checks - possible code size and performance difference? +#define COMPILE_HIP_DB 1 + + +// Compile HIP tracing capability. +// 0x1 = print a string at function entry with arguments. +// 0x2 = prints a simple message with function name + return code when function exits. +// 0x3 = print both. +// Must be enabled at runtime with HIP_TRACE_API +#define COMPILE_HIP_TRACE_API 0x3 + + +// Compile code that generates trace markers for CodeXL ATP at HIP function begin/end. +// ATP is standard CodeXL format that includes timestamps for kernels, HSA RT APIs, and HIP APIs. +#ifndef COMPILE_HIP_ATP_MARKER +#define COMPILE_HIP_ATP_MARKER 0 +#endif + + + + +// Compile support for trace markers that are displayed on CodeXL GUI at start/stop of each function boundary. +// TODO - currently we print the trace message at the beginning. if we waited, we could also tls_tidInfo return codes, and any values returned +// through ptr-to-args (ie the pointers allocated by hipMalloc). +#if COMPILE_HIP_ATP_MARKER +#include "CXLActivityLogger.h" +#define MARKER_BEGIN(markerName,group) amdtBeginMarker(markerName, group, nullptr); +#define MARKER_END() amdtEndMarker(); +#define RESUME_PROFILING amdtResumeProfiling(AMDT_ALL_PROFILING); +#define STOP_PROFILING amdtStopProfiling(AMDT_ALL_PROFILING); +#else +// Swallow scoped markers: +#define MARKER_BEGIN(markerName,group) +#define MARKER_END() +#define RESUME_PROFILING +#define STOP_PROFILING +#endif + + +//--- +//HIP Trace modes +#define TRACE_ALL 0 // 0x1 +#define TRACE_CMD 1 // 0x2 +#define TRACE_MEM 2 // 0x4 + + +//--- +//HIP_DB Debug flags: +#define DB_API 0 /* 0x01 - shortcut to enable HIP_TRACE_API on single switch */ +#define DB_SYNC 1 /* 0x02 - trace synchronization pieces */ +#define DB_MEM 2 /* 0x04 - trace memory allocation / deallocation */ +#define DB_COPY 3 /* 0x08 - trace memory copy and peer commands. . */ +#define DB_MAX_FLAG 4 +// When adding a new debug flag, also add to the char name table below. +// +// + +struct DbName { + const char *_color; + const char *_shortName; +}; + +// This table must be kept in-sync with the defines above. +static const DbName dbName [] = +{ + {KGRN, "api"}, // not used, + {KYEL, "sync"}, + {KCYN, "mem"}, + {KMAG, "copy"}, +}; + + + +#if COMPILE_HIP_DB +#define tprintf(trace_level, ...) {\ + if (HIP_DB & (1<<(trace_level))) {\ + char msgStr[1000];\ + snprintf(msgStr, 2000, __VA_ARGS__);\ + fprintf (stderr, " %ship-%s tid:%d:%s%s", dbName[trace_level]._color, dbName[trace_level]._shortName, tls_tidInfo.tid(), msgStr, KNRM); \ + }\ +} +#else +/* Compile to empty code */ +#define tprintf(trace_level, ...) +#endif + + + + +//--- +extern void recordApiTrace(std::string *fullStr, const std::string &apiStr); + +#if COMPILE_HIP_ATP_MARKER || (COMPILE_HIP_TRACE_API & 0x1) +#define API_TRACE(forceTrace, ...)\ +{\ + tls_tidInfo.incApiSeqNum();\ + if (forceTrace || (HIP_PROFILE_API || (COMPILE_HIP_DB && (HIP_TRACE_API & (1<>%s\n", (localHipStatus == 0) ? API_COLOR:KRED, tls_tidInfo.tid(),tls_tidInfo.apiSeqNum(), __func__, localHipStatus, ihipErrorString(localHipStatus), API_COLOR_END);\ + }\ + if (HIP_PROFILE_API) { MARKER_END(); }\ + localHipStatus;\ + }) + + + + + + +class ihipException : public std::exception +{ +public: + ihipException(hipError_t e) : _code(e) {}; + + hipError_t _code; +}; + + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +const hipStream_t hipStreamNull = 0x0; + + +/** + * HIP IPC Handle Size + */ +#define HIP_IPC_RESERVED_SIZE 24 +class ihipIpcMemHandle_t +{ +public: +#if USE_IPC + hsa_amd_ipc_memory_t ipc_handle; ///< ipc memory handle on ROCr +#endif + size_t psize; + char reserved[HIP_IPC_RESERVED_SIZE]; +}; + + +class ihipModule_t { +public: + hsa_executable_t executable; + hsa_code_object_t object; + std::string fileName; + void *ptr; + size_t size; + std::list funcTrack; + ihipModule_t() : executable(), object(), fileName(), ptr(nullptr), size(0) {} +}; + + +//--- +// Used to remove lock, for performance or stimulating bugs. +class FakeMutex +{ + public: + void lock() { } + bool try_lock() {return true; } + void unlock() { } +}; + + +#if STREAM_THREAD_SAFE +typedef std::mutex StreamMutex; +#else +#warning "Stream thread-safe disabled" +typedef FakeMutex StreamMutex; +#endif + +// Pair Device and Ctx together, these could also be toggled separately if desired. +#if CTX_THREAD_SAFE +typedef std::mutex CtxMutex; +#else +typedef FakeMutex CtxMutex; +#warning "Ctx thread-safe disabled" +#endif + +#if DEVICE_THREAD_SAFE +typedef std::mutex DeviceMutex; +#else +typedef FakeMutex DeviceMutex; +#warning "Device thread-safe disabled" +#endif + +// +//--- +// Protects access to the member _data with a lock acquired on contruction/destruction. +// T must contain a _mutex field which meets the BasicLockable requirements (lock/unlock) +template +class LockedAccessor +{ +public: + LockedAccessor(T &criticalData, bool autoUnlock=true) : + _criticalData(&criticalData), + _autoUnlock(autoUnlock) + + { + tprintf(DB_SYNC, "locking criticalData=%p for %s..\n", _criticalData, ToString(_criticalData->_parent).c_str()); + _criticalData->_mutex.lock(); + }; + + ~LockedAccessor() + { + if (_autoUnlock) { + tprintf(DB_SYNC, "auto-unlocking criticalData=%p for %s...\n", _criticalData, ToString(_criticalData->_parent).c_str()); + _criticalData->_mutex.unlock(); + } + } + + void unlock() + { + tprintf(DB_SYNC, "unlocking criticalData=%p for %s...\n", _criticalData, ToString(_criticalData->_parent).c_str()); + _criticalData->_mutex.unlock(); + } + + // Syntactic sugar so -> can be used to get the underlying type. + T *operator->() { return _criticalData; }; + +private: + T *_criticalData; + bool _autoUnlock; +}; + + +template +struct LockedBase { + + // Experts-only interface for explicit locking. + // Most uses should use the lock-accessor. + void lock() { _mutex.lock(); } + void unlock() { _mutex.unlock(); } + bool try_lock() { return _mutex.try_lock(); } + + MUTEX_TYPE _mutex; +}; + + +template +class ihipStreamCriticalBase_t : public LockedBase +{ +public: + ihipStreamCriticalBase_t(ihipStream_t *parentStream, hc::accelerator_view av) : + _kernelCnt(0), + _av(av), + _hasQueue(true), + _parent(parentStream) + { + }; + + ~ihipStreamCriticalBase_t() { + } + + ihipStreamCriticalBase_t * mlock() { LockedBase::lock(); return this;}; + + void munlock() { + tprintf(DB_SYNC, "munlocking criticalData=%p for %s...\n", this, ToString(this->_parent).c_str()); + LockedBase::unlock(); + }; + + ihipStreamCriticalBase_t * mtry_lock() { + bool gotLock = LockedBase::try_lock() ; + tprintf(DB_SYNC, "mtry_locking=%d criticalData=%p for %s...\n", gotLock, this, ToString(this->_parent).c_str()); + return gotLock ? this: nullptr; + }; + +public: + ihipStream_t * _parent; + uint32_t _kernelCnt; // Count of inflight kernels in this stream. Reset at ::wait(). + + hc::accelerator_view _av; + + // True if the stream has an allocated queue (accelerato_view) for its use: + // Always true at ihipStream creation but queue may later be stolen. + // This acts as a valid bit for the _av. + bool _hasQueue; +private: +}; + + +// if HIP code needs to acquire locks for both ihipCtx_t and ihipStream_t, it should first acquire the lock +// for the ihipCtx_t and then for the individual streams. The locks should not be acquired in reverse order +// or deadlock may occur. In some cases, it may be possible to reduce the range where the locks must be held. +// HIP routines should avoid acquiring and releasing the same lock during the execution of a single HIP API. +// Another option is to use try_lock in the innermost lock query. + + +typedef ihipStreamCriticalBase_t ihipStreamCritical_t; +typedef LockedAccessor LockedAccessor_StreamCrit_t; + +//--- +// Internal stream structure. +class ihipStream_t { +public: + enum ScheduleMode {Auto, Spin, Yield}; + typedef uint64_t SeqNum_t ; + + // TODOD -make av a reference to avoid shared_ptr overhead? + ihipStream_t(ihipCtx_t *ctx, hc::accelerator_view av, unsigned int flags); + ~ihipStream_t(); + + // kind is hipMemcpyKind + void locked_copySync (void* dst, const void* src, size_t sizeBytes, unsigned kind, bool resolveOn = true); + void locked_copyAsync(void* dst, const void* src, size_t sizeBytes, unsigned kind); + + void lockedSymbolCopySync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, size_t offset, unsigned kind); + void lockedSymbolCopyAsync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, size_t offset, unsigned kind); + + //--- + // Member functions that begin with locked_ are thread-safe accessors - these acquire / release the critical mutex. + LockedAccessor_StreamCrit_t lockopen_preKernelCommand(); + void lockclose_postKernelCommand(const char *kernelName, hc::accelerator_view *av); + + + void locked_wait(); + + hc::accelerator_view* locked_getAv() { LockedAccessor_StreamCrit_t crit(_criticalData); return &(crit->_av); }; + + void locked_waitEvent(hipEvent_t event); + void locked_recordEvent(hipEvent_t event); + + + //--- + + // Use this if we already have the stream critical data mutex: + void wait(LockedAccessor_StreamCrit_t &crit); + + void launchModuleKernel(hc::accelerator_view av, hsa_signal_t signal, + uint32_t blockDimX, uint32_t blockDimY, uint32_t blockDimZ, + uint32_t gridDimX, uint32_t gridDimY, uint32_t gridDimZ, + uint32_t groupSegmentSize, uint32_t sharedMemBytes, + void *kernarg, size_t kernSize, uint64_t kernel); + + + + //-- Non-racy accessors: + // These functions access fields set at initialization time and are non-racy (so do not acquire mutex) + const ihipDevice_t * getDevice() const; + ihipCtx_t * getCtx() const; + + void ensureHaveQueue(LockedAccessor_StreamCrit_t &streamCrit); + +public: + //--- + //Public member vars - these are set at initialization and never change: + SeqNum_t _id; // monotonic sequence ID + unsigned _flags; + + +private: + + + // The unsigned return is hipMemcpyKind + unsigned resolveMemcpyDirection(bool srcInDeviceMem, bool dstInDeviceMem); + void resolveHcMemcpyDirection(unsigned hipMemKind, + const hc::AmPointerInfo *dstPtrInfo, const hc::AmPointerInfo *srcPtrInfo, + hc::hcCommandKind *hcCopyDir, + ihipCtx_t **copyDevice, + bool *forceUnpinnedCopy); + + bool canSeeMemory(const ihipCtx_t *thisCtx, const hc::AmPointerInfo *dstInfo, const hc::AmPointerInfo *srcInfo); + + void addSymbolPtrToTracker(hc::accelerator& acc, void* ptr, size_t sizeBytes); + +public: // TODO - move private + // Critical Data - MUST be accessed through LockedAccessor_StreamCrit_t + ihipStreamCritical_t _criticalData; + +private: // Data + + std::mutex _hasQueueLock; + + ihipCtx_t *_ctx; // parent context that owns this stream. + + // Friends: + friend std::ostream& operator<<(std::ostream& os, const ihipStream_t& s); + friend hipError_t hipStreamQuery(hipStream_t); + + ScheduleMode _scheduleMode; +}; + + + +//---- +// Internal event structure: +enum hipEventStatus_t { + hipEventStatusUnitialized = 0, // event is unutilized, must be "Created" before use. + hipEventStatusCreated = 1, + hipEventStatusRecording = 2, // event has been enqueued to record something. + hipEventStatusRecorded = 3, // event has been recorded - timestamps are valid. +} ; + + +// internal hip event structure. +struct ihipEvent_t { + hipEventStatus_t _state; + + hipStream_t _stream; // Stream where the event is recorded, or NULL if all streams. + unsigned _flags; + + hc::completion_future _marker; + uint64_t _timestamp; // store timestamp, may be set on host or by marker. +} ; + + + +//============================================================================= +//class ihipDeviceCriticalBase_t +template +class ihipDeviceCriticalBase_t : LockedBase +{ +public: + ihipDeviceCriticalBase_t(ihipDevice_t *parentDevice) : + _parent(parentDevice) + { + }; + + ~ihipDeviceCriticalBase_t() { + + } + + // Contexts: + void addContext(ihipCtx_t *ctx); + void removeContext(ihipCtx_t *ctx); + std::list &ctxs() { return _ctxs; }; + const std::list &const_ctxs() const { return _ctxs; }; + int getcount() {return _ctxCount;}; + friend class LockedAccessor; +private: + ihipDevice_t *_parent; + + //--- Context Tracker: + std::list< ihipCtx_t* > _ctxs; // contexts associated with this device across all threads. + + int _ctxCount; +}; + +typedef ihipDeviceCriticalBase_t ihipDeviceCritical_t; + +typedef LockedAccessor LockedAccessor_DeviceCrit_t; + +//---- +// Properties of the HIP device. +// Multiple contexts can point to same device. +class ihipDevice_t +{ +public: + ihipDevice_t(unsigned deviceId, unsigned deviceCnt, hc::accelerator &acc); + ~ihipDevice_t(); + + // Accessors: + ihipCtx_t *getPrimaryCtx() const { return _primaryCtx; }; + void locked_removeContext(ihipCtx_t *c); + void locked_reset(); + ihipDeviceCritical_t &criticalData() { return _criticalData; }; +public: + unsigned _deviceId; // device ID + + hc::accelerator _acc; + hsa_agent_t _hsaAgent; // hsa agent handle + + //! Number of compute units supported by the device: + unsigned _computeUnits; + hipDeviceProp_t _props; // saved device properties. + + // TODO - report this through device properties, base on HCC API call. + int _isLargeBar; + + ihipCtx_t *_primaryCtx; + + int _state; //1 if device is set otherwise 0 + +private: + hipError_t initProperties(hipDeviceProp_t* prop); +private: + ihipDeviceCritical_t _criticalData; +}; +//============================================================================= + + + +//============================================================================= +//class ihipCtxCriticalBase_t +template +class ihipCtxCriticalBase_t : LockedBase +{ +public: + ihipCtxCriticalBase_t(ihipCtx_t *parentCtx, unsigned deviceCnt) : + _parent(parentCtx), + _peerCnt(0) + { + _peerAgents = new hsa_agent_t[deviceCnt]; + }; + + ~ihipCtxCriticalBase_t() { + if (_peerAgents != nullptr) { + delete _peerAgents; + _peerAgents = nullptr; + } + _peerCnt = 0; + } + + // Streams: + void addStream(ihipStream_t *stream); + std::list &streams() { return _streams; }; + const std::list &const_streams() const { return _streams; }; + + + + // Peer Accessor classes: + bool isPeerWatcher(const ihipCtx_t *peer); // returns True if peer has access to memory physically located on this device. + bool addPeerWatcher(const ihipCtx_t *thisCtx, ihipCtx_t *peer); + bool removePeerWatcher(const ihipCtx_t *thisCtx, ihipCtx_t *peer); + void resetPeerWatchers(ihipCtx_t *thisDevice); + void printPeerWatchers(FILE *f) const; + + uint32_t peerCnt() const { return _peerCnt; }; + hsa_agent_t *peerAgents() const { return _peerAgents; }; + + + // TODO - move private + std::list _peers; // list of enabled peer devices. + + friend class LockedAccessor; +private: + ihipCtx_t * _parent; + + //--- Stream Tracker: + std::list< ihipStream_t* > _streams; // streams associated with this device. + + + //--- Peer Tracker: + // These reflect the currently Enabled set of peers for this GPU: + // Enabled peers have permissions to access the memory physically allocated on this device. + // Note the peers always contain the self agent for easy interfacing with HSA APIs. + uint32_t _peerCnt; // number of enabled peers + hsa_agent_t *_peerAgents; // efficient packed array of enabled agents (to use for allocations.) +private: + void recomputePeerAgents(); +}; +// Note Mutex type Real/Fake selected based on CtxMutex +typedef ihipCtxCriticalBase_t ihipCtxCritical_t; + +// This type is used by functions that need access to the critical device structures. +typedef LockedAccessor LockedAccessor_CtxCrit_t; +//============================================================================= + + +//============================================================================= +//class ihipCtx_t: +// A HIP CTX (context) points at one of the existing devices and contains the streams, +// peer-to-peer mappings, creation flags. Multiple contexts can point to the same +// device. +// +class ihipCtx_t +{ +public: // Functions: + ihipCtx_t(ihipDevice_t *device, unsigned deviceCnt, unsigned flags); // note: calls constructor for _criticalData + ~ihipCtx_t(); + + // Functions which read or write the critical data are named locked_. + // (might be better called "locking_" + // ihipCtx_t does not use recursive locks so the ihip implementation must avoid calling a locked_ function from within a locked_ function. + // External functions which call several locked_ functions will acquire and release the lock for each function. if this occurs in + // performance-sensitive code we may want to refactor by adding non-locked functions and creating a new locked_ member function to call them all. + void locked_removeStream(ihipStream_t *s); + void locked_reset(); + void locked_waitAllStreams(); + void locked_syncDefaultStream(bool waitOnSelf); + + // Will allocate a queue and assign it to the needyStream: + hc::accelerator_view stealActiveQueue(LockedAccessor_CtxCrit_t &ctxCrit, ihipStream_t *needyStream); + hc::accelerator_view createOrStealQueue(LockedAccessor_CtxCrit_t &ctxCrit); + + ihipCtxCritical_t &criticalData() { return _criticalData; }; + + const ihipDevice_t *getDevice() const { return _device; }; + int getDeviceNum() const { return _device->_deviceId; }; + + // TODO - review uses of getWriteableDevice(), can these be converted to getDevice() + ihipDevice_t *getWriteableDevice() const { return _device; }; + + std::string toString() const; + +public: // Data + // The NULL stream is used if no other stream is specified. + // Default stream has special synchronization properties with other streams. + ihipStream_t *_defaultStream; + + // Flags specified when the context is created: + unsigned _ctxFlags; + +private: + ihipDevice_t *_device; + + +private: // Critical data, protected with locked access: + // Members of _protected data MUST be accessed through the LockedAccessor. + // Search for LockedAccessor for examples; do not access _criticalData directly. + ihipCtxCritical_t _criticalData; + +}; + + + +//================================================================================================= +// Global variable definition: +extern std::once_flag hip_initialized; +extern unsigned g_deviceCnt; +extern hsa_agent_t g_cpu_agent ; // the CPU agent. + +//================================================================================================= +// Extern functions: +extern void ihipInit(); +extern const char *ihipErrorString(hipError_t); +extern ihipCtx_t *ihipGetTlsDefaultCtx(); +extern void ihipSetTlsDefaultCtx(ihipCtx_t *ctx); +extern hipError_t ihipSynchronize(void); +extern void ihipCtxStackUpdate(); +extern hipError_t ihipDeviceSetState(); + +extern ihipDevice_t *ihipGetDevice(int); +ihipCtx_t * ihipGetPrimaryCtx(unsigned deviceIndex); + +extern void ihipSetTs(hipEvent_t e); + + +hipStream_t ihipSyncAndResolveStream(hipStream_t); + +// Stream printf functions: +inline std::ostream& operator<<(std::ostream& os, const ihipStream_t& s) +{ + os << "stream:"; + os << s.getDevice()->_deviceId;; + os << '.'; + os << s._id; + return os; +} + +inline std::ostream & operator<<(std::ostream& os, const dim3& s) +{ + os << '{'; + os << s.x; + os << ','; + os << s.y; + os << ','; + os << s.z; + os << '}'; + return os; +} + +inline std::ostream & operator<<(std::ostream& os, const gl_dim3& s) +{ + os << '{'; + os << s.x; + os << ','; + os << s.y; + os << ','; + os << s.z; + os << '}'; + return os; +} + +// Stream printf functions: +inline std::ostream& operator<<(std::ostream& os, const hipEvent_t& e) +{ + os << "event:" << std::hex << static_cast (e); + return os; +} + +inline std::ostream& operator<<(std::ostream& os, const ihipCtx_t* c) +{ + os << "ctx:" << static_cast (c) + << ".dev:" << c->getDevice()->_deviceId; + return os; +} + + +// Helper functions that are used across src files: +namespace hip_internal { + hipError_t memcpyAsync (void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream); +}; + + +#endif diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 4684287076..805fc9efc0 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,7 @@ THE SOFTWARE. #include "hsa/hsa_ext_amd.h" #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" #include "hip/hcc_detail/hip_texture.h" #include @@ -261,11 +261,11 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) auto device = ctx->getWriteableDevice(); unsigned amFlags = HIP_COHERENT_HOST_ALLOC ? amHostCoherent : amHostPinned; - *ptr = hip_internal::allocAndSharePtr(HIP_COHERENT_HOST_ALLOC ? "finegrained_host":"pinned_host", + *ptr = hip_internal::allocAndSharePtr(HIP_COHERENT_HOST_ALLOC ? "finegrained_host":"pinned_host", sizeBytes, ctx, amFlags, flags); if(sizeBytes && (*ptr == NULL)){ hip_status = hipErrorMemoryAllocation; - } + } } } @@ -314,7 +314,7 @@ hipError_t hipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height if (sizeBytes && (*ptr == NULL)) { hip_status = hipErrorMemoryAllocation; - } + } } else { hip_status = hipErrorMemoryAllocation; } @@ -372,7 +372,7 @@ hipError_t hipMallocArray(hipArray** array, const hipChannelFormatDesc* desc, *ptr = hip_internal::allocAndSharePtr("device_array", allocSize, ctx, am_flags, 0); if (size && (*ptr == NULL)) { hip_status = hipErrorMemoryAllocation; - } + } } else { hip_status = hipErrorMemoryAllocation; diff --git a/projects/clr/hipamd/src/hip_module.cpp b/projects/clr/hipamd/src/hip_module.cpp index c4b6cb8e08..554e13387a 100644 --- a/projects/clr/hipamd/src/hip_module.cpp +++ b/projects/clr/hipamd/src/hip_module.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -27,15 +27,13 @@ THE SOFTWARE. #include #include #include -#include "AMDGPUPTNote.h" -#include "AMDGPURuntimeMetadata.h" #include "hsa/hsa.h" #include "hsa/hsa_ext_amd.h" #include "hsa/amd_hsa_kernel_code.h" #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" //TODO Use Pool APIs from HCC to get memory regions. @@ -365,16 +363,12 @@ hipError_t hipModuleGetFunction(hipFunction_t *hfunc, hipModule_t hmod, } -hipError_t hipModuleLaunchKernel(hipFunction_t f, - uint32_t gridDimX, uint32_t gridDimY, uint32_t gridDimZ, - uint32_t blockDimX, uint32_t blockDimY, uint32_t blockDimZ, - uint32_t sharedMemBytes, hipStream_t hStream, +hipError_t ihipModuleLaunchKernel(hipFunction_t f, + uint32_t globalWorkSizeX, uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ, + uint32_t localWorkSizeX, uint32_t localWorkSizeY, uint32_t localWorkSizeZ, + size_t sharedMemBytes, hipStream_t hStream, void **kernelParams, void **extra) { - HIP_INIT_API(f, gridDimX, gridDimY, gridDimZ, - blockDimX, blockDimY, blockDimZ, - sharedMemBytes, hStream, - kernelParams, extra); auto ctx = ihipGetTlsDefaultCtx(); hipError_t ret = hipSuccess; @@ -420,7 +414,7 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f, */ grid_launch_parm lp; lp.dynamic_group_mem_bytes = sharedMemBytes; // TODO - this should be part of preLaunchKernel. - hStream = ihipPreLaunchKernel(hStream, dim3(gridDimX, gridDimY, gridDimZ), dim3(blockDimX, blockDimY, blockDimZ), &lp, f->_name.c_str()); + hStream = ihipPreLaunchKernel(hStream, dim3(globalWorkSizeX, globalWorkSizeY, globalWorkSizeZ), dim3(localWorkSizeX, localWorkSizeY, localWorkSizeZ), &lp, f->_name.c_str()); hsa_kernel_dispatch_packet_t aql; @@ -430,12 +424,12 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f, //aql.completion_signal._handle = 0; //aql.kernarg_address = 0; - aql.workgroup_size_x = blockDimX; - aql.workgroup_size_y = blockDimY; - aql.workgroup_size_z = blockDimZ; - aql.grid_size_x = blockDimX * gridDimX; - aql.grid_size_y = blockDimY * gridDimY; - aql.grid_size_z = blockDimZ * gridDimZ; + aql.workgroup_size_x = localWorkSizeX; + aql.workgroup_size_y = localWorkSizeY; + aql.workgroup_size_z = localWorkSizeZ; + aql.grid_size_x = globalWorkSizeX; + aql.grid_size_y = globalWorkSizeY; + aql.grid_size_z = globalWorkSizeZ; aql.group_segment_size = f->_groupSegmentSize + sharedMemBytes; aql.private_segment_size = f->_privateSegmentSize; aql.kernel_object = f->_object; @@ -459,9 +453,40 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f, ihipPostLaunchKernel(f->_name.c_str(), hStream, lp); } - return ihipLogStatus(ret); + return ret; } +hipError_t hipModuleLaunchKernel(hipFunction_t f, + uint32_t gridDimX, uint32_t gridDimY, uint32_t gridDimZ, + uint32_t blockDimX, uint32_t blockDimY, uint32_t blockDimZ, + uint32_t sharedMemBytes, hipStream_t hStream, + void **kernelParams, void **extra) +{ + HIP_INIT_API(f, gridDimX, gridDimY, gridDimZ, + blockDimX, blockDimY, blockDimZ, + sharedMemBytes, hStream, + kernelParams, extra); + return ihipLogStatus(ihipModuleLaunchKernel(f, + blockDimX * gridDimX, blockDimY * gridDimY, gridDimZ * blockDimZ, + blockDimX, blockDimY, blockDimZ, + sharedMemBytes, hStream, kernelParams, extra)); +} + + +hipError_t hipHccModuleLaunchKernel(hipFunction_t f, + uint32_t globalWorkSizeX, uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ, + uint32_t localWorkSizeX, uint32_t localWorkSizeY, uint32_t localWorkSizeZ, + size_t sharedMemBytes, hipStream_t hStream, + void **kernelParams, void **extra) +{ + HIP_INIT_API(f, globalWorkSizeX, globalWorkSizeY, globalWorkSizeZ, + localWorkSizeX, localWorkSizeY, localWorkSizeZ, + sharedMemBytes, hStream, + kernelParams, extra); + return ihipLogStatus(ihipModuleLaunchKernel(f, globalWorkSizeX, globalWorkSizeY, globalWorkSizeZ, + localWorkSizeX, localWorkSizeY, localWorkSizeZ, + sharedMemBytes, hStream, kernelParams, extra)); +} hipError_t hipModuleGetGlobal(hipDeviceptr_t *dptr, size_t *bytes, hipModule_t hmod, const char* name) diff --git a/projects/clr/hipamd/src/hip_peer.cpp b/projects/clr/hipamd/src/hip_peer.cpp index e57665be0c..984110a6b5 100644 --- a/projects/clr/hipamd/src/hip_peer.cpp +++ b/projects/clr/hipamd/src/hip_peer.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,7 @@ THE SOFTWARE. #include #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" diff --git a/projects/clr/hipamd/src/hip_stream.cpp b/projects/clr/hipamd/src/hip_stream.cpp index 594fb6e860..d7f8717725 100644 --- a/projects/clr/hipamd/src/hip_stream.cpp +++ b/projects/clr/hipamd/src/hip_stream.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ THE SOFTWARE. */ #include "hip/hip_runtime.h" -#include "hip_hcc.h" +#include "hip_hcc_internal.h" #include "trace_helper.h" From e54234667ca80c2c5942373bc57086a99b7ea44e Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Fri, 31 Mar 2017 12:18:55 -0500 Subject: [PATCH 42/56] fixed header names Change-Id: I21650d6398187d3767b28e8ac81b2642d3b89a0e [ROCm/clr commit: 614e7db5139be717246313be80d6dd5ee04b039c] --- .../include/hip/hcc_detail/device_functions.h | 9 ++- .../include/hip/hcc_detail/driver_types.h | 9 ++- .../hipamd/include/hip/hcc_detail/hcc_acc.h | 59 ------------------- .../hipamd/include/hip/hcc_detail/helpers.hpp | 2 +- .../include/hip/hcc_detail/hip_complex.h | 6 +- .../hipamd/include/hip/hcc_detail/hip_fp16.h | 6 +- .../hipamd/include/hip/hcc_detail/hip_ldg.h | 6 +- .../include/hip/hcc_detail/hip_runtime.h | 6 +- .../include/hip/hcc_detail/hip_runtime_api.h | 8 +-- .../include/hip/hcc_detail/hip_texture.h | 6 +- .../include/hip/hcc_detail/hip_vector_types.h | 6 +- .../include/hip/hcc_detail/host_defines.h | 8 +-- .../include/hip/hcc_detail/math_functions.h | 9 ++- .../include/hip/hcc_detail/texture_types.h | 9 ++- 14 files changed, 51 insertions(+), 98 deletions(-) delete mode 100644 projects/clr/hipamd/include/hip/hcc_detail/hcc_acc.h diff --git a/projects/clr/hipamd/include/hip/hcc_detail/device_functions.h b/projects/clr/hipamd/include/hip/hcc_detail/device_functions.h index 212f22d5dc..8073503364 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/device_functions.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/device_functions.h @@ -1,13 +1,16 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -17,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_HCC_DETAIL_DEVICE_FUNCTIONS_H -#define HIP_HCC_DETAIL_DEVICE_FUNCTIONS_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_DEVICE_FUNCTIONS_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_DEVICE_FUNCTIONS_H #include #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/driver_types.h b/projects/clr/hipamd/include/hip/hcc_detail/driver_types.h index 1fe72b0507..3578ddc609 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/driver_types.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/driver_types.h @@ -1,13 +1,16 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -17,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_HCC_DETAIL_DRIVER_TYPES_H -#define HIP_HCC_DETAIL_DRIVER_TYPES_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_DRIVER_TYPES_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_DRIVER_TYPES_H enum hipChannelFormatKind { diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hcc_acc.h b/projects/clr/hipamd/include/hip/hcc_detail/hcc_acc.h deleted file mode 100644 index 962f795d6f..0000000000 --- a/projects/clr/hipamd/include/hip/hcc_detail/hcc_acc.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef HCC_ACC_H -#define HCC_ACC_H -#include "hip/hip_runtime_api.h" - -#if __cplusplus -#ifdef __HCC__ -#include -/** - * @brief Return hc::accelerator associated with the specified deviceId - * @return #hipSuccess, #hipErrorInvalidDevice - */ -hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc); - -/** - * @brief Return hc::accelerator_view associated with the specified stream - * - * If stream is 0, the accelerator_view for the default stream is returned. - * @return #hipSuccess - */ -hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view **av); - - -hipError_t hipHccModuleLaunchKernel(hipFunction_t f, - uint32_t globalWorkSizeX, - uint32_t globalWorkSizeY, - uint32_t globalWorkSizeZ, - uint32_t localWorkSizeX, - uint32_t localWorkSizeY, - uint32_t localWorkSizeZ, - size_t sharedMemBytes, - hipStream_t hStream, - void **kernelParams, - void **extra); -#endif -#endif - -#endif diff --git a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp index f12087faa9..5ab866dc66 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_complex.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_complex.h index f50a601b90..9ff75d381a 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_complex.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_complex.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef INCLUDE_HIP_HCC_DETAIL_HIP_COMPLEX_H -#define INCLUDE_HIP_HCC_DETAIL_HIP_COMPLEX_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_COMPLEX_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_COMPLEX_H #include "./hip_fp16.h" #include "./hip_vector_types.h" diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_fp16.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_fp16.h index b0276d51b3..a3766fb053 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_fp16.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_fp16.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_HCC_DETAIL_FP16_H -#define HIP_HCC_DETAIL_FP16_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_FP16_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_FP16_H #include "hip/hip_runtime.h" diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h index 5c33ee773f..473e70b4cb 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_ldg.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_LDG_H -#define HIP_LDG_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_LDG_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_LDG_H #if defined __HCC__ #if __hcc_workweek__ >= 16164 diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 42d80ecb0e..9692b16a4c 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,8 +26,8 @@ THE SOFTWARE. */ //#pragma once -#ifndef HIP_HCC_DETAIL_RUNTIME_H -#define HIP_HCC_DETAIL_RUNTIME_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_RUNTIME_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_RUNTIME_H //--- // Top part of file can be compiled with any compiler diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index 87e552a6cf..0daca7a53b 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,8 +21,8 @@ THE SOFTWARE. */ //#pragma once -#ifndef HIP_HCC_DETAIL_HIP_RUNTIME_API_H -#define HIP_HCC_DETAIL_HIP_RUNTIME_API_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_RUNTIME_API_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_RUNTIME_API_H /** * @file hcc_detail/hip_runtime_api.h * @brief Contains C function APIs for HIP runtime. This file does not use any HCC builtin or special language extensions (-hc mode) ; those functions in hip_runtime.h. @@ -32,7 +32,7 @@ THE SOFTWARE. #include #ifndef GENERIC_GRID_LAUNCH -#define GENERIC_GRID_LAUNCH 1 +#define GENERIC_GRID_LAUNCH 1 #endif #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_texture.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_texture.h index d60f66ddc2..c6f5a1cfb2 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_texture.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_texture.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,8 +22,8 @@ THE SOFTWARE. //#pragma once -#ifndef HIP_HCC_DETAIL_TEXTURE_H -#define HIP_HCC_DETAIL_TEXTURE_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_TEXTURE_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_TEXTURE_H /** * @file hcc_detail/hip_texture.h diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_vector_types.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_vector_types.h index 8e6ec49511..42e1d6663c 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_vector_types.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_vector_types.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,8 +25,8 @@ THE SOFTWARE. * @brief Defines the different newt vector types for HIP runtime. */ -#ifndef HIP_VECTOR_TYPES_H -#define HIP_VECTOR_TYPES_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_VECTOR_TYPES_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_VECTOR_TYPES_H #if defined (__HCC__) && (__hcc_workweek__ < 16032) #error("This version of HIP requires a newer version of HCC."); diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index d077873797..4f44774700 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,14 +25,14 @@ THE SOFTWARE. * @brief TODO-doc */ -#ifndef HOST_DEFINES_H -#define HOST_DEFINES_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HOST_DEFINES_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_HOST_DEFINES_H #define USE_PROMOTE_FREE_HCC 0 // Add guard to Generic Grid Launch method #ifndef GENERIC_GRID_LAUNCH -#define GENERIC_GRID_LAUNCH 1 +#define GENERIC_GRID_LAUNCH 1 #endif #ifdef __HCC__ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/math_functions.h b/projects/clr/hipamd/include/hip/hcc_detail/math_functions.h index 8455509732..c3b8186fd3 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/math_functions.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/math_functions.h @@ -1,13 +1,16 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -17,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_HCC_DETAIL_MATH_FUNCTIONS_H -#define HIP_HCC_DETAIL_MATH_FUNCTIONS_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_MATH_FUNCTIONS_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_MATH_FUNCTIONS_H #include #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/texture_types.h b/projects/clr/hipamd/include/hip/hcc_detail/texture_types.h index 107b5d26c1..74680bbc76 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/texture_types.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/texture_types.h @@ -1,13 +1,16 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -18,8 +21,8 @@ THE SOFTWARE. */ -#ifndef HIP_HCC_DETAIL_TEXTURE_TYPES_H -#define HIP_HCC_DETAIL_TEXTURE_TYPES_H +#ifndef HIP_INCLUDE_HIP_HCC_DETAIL_TEXTURE_TYPES_H +#define HIP_INCLUDE_HIP_HCC_DETAIL_TEXTURE_TYPES_H #include From e3d3cacebcab101b809df075f171652b03b82425 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Fri, 31 Mar 2017 12:40:29 -0500 Subject: [PATCH 43/56] Fixed copyright and header names Change-Id: Id595c65ea3b7289e87be4c42db5d8a31905a4fdd [ROCm/clr commit: 3859f591895ec16e7baec6c878723765e0a33341] --- .../include/hip/hcc_detail/grid_launch_v2.hpp | 4 +- .../hipamd/include/hip/hcc_detail/hip_fp16.h | 3 - .../clr/hipamd/include/hip/hip_runtime_api.h | 2 + .../hip/nvcc_detail/channel_descriptor.h | 7 +- .../include/hip/nvcc_detail/hip_complex.h | 6 +- .../include/hip/nvcc_detail/hip_runtime.h | 7 +- .../include/hip/nvcc_detail/hip_runtime_api.h | 5 +- .../include/hip/nvcc_detail/hip_texture.h | 26 +- projects/clr/hipamd/src/hip_fp16.cpp | 4 +- projects/clr/hipamd/src/hip_hcc.h | 885 ------------------ projects/clr/hipamd/src/hip_hcc_internal.h | 6 +- projects/clr/hipamd/src/hip_ldg.cpp | 2 +- projects/clr/hipamd/src/hip_util.h | 6 +- projects/clr/hipamd/tests/src/hipHcc.cpp | 3 +- 14 files changed, 54 insertions(+), 912 deletions(-) delete mode 100644 projects/clr/hipamd/src/hip_hcc.h diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp index b360d4c19d..8b1eded2f3 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ THE SOFTWARE. #include "helpers.hpp" #include "hc.hpp" -#include "hcc_acc.h" +#include "hip_hcc.h" #include #include diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_fp16.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_fp16.h index a3766fb053..febc1b4fce 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_fp16.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_fp16.h @@ -464,9 +464,6 @@ __device__ static inline __half2 h2trunc(const __half2 h) { return a; } - - - #endif #if __clang_major__ == 3 diff --git a/projects/clr/hipamd/include/hip/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hip_runtime_api.h index 5715be0599..8eae1d6a3a 100644 --- a/projects/clr/hipamd/include/hip/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hip_runtime_api.h @@ -284,3 +284,5 @@ static inline hipError_t hipHostMalloc( T** ptr, size_t size, unsigned int flags return hipHostMalloc((void**)ptr, size, flags); } #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/channel_descriptor.h b/projects/clr/hipamd/include/hip/nvcc_detail/channel_descriptor.h index 8502745968..2e88c56268 100644 --- a/projects/clr/hipamd/include/hip/nvcc_detail/channel_descriptor.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/channel_descriptor.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,6 +20,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_NVCC_DETAIL_CHANNEL_DESCRIPTOR_H +#define HIP_INCLUDE_HIP_NVCC_DETAIL_CHANNEL_DESCRIPTOR_H #include"channel_descriptor.h" + +#endif diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/hip_complex.h b/projects/clr/hipamd/include/hip/nvcc_detail/hip_complex.h index 174cabc12c..84afb13e50 100644 --- a/projects/clr/hipamd/include/hip/nvcc_detail/hip_complex.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/hip_complex.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIPCOMPLEX_H -#define HIPCOMPLEX_H +#ifndef HIP_INCLUDE_HIP_NVCC_DETAIL_HIP_COMPLEX_H +#define HIP_INCLUDE_HIP_NVCC_DETAIL_HIP_COMPLEX_H #include"cuComplex.h" diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime.h index 2c774bfb7d..b4fa13f48c 100644 --- a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_NVCC_DETAIL_HIP_RUNTIME_H +#define HIP_INCLUDE_HIP_NVCC_DETAIL_HIP_RUNTIME_H #include @@ -105,3 +106,5 @@ kernelName<<>>(0, ##__VA_ARGS__);\ #define HIP_DYNAMIC_SHARED_ATTRIBUTE #endif + +#endif diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h index 758ef064bd..7e881df3ab 100644 --- a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#pragma once +#ifndef HIP_INCLUDE_HIP_NVCC_DETAIL_HIP_RUNTIME_API_H +#define HIP_INCLUDE_HIP_NVCC_DETAIL_HIP_RUNTIME_API_H #include #include diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/hip_texture.h b/projects/clr/hipamd/include/hip/nvcc_detail/hip_texture.h index 388733e492..c669d62192 100644 --- a/projects/clr/hipamd/include/hip/nvcc_detail/hip_texture.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/hip_texture.h @@ -1,5 +1,27 @@ -#ifndef HIP_TEXTURE_H -#define HIP_TEXTURE_H +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef HIP_INCLUDE_HIP_NVCC_DETAIL_HIP_TEXTURE_H +#define HIP_INCLUDE_HIP_NVCC_DETAIL_HIP_TEXTURE_H #include diff --git a/projects/clr/hipamd/src/hip_fp16.cpp b/projects/clr/hipamd/src/hip_fp16.cpp index e7f75844ff..c2b7b47597 100644 --- a/projects/clr/hipamd/src/hip_fp16.cpp +++ b/projects/clr/hipamd/src/hip_fp16.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include"hip/hip_fp16.h" +#include"hip/hcc_detail/hip_fp16.h" struct hipHalfHolder{ union { diff --git a/projects/clr/hipamd/src/hip_hcc.h b/projects/clr/hipamd/src/hip_hcc.h deleted file mode 100644 index 245f154305..0000000000 --- a/projects/clr/hipamd/src/hip_hcc.h +++ /dev/null @@ -1,885 +0,0 @@ -/* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef HIP_HCC_H -#define HIP_HCC_H - -#include -#include -#include "hsa/hsa_ext_amd.h" - -#include "hip/hip_runtime.h" -#include "hip_util.h" -#include "env.h" - - -#if defined(__HCC__) && (__hcc_workweek__ < 16354) -#error("This version of HIP requires a newer version of HCC."); -#endif - -#define USE_IPC 1 - -//--- -// Environment variables: - -// Intended to distinguish whether an environment variable should be visible only in debug mode, or in debug+release. -//static const int debug = 0; -extern const int release; - -// TODO - this blocks both kernels and memory ops. Perhaps should have separate env var for kernels? -extern int HIP_LAUNCH_BLOCKING; -extern int HIP_API_BLOCKING; - -extern int HIP_PRINT_ENV; -extern int HIP_PROFILE_API; -//extern int HIP_TRACE_API; -extern int HIP_ATP; -extern int HIP_DB; -extern int HIP_STAGING_SIZE; /* size of staging buffers, in KB */ -extern int HIP_STREAM_SIGNALS; /* number of signals to allocate at stream creation */ -extern int HIP_VISIBLE_DEVICES; /* Contains a comma-separated sequence of GPU identifiers */ -extern int HIP_FORCE_P2P_HOST; - -extern int HIP_COHERENT_HOST_ALLOC; - - -//--- -// Chicken bits for disabling functionality to work around potential issues: -extern int HIP_SYNC_HOST_ALLOC; - -// TODO - remove when this is standard behavior. -extern int HCC_OPT_FLUSH; - - -// Class to assign a short TID to each new thread, for HIP debugging purposes. -class TidInfo { -public: - - TidInfo() ; - - int tid() const { return _shortTid; }; - uint64_t incApiSeqNum() { return ++_apiSeqNum; }; - uint64_t apiSeqNum() const { return _apiSeqNum; }; - -private: - int _shortTid; - - // monotonically increasing API sequence number for this threa. - uint64_t _apiSeqNum; -}; - -struct ProfTrigger { - - static const uint64_t MAX_TRIGGER = std::numeric_limits::max(); - - void print (int tid) { - std::cout << "Enabling tracing for "; - for (auto iter=_profTrigger.begin(); iter != _profTrigger.end(); iter++) { - std::cout << "tid:" << tid << "." << *iter << ","; - } - std::cout << "\n"; - }; - - uint64_t nextTrigger() { return _profTrigger.empty() ? MAX_TRIGGER : _profTrigger.back(); }; - void add(uint64_t trigger) { _profTrigger.push_back(trigger); }; - void sort() { std::sort (_profTrigger.begin(), _profTrigger.end(), std::greater()); }; -private: - std::vector _profTrigger; -}; - - - -//--- -//Extern tls -extern thread_local hipError_t tls_lastHipError; -extern thread_local TidInfo tls_tidInfo; - -extern std::vector g_dbStartTriggers; -extern std::vector g_dbStopTriggers; - -//--- -//Forward defs: -class ihipStream_t; -class ihipDevice_t; -class ihipCtx_t; - -// Color defs for debug messages: -#define KNRM "\x1B[0m" -#define KRED "\x1B[31m" -#define KGRN "\x1B[32m" -#define KYEL "\x1B[33m" -#define KBLU "\x1B[34m" -#define KMAG "\x1B[35m" -#define KCYN "\x1B[36m" -#define KWHT "\x1B[37m" - -extern const char *API_COLOR; -extern const char *API_COLOR_END; - - -// If set, thread-safety is enforced on all stream functions. -// Stream functions will acquire a mutex before entering critical sections. -#define STREAM_THREAD_SAFE 1 - - -#define CTX_THREAD_SAFE 1 - -#define DEVICE_THREAD_SAFE 1 - - -// Compile debug trace mode - this prints debug messages to stderr when env var HIP_DB is set. -// May be set to 0 to remove debug if checks - possible code size and performance difference? -#define COMPILE_HIP_DB 1 - - -// Compile HIP tracing capability. -// 0x1 = print a string at function entry with arguments. -// 0x2 = prints a simple message with function name + return code when function exits. -// 0x3 = print both. -// Must be enabled at runtime with HIP_TRACE_API -#define COMPILE_HIP_TRACE_API 0x3 - - -// Compile code that generates trace markers for CodeXL ATP at HIP function begin/end. -// ATP is standard CodeXL format that includes timestamps for kernels, HSA RT APIs, and HIP APIs. -#ifndef COMPILE_HIP_ATP_MARKER -#define COMPILE_HIP_ATP_MARKER 0 -#endif - - - - -// Compile support for trace markers that are displayed on CodeXL GUI at start/stop of each function boundary. -// TODO - currently we print the trace message at the beginning. if we waited, we could also tls_tidInfo return codes, and any values returned -// through ptr-to-args (ie the pointers allocated by hipMalloc). -#if COMPILE_HIP_ATP_MARKER -#include "CXLActivityLogger.h" -#define MARKER_BEGIN(markerName,group) amdtBeginMarker(markerName, group, nullptr); -#define MARKER_END() amdtEndMarker(); -#define RESUME_PROFILING amdtResumeProfiling(AMDT_ALL_PROFILING); -#define STOP_PROFILING amdtStopProfiling(AMDT_ALL_PROFILING); -#else -// Swallow scoped markers: -#define MARKER_BEGIN(markerName,group) -#define MARKER_END() -#define RESUME_PROFILING -#define STOP_PROFILING -#endif - - -//--- -//HIP Trace modes -#define TRACE_ALL 0 // 0x1 -#define TRACE_CMD 1 // 0x2 -#define TRACE_MEM 2 // 0x4 - - -//--- -//HIP_DB Debug flags: -#define DB_API 0 /* 0x01 - shortcut to enable HIP_TRACE_API on single switch */ -#define DB_SYNC 1 /* 0x02 - trace synchronization pieces */ -#define DB_MEM 2 /* 0x04 - trace memory allocation / deallocation */ -#define DB_COPY 3 /* 0x08 - trace memory copy and peer commands. . */ -#define DB_MAX_FLAG 4 -// When adding a new debug flag, also add to the char name table below. -// -// - -struct DbName { - const char *_color; - const char *_shortName; -}; - -// This table must be kept in-sync with the defines above. -static const DbName dbName [] = -{ - {KGRN, "api"}, // not used, - {KYEL, "sync"}, - {KCYN, "mem"}, - {KMAG, "copy"}, -}; - - - -#if COMPILE_HIP_DB -#define tprintf(trace_level, ...) {\ - if (HIP_DB & (1<<(trace_level))) {\ - char msgStr[1000];\ - snprintf(msgStr, 2000, __VA_ARGS__);\ - fprintf (stderr, " %ship-%s tid:%d:%s%s", dbName[trace_level]._color, dbName[trace_level]._shortName, tls_tidInfo.tid(), msgStr, KNRM); \ - }\ -} -#else -/* Compile to empty code */ -#define tprintf(trace_level, ...) -#endif - - - - -//--- -extern void recordApiTrace(std::string *fullStr, const std::string &apiStr); - -#if COMPILE_HIP_ATP_MARKER || (COMPILE_HIP_TRACE_API & 0x1) -#define API_TRACE(forceTrace, ...)\ -{\ - tls_tidInfo.incApiSeqNum();\ - if (forceTrace || (HIP_PROFILE_API || (COMPILE_HIP_DB && (HIP_TRACE_API & (1<>%s\n", (localHipStatus == 0) ? API_COLOR:KRED, tls_tidInfo.tid(),tls_tidInfo.apiSeqNum(), __func__, localHipStatus, ihipErrorString(localHipStatus), API_COLOR_END);\ - }\ - if (HIP_PROFILE_API) { MARKER_END(); }\ - localHipStatus;\ - }) - - - - - - -class ihipException : public std::exception -{ -public: - ihipException(hipError_t e) : _code(e) {}; - - hipError_t _code; -}; - - -#ifdef __cplusplus -extern "C" { -#endif - - -#ifdef __cplusplus -} -#endif - -const hipStream_t hipStreamNull = 0x0; - - -/** - * HIP IPC Handle Size - */ -#define HIP_IPC_RESERVED_SIZE 24 -class ihipIpcMemHandle_t -{ -public: -#if USE_IPC - hsa_amd_ipc_memory_t ipc_handle; ///< ipc memory handle on ROCr -#endif - size_t psize; - char reserved[HIP_IPC_RESERVED_SIZE]; -}; - - -class ihipModule_t { -public: - hsa_executable_t executable; - hsa_code_object_t object; - std::string fileName; - void *ptr; - size_t size; - std::list funcTrack; - ihipModule_t() : executable(), object(), fileName(), ptr(nullptr), size(0) {} -}; - - -//--- -// Used to remove lock, for performance or stimulating bugs. -class FakeMutex -{ - public: - void lock() { } - bool try_lock() {return true; } - void unlock() { } -}; - - -#if STREAM_THREAD_SAFE -typedef std::mutex StreamMutex; -#else -#warning "Stream thread-safe disabled" -typedef FakeMutex StreamMutex; -#endif - -// Pair Device and Ctx together, these could also be toggled separately if desired. -#if CTX_THREAD_SAFE -typedef std::mutex CtxMutex; -#else -typedef FakeMutex CtxMutex; -#warning "Ctx thread-safe disabled" -#endif - -#if DEVICE_THREAD_SAFE -typedef std::mutex DeviceMutex; -#else -typedef FakeMutex DeviceMutex; -#warning "Device thread-safe disabled" -#endif - -// -//--- -// Protects access to the member _data with a lock acquired on contruction/destruction. -// T must contain a _mutex field which meets the BasicLockable requirements (lock/unlock) -template -class LockedAccessor -{ -public: - LockedAccessor(T &criticalData, bool autoUnlock=true) : - _criticalData(&criticalData), - _autoUnlock(autoUnlock) - - { - tprintf(DB_SYNC, "locking criticalData=%p for %s..\n", _criticalData, ToString(_criticalData->_parent).c_str()); - _criticalData->_mutex.lock(); - }; - - ~LockedAccessor() - { - if (_autoUnlock) { - tprintf(DB_SYNC, "auto-unlocking criticalData=%p for %s...\n", _criticalData, ToString(_criticalData->_parent).c_str()); - _criticalData->_mutex.unlock(); - } - } - - void unlock() - { - tprintf(DB_SYNC, "unlocking criticalData=%p for %s...\n", _criticalData, ToString(_criticalData->_parent).c_str()); - _criticalData->_mutex.unlock(); - } - - // Syntactic sugar so -> can be used to get the underlying type. - T *operator->() { return _criticalData; }; - -private: - T *_criticalData; - bool _autoUnlock; -}; - - -template -struct LockedBase { - - // Experts-only interface for explicit locking. - // Most uses should use the lock-accessor. - void lock() { _mutex.lock(); } - void unlock() { _mutex.unlock(); } - bool try_lock() { return _mutex.try_lock(); } - - MUTEX_TYPE _mutex; -}; - - -template -class ihipStreamCriticalBase_t : public LockedBase -{ -public: - ihipStreamCriticalBase_t(ihipStream_t *parentStream, hc::accelerator_view av) : - _kernelCnt(0), - _av(av), - _hasQueue(true), - _parent(parentStream) - { - }; - - ~ihipStreamCriticalBase_t() { - } - - ihipStreamCriticalBase_t * mlock() { LockedBase::lock(); return this;}; - - void munlock() { - tprintf(DB_SYNC, "munlocking criticalData=%p for %s...\n", this, ToString(this->_parent).c_str()); - LockedBase::unlock(); - }; - - ihipStreamCriticalBase_t * mtry_lock() { - bool gotLock = LockedBase::try_lock() ; - tprintf(DB_SYNC, "mtry_locking=%d criticalData=%p for %s...\n", gotLock, this, ToString(this->_parent).c_str()); - return gotLock ? this: nullptr; - }; - -public: - ihipStream_t * _parent; - uint32_t _kernelCnt; // Count of inflight kernels in this stream. Reset at ::wait(). - - hc::accelerator_view _av; - - // True if the stream has an allocated queue (accelerato_view) for its use: - // Always true at ihipStream creation but queue may later be stolen. - // This acts as a valid bit for the _av. - bool _hasQueue; -private: -}; - - -// if HIP code needs to acquire locks for both ihipCtx_t and ihipStream_t, it should first acquire the lock -// for the ihipCtx_t and then for the individual streams. The locks should not be acquired in reverse order -// or deadlock may occur. In some cases, it may be possible to reduce the range where the locks must be held. -// HIP routines should avoid acquiring and releasing the same lock during the execution of a single HIP API. -// Another option is to use try_lock in the innermost lock query. - - -typedef ihipStreamCriticalBase_t ihipStreamCritical_t; -typedef LockedAccessor LockedAccessor_StreamCrit_t; - -//--- -// Internal stream structure. -class ihipStream_t { -public: - enum ScheduleMode {Auto, Spin, Yield}; - typedef uint64_t SeqNum_t ; - - // TODOD -make av a reference to avoid shared_ptr overhead? - ihipStream_t(ihipCtx_t *ctx, hc::accelerator_view av, unsigned int flags); - ~ihipStream_t(); - - // kind is hipMemcpyKind - void locked_copySync (void* dst, const void* src, size_t sizeBytes, unsigned kind, bool resolveOn = true); - void locked_copyAsync(void* dst, const void* src, size_t sizeBytes, unsigned kind); - - void lockedSymbolCopySync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, size_t offset, unsigned kind); - void lockedSymbolCopyAsync(hc::accelerator &acc, void *dst, void* src, size_t sizeBytes, size_t offset, unsigned kind); - - //--- - // Member functions that begin with locked_ are thread-safe accessors - these acquire / release the critical mutex. - LockedAccessor_StreamCrit_t lockopen_preKernelCommand(); - void lockclose_postKernelCommand(const char *kernelName, hc::accelerator_view *av); - - - void locked_wait(); - - hc::accelerator_view* locked_getAv() { LockedAccessor_StreamCrit_t crit(_criticalData); return &(crit->_av); }; - - void locked_waitEvent(hipEvent_t event); - void locked_recordEvent(hipEvent_t event); - - - //--- - - // Use this if we already have the stream critical data mutex: - void wait(LockedAccessor_StreamCrit_t &crit); - - void launchModuleKernel(hc::accelerator_view av, hsa_signal_t signal, - uint32_t blockDimX, uint32_t blockDimY, uint32_t blockDimZ, - uint32_t gridDimX, uint32_t gridDimY, uint32_t gridDimZ, - uint32_t groupSegmentSize, uint32_t sharedMemBytes, - void *kernarg, size_t kernSize, uint64_t kernel); - - - - //-- Non-racy accessors: - // These functions access fields set at initialization time and are non-racy (so do not acquire mutex) - const ihipDevice_t * getDevice() const; - ihipCtx_t * getCtx() const; - - void ensureHaveQueue(LockedAccessor_StreamCrit_t &streamCrit); - -public: - //--- - //Public member vars - these are set at initialization and never change: - SeqNum_t _id; // monotonic sequence ID - unsigned _flags; - - -private: - - - // The unsigned return is hipMemcpyKind - unsigned resolveMemcpyDirection(bool srcInDeviceMem, bool dstInDeviceMem); - void resolveHcMemcpyDirection(unsigned hipMemKind, - const hc::AmPointerInfo *dstPtrInfo, const hc::AmPointerInfo *srcPtrInfo, - hc::hcCommandKind *hcCopyDir, - ihipCtx_t **copyDevice, - bool *forceUnpinnedCopy); - - bool canSeeMemory(const ihipCtx_t *thisCtx, const hc::AmPointerInfo *dstInfo, const hc::AmPointerInfo *srcInfo); - - void addSymbolPtrToTracker(hc::accelerator& acc, void* ptr, size_t sizeBytes); - -public: // TODO - move private - // Critical Data - MUST be accessed through LockedAccessor_StreamCrit_t - ihipStreamCritical_t _criticalData; - -private: // Data - - std::mutex _hasQueueLock; - - ihipCtx_t *_ctx; // parent context that owns this stream. - - // Friends: - friend std::ostream& operator<<(std::ostream& os, const ihipStream_t& s); - friend hipError_t hipStreamQuery(hipStream_t); - - ScheduleMode _scheduleMode; -}; - - - -//---- -// Internal event structure: -enum hipEventStatus_t { - hipEventStatusUnitialized = 0, // event is unutilized, must be "Created" before use. - hipEventStatusCreated = 1, - hipEventStatusRecording = 2, // event has been enqueued to record something. - hipEventStatusRecorded = 3, // event has been recorded - timestamps are valid. -} ; - - -// internal hip event structure. -struct ihipEvent_t { - hipEventStatus_t _state; - - hipStream_t _stream; // Stream where the event is recorded, or NULL if all streams. - unsigned _flags; - - hc::completion_future _marker; - uint64_t _timestamp; // store timestamp, may be set on host or by marker. -} ; - - - -//============================================================================= -//class ihipDeviceCriticalBase_t -template -class ihipDeviceCriticalBase_t : LockedBase -{ -public: - ihipDeviceCriticalBase_t(ihipDevice_t *parentDevice) : - _parent(parentDevice) - { - }; - - ~ihipDeviceCriticalBase_t() { - - } - - // Contexts: - void addContext(ihipCtx_t *ctx); - void removeContext(ihipCtx_t *ctx); - std::list &ctxs() { return _ctxs; }; - const std::list &const_ctxs() const { return _ctxs; }; - int getcount() {return _ctxCount;}; - friend class LockedAccessor; -private: - ihipDevice_t *_parent; - - //--- Context Tracker: - std::list< ihipCtx_t* > _ctxs; // contexts associated with this device across all threads. - - int _ctxCount; -}; - -typedef ihipDeviceCriticalBase_t ihipDeviceCritical_t; - -typedef LockedAccessor LockedAccessor_DeviceCrit_t; - -//---- -// Properties of the HIP device. -// Multiple contexts can point to same device. -class ihipDevice_t -{ -public: - ihipDevice_t(unsigned deviceId, unsigned deviceCnt, hc::accelerator &acc); - ~ihipDevice_t(); - - // Accessors: - ihipCtx_t *getPrimaryCtx() const { return _primaryCtx; }; - void locked_removeContext(ihipCtx_t *c); - void locked_reset(); - ihipDeviceCritical_t &criticalData() { return _criticalData; }; -public: - unsigned _deviceId; // device ID - - hc::accelerator _acc; - hsa_agent_t _hsaAgent; // hsa agent handle - - //! Number of compute units supported by the device: - unsigned _computeUnits; - hipDeviceProp_t _props; // saved device properties. - - // TODO - report this through device properties, base on HCC API call. - int _isLargeBar; - - ihipCtx_t *_primaryCtx; - - int _state; //1 if device is set otherwise 0 - -private: - hipError_t initProperties(hipDeviceProp_t* prop); -private: - ihipDeviceCritical_t _criticalData; -}; -//============================================================================= - - - -//============================================================================= -//class ihipCtxCriticalBase_t -template -class ihipCtxCriticalBase_t : LockedBase -{ -public: - ihipCtxCriticalBase_t(ihipCtx_t *parentCtx, unsigned deviceCnt) : - _parent(parentCtx), - _peerCnt(0) - { - _peerAgents = new hsa_agent_t[deviceCnt]; - }; - - ~ihipCtxCriticalBase_t() { - if (_peerAgents != nullptr) { - delete _peerAgents; - _peerAgents = nullptr; - } - _peerCnt = 0; - } - - // Streams: - void addStream(ihipStream_t *stream); - std::list &streams() { return _streams; }; - const std::list &const_streams() const { return _streams; }; - - - - // Peer Accessor classes: - bool isPeerWatcher(const ihipCtx_t *peer); // returns True if peer has access to memory physically located on this device. - bool addPeerWatcher(const ihipCtx_t *thisCtx, ihipCtx_t *peer); - bool removePeerWatcher(const ihipCtx_t *thisCtx, ihipCtx_t *peer); - void resetPeerWatchers(ihipCtx_t *thisDevice); - void printPeerWatchers(FILE *f) const; - - uint32_t peerCnt() const { return _peerCnt; }; - hsa_agent_t *peerAgents() const { return _peerAgents; }; - - - // TODO - move private - std::list _peers; // list of enabled peer devices. - - friend class LockedAccessor; -private: - ihipCtx_t * _parent; - - //--- Stream Tracker: - std::list< ihipStream_t* > _streams; // streams associated with this device. - - - //--- Peer Tracker: - // These reflect the currently Enabled set of peers for this GPU: - // Enabled peers have permissions to access the memory physically allocated on this device. - // Note the peers always contain the self agent for easy interfacing with HSA APIs. - uint32_t _peerCnt; // number of enabled peers - hsa_agent_t *_peerAgents; // efficient packed array of enabled agents (to use for allocations.) -private: - void recomputePeerAgents(); -}; -// Note Mutex type Real/Fake selected based on CtxMutex -typedef ihipCtxCriticalBase_t ihipCtxCritical_t; - -// This type is used by functions that need access to the critical device structures. -typedef LockedAccessor LockedAccessor_CtxCrit_t; -//============================================================================= - - -//============================================================================= -//class ihipCtx_t: -// A HIP CTX (context) points at one of the existing devices and contains the streams, -// peer-to-peer mappings, creation flags. Multiple contexts can point to the same -// device. -// -class ihipCtx_t -{ -public: // Functions: - ihipCtx_t(ihipDevice_t *device, unsigned deviceCnt, unsigned flags); // note: calls constructor for _criticalData - ~ihipCtx_t(); - - // Functions which read or write the critical data are named locked_. - // (might be better called "locking_" - // ihipCtx_t does not use recursive locks so the ihip implementation must avoid calling a locked_ function from within a locked_ function. - // External functions which call several locked_ functions will acquire and release the lock for each function. if this occurs in - // performance-sensitive code we may want to refactor by adding non-locked functions and creating a new locked_ member function to call them all. - void locked_removeStream(ihipStream_t *s); - void locked_reset(); - void locked_waitAllStreams(); - void locked_syncDefaultStream(bool waitOnSelf); - - // Will allocate a queue and assign it to the needyStream: - hc::accelerator_view stealActiveQueue(LockedAccessor_CtxCrit_t &ctxCrit, ihipStream_t *needyStream); - hc::accelerator_view createOrStealQueue(LockedAccessor_CtxCrit_t &ctxCrit); - - ihipCtxCritical_t &criticalData() { return _criticalData; }; - - const ihipDevice_t *getDevice() const { return _device; }; - int getDeviceNum() const { return _device->_deviceId; }; - - // TODO - review uses of getWriteableDevice(), can these be converted to getDevice() - ihipDevice_t *getWriteableDevice() const { return _device; }; - - std::string toString() const; - -public: // Data - // The NULL stream is used if no other stream is specified. - // Default stream has special synchronization properties with other streams. - ihipStream_t *_defaultStream; - - // Flags specified when the context is created: - unsigned _ctxFlags; - -private: - ihipDevice_t *_device; - - -private: // Critical data, protected with locked access: - // Members of _protected data MUST be accessed through the LockedAccessor. - // Search for LockedAccessor for examples; do not access _criticalData directly. - ihipCtxCritical_t _criticalData; - -}; - - - -//================================================================================================= -// Global variable definition: -extern std::once_flag hip_initialized; -extern unsigned g_deviceCnt; -extern hsa_agent_t g_cpu_agent ; // the CPU agent. - -//================================================================================================= -// Extern functions: -extern void ihipInit(); -extern const char *ihipErrorString(hipError_t); -extern ihipCtx_t *ihipGetTlsDefaultCtx(); -extern void ihipSetTlsDefaultCtx(ihipCtx_t *ctx); -extern hipError_t ihipSynchronize(void); -extern void ihipCtxStackUpdate(); -extern hipError_t ihipDeviceSetState(); - -extern ihipDevice_t *ihipGetDevice(int); -ihipCtx_t * ihipGetPrimaryCtx(unsigned deviceIndex); - -extern void ihipSetTs(hipEvent_t e); - - -hipStream_t ihipSyncAndResolveStream(hipStream_t); - -// Stream printf functions: -inline std::ostream& operator<<(std::ostream& os, const ihipStream_t& s) -{ - os << "stream:"; - os << s.getDevice()->_deviceId;; - os << '.'; - os << s._id; - return os; -} - -inline std::ostream & operator<<(std::ostream& os, const dim3& s) -{ - os << '{'; - os << s.x; - os << ','; - os << s.y; - os << ','; - os << s.z; - os << '}'; - return os; -} - -inline std::ostream & operator<<(std::ostream& os, const gl_dim3& s) -{ - os << '{'; - os << s.x; - os << ','; - os << s.y; - os << ','; - os << s.z; - os << '}'; - return os; -} - -// Stream printf functions: -inline std::ostream& operator<<(std::ostream& os, const hipEvent_t& e) -{ - os << "event:" << std::hex << static_cast (e); - return os; -} - -inline std::ostream& operator<<(std::ostream& os, const ihipCtx_t* c) -{ - os << "ctx:" << static_cast (c) - << ".dev:" << c->getDevice()->_deviceId; - return os; -} - - -// Helper functions that are used across src files: -namespace hip_internal { - hipError_t memcpyAsync (void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream); -}; - - -#endif diff --git a/projects/clr/hipamd/src/hip_hcc_internal.h b/projects/clr/hipamd/src/hip_hcc_internal.h index 245f154305..4b960e2820 100644 --- a/projects/clr/hipamd/src/hip_hcc_internal.h +++ b/projects/clr/hipamd/src/hip_hcc_internal.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_HCC_H -#define HIP_HCC_H +#ifndef HIP_SRC_HIP_HCC_INTERNAL_H +#define HIP_SRC_HIP_HCC_INTERNAL_H #include #include diff --git a/projects/clr/hipamd/src/hip_ldg.cpp b/projects/clr/hipamd/src/hip_ldg.cpp index d91f54a807..549d3ae085 100644 --- a/projects/clr/hipamd/src/hip_ldg.cpp +++ b/projects/clr/hipamd/src/hip_ldg.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/projects/clr/hipamd/src/hip_util.h b/projects/clr/hipamd/src/hip_util.h index f6817ffccb..8c4d19bb40 100644 --- a/projects/clr/hipamd/src/hip_util.h +++ b/projects/clr/hipamd/src/hip_util.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef HIP_UTIL_H -#define HIP_UTIL_H +#ifndef HIP_INCLUDE_HCC_DETAIL_HIP_UTIL_H +#define HIP_INCLUDE_HCC_DETAIL_HIP_UTIL_H #include #include diff --git a/projects/clr/hipamd/tests/src/hipHcc.cpp b/projects/clr/hipamd/tests/src/hipHcc.cpp index 9357e5211a..92d9e3e88d 100644 --- a/projects/clr/hipamd/tests/src/hipHcc.cpp +++ b/projects/clr/hipamd/tests/src/hipHcc.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. #include #include #include "hip/hip_runtime.h" -#include "hip/hcc.h" +#include "hip/hip_hcc.h" #include "test_common.h" #define CHECK(error) \ @@ -61,4 +61,3 @@ int main(int argc, char *argv[]) passed(); }; - From 5d097642befd24899da9d5eda009c6886491d59a Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Fri, 31 Mar 2017 13:35:26 -0500 Subject: [PATCH 44/56] Fixed bit_extract Change-Id: I92d7b7a302e3fa0db84889fb5dc6b612e6a53c73 [ROCm/clr commit: d4f3fb092a9cc05005ad46a968df06c56e33db69] --- projects/clr/hipamd/samples/0_Intro/bit_extract/Makefile | 1 - .../clr/hipamd/samples/0_Intro/bit_extract/bit_extract.cpp | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/samples/0_Intro/bit_extract/Makefile b/projects/clr/hipamd/samples/0_Intro/bit_extract/Makefile index 0965ae7296..78f6a2faa8 100644 --- a/projects/clr/hipamd/samples/0_Intro/bit_extract/Makefile +++ b/projects/clr/hipamd/samples/0_Intro/bit_extract/Makefile @@ -24,4 +24,3 @@ $(EXE): bit_extract.cpp clean: rm -f *.o $(EXE) - diff --git a/projects/clr/hipamd/samples/0_Intro/bit_extract/bit_extract.cpp b/projects/clr/hipamd/samples/0_Intro/bit_extract/bit_extract.cpp index 1535d2bd98..a30f2d052d 100644 --- a/projects/clr/hipamd/samples/0_Intro/bit_extract/bit_extract.cpp +++ b/projects/clr/hipamd/samples/0_Intro/bit_extract/bit_extract.cpp @@ -37,7 +37,7 @@ THE SOFTWARE. }\ } -void __global__ +__global__ void bit_extract_kernel(hipLaunchParm lp, uint32_t *C_d, const uint32_t *A_d, size_t N) { size_t offset = (hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x); @@ -45,7 +45,7 @@ bit_extract_kernel(hipLaunchParm lp, uint32_t *C_d, const uint32_t *A_d, size_t for (size_t i=offset; i> 8); #endif @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) C_h = (uint32_t*)malloc(Nbytes); CHECK(C_h == 0 ? hipErrorMemoryAllocation : hipSuccess ); - for (size_t i=0; i Date: Fri, 31 Mar 2017 14:13:46 -0500 Subject: [PATCH 45/56] added debug support for HIP sample Change-Id: Ia7265234082039b68114f7421f4dbcb7149d4d2b [ROCm/clr commit: 81d3725a162bec71f3bc351b825c36a13c166604] --- .../clr/hipamd/samples/0_Intro/module_api/runKernel.cpp | 9 ++++++--- projects/clr/hipamd/src/hip_module.cpp | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/projects/clr/hipamd/samples/0_Intro/module_api/runKernel.cpp b/projects/clr/hipamd/samples/0_Intro/module_api/runKernel.cpp index e7d54beb54..355f0bf5da 100644 --- a/projects/clr/hipamd/samples/0_Intro/module_api/runKernel.cpp +++ b/projects/clr/hipamd/samples/0_Intro/module_api/runKernel.cpp @@ -33,6 +33,9 @@ THE SOFTWARE. #define fileName "vcpy_kernel.code" #define kernel_name "hello_world" +#define HIP_CHECK(status) \ +if(status != hipSuccess) {std::cout<<"Got Status: "< Date: Fri, 31 Mar 2017 14:30:40 -0500 Subject: [PATCH 46/56] added module api sample which uses hipHccModuleLaunchKernel Change-Id: I7bce60b4480a3b5ff7ed69c3256078ded65a0945 [ROCm/clr commit: 0fab80e515344b869f11270d9ffebb943e2687e8] --- .../samples/0_Intro/module_api/Makefile | 3 + .../0_Intro/module_api/launchKernelHcc.cpp | 112 ++++++++++++++++++ .../samples/0_Intro/module_api/runKernel.cpp | 4 - 3 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 projects/clr/hipamd/samples/0_Intro/module_api/launchKernelHcc.cpp diff --git a/projects/clr/hipamd/samples/0_Intro/module_api/Makefile b/projects/clr/hipamd/samples/0_Intro/module_api/Makefile index 632a8d3e70..38bd00a6a6 100644 --- a/projects/clr/hipamd/samples/0_Intro/module_api/Makefile +++ b/projects/clr/hipamd/samples/0_Intro/module_api/Makefile @@ -10,6 +10,9 @@ all: vcpy_kernel.code runKernel.hip.out defaultDriver.hip.out runKernel.hip.out: runKernel.cpp $(HIPCC) $(HIPCC_FLAGS) $< -o $@ +launchKernelHcc.hip.out: launchKernelHcc.cpp + $(HIPCC) $(HIPCC_FLAGS) $< -o $@ + defaultDriver.hip.out: defaultDriver.cpp $(HIPCC) $(HIPCC_FLAGS) $< -o $@ diff --git a/projects/clr/hipamd/samples/0_Intro/module_api/launchKernelHcc.cpp b/projects/clr/hipamd/samples/0_Intro/module_api/launchKernelHcc.cpp new file mode 100644 index 0000000000..e86e44cb24 --- /dev/null +++ b/projects/clr/hipamd/samples/0_Intro/module_api/launchKernelHcc.cpp @@ -0,0 +1,112 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + + +#include "hip/hip_runtime.h" +#include "hip/hip_runtime_api.h" +#include +#include +#include + +#ifdef __HIP_PLATFORM_HCC__ +#include +#endif + +#define LEN 64 +#define SIZE LEN<<2 + +#define fileName "vcpy_kernel.code" +#define kernel_name "hello_world" + +#define HIP_CHECK(status) \ +if(status != hipSuccess) {std::cout<<"Got Status: "< Date: Sat, 1 Apr 2017 08:21:06 -0500 Subject: [PATCH 47/56] Move current GGL limitations to hip_bugs.md Change-Id: I77d0eae0a67eccef7dd2bea0f402736642c96554 [ROCm/clr commit: 5826e5364491412cf0cd865f2ba16e89ea331655] --- projects/clr/hipamd/docs/markdown/hip_bugs.md | 9 ++++++--- projects/clr/hipamd/docs/markdown/hip_faq.md | 5 ----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/projects/clr/hipamd/docs/markdown/hip_bugs.md b/projects/clr/hipamd/docs/markdown/hip_bugs.md index 3274ed5b5c..e15c37fc54 100644 --- a/projects/clr/hipamd/docs/markdown/hip_bugs.md +++ b/projects/clr/hipamd/docs/markdown/hip_bugs.md @@ -4,6 +4,7 @@ - [Errors related to undefined reference to `__hcLaunchKernel__***__grid_launch_parm**](#errors-related-to-undefined-reference-to-hclaunchkernel__grid_launch_parm) - [Application hangs after a hipLaunchKernel call](#what-if-i-see-application-hangs-after-a-hiplaunchkernel-call) +- [What is the current limitation of HIP Generic Grid Launch method?](#what-is-the-current-limitation-of-hip-generic-grid-launch-method) @@ -23,8 +24,6 @@ namespace { __global__ MyKernel … - Avoid calling member functions - -### What if I see application hangs after a hipLaunchKernel call? If hipLaunchKernel takes parameters that request explicitly memcpy, then it will cause application hang. Reason is that the hipLaunchKernel macro locks the stream. If kernel paramters are actually function calls which invoke other hip apis (i.e. memcpy) to the same stream, then deadlock occurs. @@ -43,4 +42,8 @@ auto bot_gpu_data = bottom[0]->gpu_data(); hipLaunchKernel( LRNComputeDiff, dim3(CAFFE_GET_BLOCKS(n_threads)), dim3(CAFFE_HIP_NUM_THREADS), 0, 0, n_threads, bot_gpu_data); -``` \ No newline at end of file +``` + +### What is the current limitation of HIP Generic Grid Launch method? +1. __global__ functions cannot be marked as static or put in an unnamed namespace i.e. they cannot be given internal linkage (this would clash with __attribute__((weak))); +2. using the macro based dispatch mechanism i.e. hipLaunchKernel* only works for functions that take no more than 20 arguments (this limit can be increased up to 126, and is temporary until we can enable C++14 mode and use variadic generic lambdas); no such limitation applies do dispatching directly through grid_launch. \ No newline at end of file diff --git a/projects/clr/hipamd/docs/markdown/hip_faq.md b/projects/clr/hipamd/docs/markdown/hip_faq.md index ee7e5dd347..8ccb458103 100644 --- a/projects/clr/hipamd/docs/markdown/hip_faq.md +++ b/projects/clr/hipamd/docs/markdown/hip_faq.md @@ -27,7 +27,6 @@ * [Using CodeXL markers for HIP Functions](#using-codexl-markers-for-hip-functions) * [Using HIP_TRACE_API](#using-hip_trace_api) - [How do I enable HIP Generic Grid Launch option?](#how-do-i-enable-hip-generic-grid-launch-option) -- [What is the current limitation of HIP Generic Grid Launch method?](#what-is-the-current-limitation-of-hip-generic-grid-launch-method) @@ -243,7 +242,3 @@ To disable it and use the legancy grid launch method, please either change the d $HIP/include/hip/hcc_detail/hip_runtime_api.h $HIP/include/hip/hcc_detail/host_defines.h Or pass "-DGENERIC_GRID_LAUNCH=0" to hipcc at application compilation time. - -### What is the current limitation of HIP Generic Grid Launch method? -1. __global__ functions cannot be marked as static or put in an unnamed namespace i.e. they cannot be given internal linkage (this would clash with __attribute__((weak))); -2. using the macro based dispatch mechanism i.e. hipLaunchKernel* only works for functions that take no more than 20 arguments (this limit can be increased up to 126, and is temporary until we can enable C++14 mode and use variadic generic lambdas); no such limitation applies do dispatching directly through grid_launch. \ No newline at end of file From 5a4ac0929ff4931e555226a0892dbaeef921d6a2 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Sat, 1 Apr 2017 14:50:39 -0500 Subject: [PATCH 48/56] GGL update, fix for thread-safe access to streams (accelerator_views). Change-Id: I6dd329a85b3ba7de23d52823febee0c53857a981 [ROCm/clr commit: df4cee1a5775178584d9d6d5a4a5ec0998bcc32b] --- projects/clr/hipamd/CMakeLists.txt | 1 + .../include/hip/hcc_detail/concepts.hpp | 2 +- ...grid_launch_v2.hpp => grid_launch_GGL.hpp} | 181 +++++++++++++++--- .../hipamd/include/hip/hcc_detail/helpers.hpp | 2 +- .../include/hip/hcc_detail/hip_runtime.h | 4 +- 5 files changed, 157 insertions(+), 33 deletions(-) rename projects/clr/hipamd/include/hip/hcc_detail/{grid_launch_v2.hpp => grid_launch_GGL.hpp} (86%) diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index dcecaa8d2f..9d6bf26f56 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -179,6 +179,7 @@ if(HIP_PLATFORM STREQUAL "hcc") src/hip_peer.cpp src/hip_stream.cpp src/hip_module.cpp + src/grid_launch.cpp src/env.cpp) set(SOURCE_FILES_DEVICE diff --git a/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp b/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp index 6824ad9bdf..5c50f5d577 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/concepts.hpp @@ -22,7 +22,7 @@ THE SOFTWARE. #pragma once -namespace glo_tests // Documentation only. +namespace hip_impl // Documentation only. { #define requires(...) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_GGL.hpp similarity index 86% rename from projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp rename to projects/clr/hipamd/include/hip/hcc_detail/grid_launch_GGL.hpp index 8b1eded2f3..e2965184f6 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_v2.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_GGL.hpp @@ -27,7 +27,7 @@ THE SOFTWARE. #include "hc.hpp" #include "hip_hcc.h" - +#include "hip_runtime.h" #include #include #include @@ -38,13 +38,39 @@ namespace hip_impl { struct New_grid_launch_tag {}; struct Old_grid_launch_tag {}; - } - template - using is_new_grid_launch_t = typename std::conditional< - std::is_callable{}, - New_grid_launch_tag, - Old_grid_launch_tag>::type; + template + class RAII_guard { + D dtor_; + public: + RAII_guard() = default; + + RAII_guard(const C& ctor, D dtor) : dtor_{std::move(dtor)} + { + ctor(); + } + + RAII_guard(const RAII_guard&) = default; + RAII_guard(RAII_guard&&) = default; + + RAII_guard& operator=(const RAII_guard&) = default; + RAII_guard& operator=(RAII_guard&&) = default; + + ~RAII_guard() { dtor_(); } + }; + + template + RAII_guard make_RAII_guard(const C& ctor, D dtor) + { + return RAII_guard{ctor, std::move(dtor)}; + } + + template + using is_new_grid_launch_t = typename std::conditional< + std::is_callable{}, + New_grid_launch_tag, + Old_grid_launch_tag>::type; + } // TODO: - dispatch rank should be derived from the domain dimensions passed // in, and not always assumed to be 3; @@ -52,12 +78,12 @@ namespace hip_impl template requires(Domain == {Ts...}) inline - void grid_launch_impl( + void grid_launch_hip_impl_( New_grid_launch_tag, dim3 num_blocks, dim3 dim_blocks, int group_mem_bytes, - hipStream_t stream, + const hc::accelerator_view& acc_v, K k, Ts&&... args) { @@ -69,21 +95,69 @@ namespace hip_impl dim_blocks.y, dim_blocks.x, group_mem_bytes); - hc::accelerator_view* av = nullptr; - if (hipHccGetAcceleratorView(stream, &av) != HIP_SUCCESS) { - throw std::runtime_error{"Failed to retrieve accelerator_view!"}; + try { + hc::parallel_for_each( + acc_v, + d, + [=](const hc::tiled_index<3>& idx) [[hc]] { + k(args...); + }); } + catch (std::exception& ex) { + std::cerr << "Failed in " << __FUNCTION__ << ", with exception: " + << ex.what() << std::endl; + throw; + } + } - hc::parallel_for_each(*av, d, [=](const hc::tiled_index<3>& idx) [[hc]] { - k(args...); - }); + // TODO: these are workarounds, they should be removed. + + hc::accelerator_view lock_stream_hip_(hipStream_t&, void*&); + void unlock_stream_hip_( + hipStream_t, void*, const char*, hc::accelerator_view*); + + template + requires(Domain == {Ts...}) + inline + void grid_launch_hip_impl_( + New_grid_launch_tag, + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + const char* kernel_name, + K k, + Ts&&... args) + { + void* lck_stream = nullptr; + auto acc_v = lock_stream_hip_(stream, lck_stream); + auto stream_guard = make_RAII_guard( + [](){ /* perhaps use a slimmed down ihipPrintKernelLaunch here */ }, + std::bind( + unlock_stream_hip_, stream, lck_stream, kernel_name, &acc_v)); + + try { + grid_launch_hip_impl_( + New_grid_launch_tag{}, + std::move(num_blocks), + std::move(dim_blocks), + group_mem_bytes, + acc_v, + std::move(k), + std::forward(args)...); + } + catch (std::exception& ex) { + std::cerr << "Failed in " << __FUNCTION__ << ", with exception: " + << ex.what() << std::endl; + throw; + } } template requires(Domain == {hipLaunchParm, Ts...}) inline - void grid_launch_impl( + void grid_launch_hip_impl_( Old_grid_launch_tag, dim3 num_blocks, dim3 dim_blocks, @@ -92,7 +166,7 @@ namespace hip_impl K k, Ts&&... args) { - grid_launch_impl( + grid_launch_hip_impl_( New_grid_launch_tag{}, std::move(num_blocks), std::move(dim_blocks), @@ -103,10 +177,58 @@ namespace hip_impl std::forward(args)...); } + template + requires(Domain == {hipLaunchParm, Ts...}) + inline + void grid_launch_hip_impl_( + Old_grid_launch_tag, + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + const char* kernel_name, + K k, + Ts&&... args) + { + grid_launch_hip_impl_( + New_grid_launch_tag{}, + std::move(num_blocks), + std::move(dim_blocks), + group_mem_bytes, + std::move(stream), + kernel_name, + std::move(k), + hipLaunchParm{}, + std::forward(args)...); + } + template requires(Domain == {Ts...}) inline - std::enable_if_t::value> grid_launch( + std::enable_if_t::value> grid_launch_hip_( + dim3 num_blocks, + dim3 dim_blocks, + int group_mem_bytes, + hipStream_t stream, + const char* kernel_name, + K k, + Ts&& ... args) + { + grid_launch_hip_impl_( + is_new_grid_launch_t{}, + std::move(num_blocks), + std::move(dim_blocks), + group_mem_bytes, + std::move(stream), + kernel_name, + std::move(k), + std::forward(args)...); + } + + template + requires(Domain == {Ts...}) + inline + std::enable_if_t::value> grid_launch_hip_( dim3 num_blocks, dim3 dim_blocks, int group_mem_bytes, @@ -114,7 +236,7 @@ namespace hip_impl K k, Ts&& ... args) { - grid_launch_impl( + grid_launch_hip_impl_( is_new_grid_launch_t{}, std::move(num_blocks), std::move(dim_blocks), @@ -129,7 +251,7 @@ namespace hip_impl template constexpr inline - T&& forward(std::remove_reference_t& x) [[hc]] + T&& forward_(std::remove_reference_t& x) [[hc]] { return static_cast(x); } @@ -139,7 +261,7 @@ namespace hip_impl template void operator()(Ts&&...args) const [[hc]] { - k(forward(args)...); + k(forward_(args)...); } }; } @@ -155,7 +277,7 @@ namespace hip_impl hipStream_t stream, Ts&&... args) { - grid_launch_impl( + grid_launch_hip_impl_( New_grid_launch_tag{}, std::move(num_blocks), std::move(dim_blocks), @@ -176,7 +298,7 @@ namespace hip_impl hipStream_t stream, Ts&&... args) { - grid_launch( + grid_launch_hip_( New_grid_launch_tag{}, std::move(num_blocks), std::move(dim_blocks), @@ -189,14 +311,14 @@ namespace hip_impl template requires(Domain == {Ts...}) inline - std::enable_if_t::value> grid_launch( + std::enable_if_t::value> grid_launch_hip_( dim3 num_blocks, dim3 dim_blocks, int group_mem_bytes, hipStream_t stream, Ts&&... args) { - grid_launch( + grid_launch_hip_( is_new_grid_launch_t{}, std::move(num_blocks), std::move(dim_blocks), @@ -685,7 +807,7 @@ namespace hip_impl kernel_name(_p0_);\ } #define make_kernel_lambda_hip_1(kernel_name)\ - []() [[hc]] { kernel_name(lp); } + []() [[hc]] { return kernel_name(hipLaunchParm{}); } #define make_kernel_lambda_hip_(...)\ overload_macro_hip_(make_kernel_lambda_hip_, __VA_ARGS__) @@ -697,15 +819,16 @@ namespace hip_impl group_mem_bytes,\ stream,\ ...)\ - {\ - hip_impl::grid_launch(\ + do {\ + hip_impl::grid_launch_hip_(\ num_blocks,\ dim_blocks,\ group_mem_bytes,\ stream,\ + #kernel_name,\ make_kernel_lambda_hip_(kernel_name, __VA_ARGS__),\ ##__VA_ARGS__);\ - } + } while(0) #define hipLaunchKernel(\ kernel_name,\ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp index 5ab866dc66..e5a84a4678 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/helpers.hpp @@ -123,7 +123,7 @@ namespace std #endif } -namespace // Only for documentation, macros ignore namespaces. +namespace hip_impl // Only for documentation, macros ignore namespaces. { #define count_macro_args_impl_hip_(\ _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15,\ diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index 9692b16a4c..e0375269e7 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -68,7 +68,7 @@ THE SOFTWARE. #else namespace hip_impl { - struct Empty_launch_parm{}; + struct Empty_launch_parm {}; } #define hipLaunchParm hip_impl::Empty_launch_parm #endif //GENERIC_GRID_LAUNCH @@ -81,7 +81,7 @@ namespace hip_impl #endif //HCC #if GENERIC_GRID_LAUNCH==1 && defined __HCC__ -#include "grid_launch_v2.hpp" +#include "grid_launch_GGL.hpp" #endif//GENERIC_GRID_LAUNCH extern int HIP_TRACE_API; From a8708e7bdd5858fbb94f13f9890f02e0a00d92da Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Sat, 1 Apr 2017 14:57:47 -0500 Subject: [PATCH 49/56] Add grid_launch.cpp for GGL Change-Id: I87ff9b3f1203d0909f998c96c839f7b321fc3f09 [ROCm/clr commit: ae8448a9af99290eef4b869f82e7558e2292a6f0] --- projects/clr/hipamd/src/grid_launch.cpp | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 projects/clr/hipamd/src/grid_launch.cpp diff --git a/projects/clr/hipamd/src/grid_launch.cpp b/projects/clr/hipamd/src/grid_launch.cpp new file mode 100644 index 0000000000..6e2812f159 --- /dev/null +++ b/projects/clr/hipamd/src/grid_launch.cpp @@ -0,0 +1,38 @@ +#include "hip/hcc_detail/grid_launch_GGL.hpp" + +// Internal header, do not percolate upwards. +#include "hip_hcc_internal.h" +#include "hc.hpp" +#include "trace_helper.h" + +namespace hip_impl +{ + hc::accelerator_view lock_stream_hip_( + hipStream_t& stream, void*& locked_stream) + { // This allocated but does not take ownership of locked_stream. If it is + // not deleted elsewhere it will leak. + using L = decltype(stream->lockopen_preKernelCommand()); + + HIP_INIT(); + + stream = ihipSyncAndResolveStream(stream); + locked_stream = new L{stream->lockopen_preKernelCommand()}; + return (*static_cast(locked_stream))->_av; + } + + void unlock_stream_hip_( + hipStream_t stream, + void* locked_stream, + const char* kernel_name, + hc::accelerator_view* acc_v) + { // Precondition: acc_v is the accelerator_view associated with stream + // which is guarded by locked_stream; + // locked_stream is deletable. + using L = decltype(stream->lockopen_preKernelCommand()); + + stream->lockclose_postKernelCommand(kernel_name, acc_v); + + delete static_cast(locked_stream); + locked_stream = nullptr; + } +} From f202567d83e1887e641b729c3607a87cbb6ba926 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Sat, 1 Apr 2017 15:01:00 -0500 Subject: [PATCH 50/56] Disable LLVM related config in CMakeLists.txt Change-Id: I02e52264219d68c1ae8ea37c8df166a0edf9f7cd [ROCm/clr commit: b91a37c78a718073a7f017147626930eef5823ed] --- projects/clr/hipamd/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index 9d6bf26f56..94ed2a7562 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -191,11 +191,11 @@ if(HIP_PLATFORM STREQUAL "hcc") execute_process(COMMAND ${HCC_HOME}/bin/hcc-config --ldflags OUTPUT_VARIABLE HCC_LD_FLAGS) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${HCC_LD_FLAGS} -Wl,-Bsymbolic") - find_package(LLVM HINTS ${HCC_HOME}/compiler/lib/cmake) + #find_package(LLVM HINTS ${HCC_HOME}/compiler/lib/cmake) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --amdgpu-target=gfx701 --amdgpu-target=gfx801 --amdgpu-target=gfx802 --amdgpu-target=gfx803 --amdgpu-target=gfx900") add_library(hip_hcc SHARED ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc PRIVATE hc_am) - target_link_libraries(hip_hcc PUBLIC LLVMAMDGPUUtils) + #target_link_libraries(hip_hcc PUBLIC LLVMAMDGPUUtils) add_library(hip_hcc_static STATIC ${SOURCE_FILES_RUNTIME}) target_link_libraries(hip_hcc_static PRIVATE hc_am) add_dependencies(hip_hcc_static hip_hcc) From 72d4fe0213dfe816f86c8057fc4118f728a676aa Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Sat, 1 Apr 2017 15:12:00 -0500 Subject: [PATCH 51/56] Add copy right in grid_launch.cpp Change-Id: I7de3fc32f13182b5c41a4e44147b642ba15e8636 [ROCm/clr commit: 97626674319eb27749758989ec36e604e5db7f0a] --- projects/clr/hipamd/src/grid_launch.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/projects/clr/hipamd/src/grid_launch.cpp b/projects/clr/hipamd/src/grid_launch.cpp index 6e2812f159..7739995600 100644 --- a/projects/clr/hipamd/src/grid_launch.cpp +++ b/projects/clr/hipamd/src/grid_launch.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "hip/hcc_detail/grid_launch_GGL.hpp" // Internal header, do not percolate upwards. From 0e23f09b4766cd01625730a19f685c117d178edb Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Sat, 1 Apr 2017 15:42:53 -0500 Subject: [PATCH 52/56] Fix warpSize, for related issue in hipeigen and torch Change-Id: Ic66b24923a363304dca189011869ba7a0a6f8895 [ROCm/clr commit: a7d7797781fc6686c1d30b28913a1d8407463533] --- projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h | 3 +-- projects/clr/hipamd/src/device_util.cpp | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h index e0375269e7..06ce65bc9a 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime.h @@ -159,8 +159,7 @@ extern int HIP_TRACE_API; // TODO - hipify-clang - change to use the function call. //#define warpSize hc::__wavesize() -extern const int warpSize; - +static constexpr int warpSize = 64; #define clock_t long long int __device__ long long int clock64(); diff --git a/projects/clr/hipamd/src/device_util.cpp b/projects/clr/hipamd/src/device_util.cpp index b0df62f43b..8ce53765b5 100644 --- a/projects/clr/hipamd/src/device_util.cpp +++ b/projects/clr/hipamd/src/device_util.cpp @@ -835,10 +835,6 @@ __device__ float __hip_ynf(int n, float x) return b0; } - - -const int warpSize = 64; - __device__ long long int clock64() { return (long long int)hc::__cycle_u64(); }; __device__ clock_t clock() { return (clock_t)hc::__cycle_u64(); }; From b3235100025ed4d628d31fb86c8ff389206d2d0d Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Sun, 2 Apr 2017 11:56:15 -0500 Subject: [PATCH 53/56] Fix hip Module APIs by disabling GGL when hipcc takes -genco option Change-Id: I0a79e9c8e750f92c3d0be336d6ff709a2d1afd63 [ROCm/clr commit: f9c8ac54356642797802da9a96ca09342c98b384] --- projects/clr/hipamd/bin/hccgenco.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/bin/hccgenco.sh b/projects/clr/hipamd/bin/hccgenco.sh index 7f90cce83d..9d7f602911 100755 --- a/projects/clr/hipamd/bin/hccgenco.sh +++ b/projects/clr/hipamd/bin/hccgenco.sh @@ -45,7 +45,7 @@ for inputfile in $INPUT_FILES; do done printf "\nint main(){}\n" >> $hipgenisa_main -$HIP_PATH/bin/hipcc $hipgenisa_files -o $hipgenisa_dir/a.out +$HIP_PATH/bin/hipcc -DGENERIC_GRID_LAUNCH=0 $hipgenisa_files -o $hipgenisa_dir/a.out mv dump* $hipgenisa_dir hsaco_file="dump-$ROCM_TARGET.hsaco" From 5f99f3811bf4084c6b3cf0c480ce66c3f4b19494 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Mon, 3 Apr 2017 11:18:30 +0530 Subject: [PATCH 54/56] Enable promote free HCC by default Change-Id: I5f82a8d958dd675a8a46d9d17458c71321daab7c [ROCm/clr commit: cea13c34c3f58fdb8e9f963e61cef8520732152b] --- projects/clr/hipamd/include/hip/hcc_detail/host_defines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h index 4f44774700..b0a7421d18 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/host_defines.h @@ -28,7 +28,7 @@ THE SOFTWARE. #ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HOST_DEFINES_H #define HIP_INCLUDE_HIP_HCC_DETAIL_HOST_DEFINES_H -#define USE_PROMOTE_FREE_HCC 0 +#define USE_PROMOTE_FREE_HCC 1 // Add guard to Generic Grid Launch method #ifndef GENERIC_GRID_LAUNCH From aab655ff0156c7c52e3ffb75e09996ddebd30c87 Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Mon, 3 Apr 2017 15:09:31 +0530 Subject: [PATCH 55/56] Force stdlib=libc++ on UB14.04 Change-Id: I7f24d663e57fbbee56afde12a0e61fc8bfc1e9b6 [ROCm/clr commit: 3df134971b27f10a984968875ab903f2dfdb0ec1] --- projects/clr/hipamd/bin/hipcc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/projects/clr/hipamd/bin/hipcc b/projects/clr/hipamd/bin/hipcc index de4883fea3..bcd3e3a591 100755 --- a/projects/clr/hipamd/bin/hipcc +++ b/projects/clr/hipamd/bin/hipcc @@ -123,6 +123,14 @@ if ($HIP_PLATFORM eq "hcc") { } } + # Force -stdlib=libc++ on UB14.04 + $HOST_OSNAME= `cat /etc/os-release | grep "^ID\=" | cut -d= -f2 | tr -d '\n'`; + $HOST_OSVER= `cat /etc/os-release | grep "^VERSION_ID\=" | cut -d= -f2 | tr -d '\n'`; + if ($HOST_OSNAME eq "ubuntu" and $HOST_OSVER eq "\"14.04\"") { + $HIPCXXFLAGS .= " -stdlib=libc++"; + $setStdLib = 1; + } + $HIPCXXFLAGS .= " -I$HIP_PATH/include/hip/hcc_detail/cuda"; $HIPCXXFLAGS .= " -I$HSA_PATH/include"; $HIPCXXFLAGS .= " -Wno-deprecated-register"; From e342bbc7fb197d23534ba25972501af6edc2abb1 Mon Sep 17 00:00:00 2001 From: "Sun, Peng" Date: Mon, 3 Apr 2017 11:06:18 -0500 Subject: [PATCH 56/56] Add more include header file for GGL, to make it self-compilable Change-Id: I833cb194784450fb86e7961a7f9fe196ce3c7da5 [ROCm/clr commit: 2ca9eec9fcc1a255874445b245bf0d12eff9e397] --- projects/clr/hipamd/include/hip/hcc_detail/grid_launch_GGL.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_GGL.hpp b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_GGL.hpp index e2965184f6..4fd7c3ff3a 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_GGL.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/grid_launch_GGL.hpp @@ -28,6 +28,9 @@ THE SOFTWARE. #include "hc.hpp" #include "hip_hcc.h" #include "hip_runtime.h" + +#include +#include #include #include #include