diff --git a/docs/faq.rst b/docs/faq.rst index 3a20742e80..14e3fc0643 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -2,8 +2,11 @@ Frequently asked questions ******************************************************************************* +HIP Support +=========== + What APIs and features does HIP support? -======================================== +---------------------------------------- HIP provides the following: @@ -18,13 +21,13 @@ HIP provides the following: * Most device-side math built-ins * Error reporting (``hipGetLastError()``, ``hipGetErrorString()``) -The HIP API documentation describes each API and its limitations, if any, compared with the equivalent CUDA API. +The `HIP API documentation `_ describes each API and its limitations, if any, compared with the equivalent CUDA API. What is not supported? -====================== +---------------------- Runtime/Driver API features ---------------------------- +``````````````````````````` At a high-level, the following features are not supported: @@ -38,7 +41,7 @@ At a high-level, the following features are not supported: See the `API Support Table `_ for more detailed information. Kernel language features ------------------------- +```````````````````````` * C++-style device-side dynamic memory allocations (free, new, delete) (CUDA 4.0) * Try/catch (CUDA 4.0) @@ -46,15 +49,96 @@ Kernel language features * PTX assembly (CUDA 4.0). HIP-Clang supports inline GCN assembly. * Several kernel features are under development. See the :doc:`/reference/cpp_language_extensions` for more information. +What libraries does HIP support? +-------------------------------- + +HIP includes growing support for the four key math libraries using hipBLAS, hipFFT, hipRAND and hipSPARSE, as well as MIOpen for machine intelligence applications. +These offer pointer-based memory interfaces (as opposed to opaque buffers) and can be easily interfaced with other HIP applications. +The hip interfaces support both ROCm and CUDA paths, with familiar library interfaces. + +* `hipBLAS `_, which utilizes `rocBlas `_. +* `hipCUB `_, which utilizes `rocPRIM `_. +* `hipFFT `_ +* `hipsSPARSE `_ +* `hipRAND `_ +* `MIOpen `_ +* `rocThrust `_, which utilizes `rocPRIM `_. + +Additionally, some of the cuBLAS routines are automatically converted to hipblas equivalents by the HIPIFY tools. These APIs use cuBLAS or hcBLAS depending on the platform and replace the need to use conditional compilation. + +On HIP-Clang, can I link HIP code with host code compiled with another compiler such as gcc, icc, or clang? +----------------------------------------------------------------------------------------------------------- + +Yes. HIP generates the object code which conforms to the GCC ABI, and also links with libstdc++. This means you can compile host code with the compiler of your choice and link the generated object code +with GPU code compiled with HIP. Larger projects often contain a mixture of accelerator code (initially written in CUDA with NVCC) and host code (compiled with gcc, icc, or clang). These projects +can convert the accelerator code to HIP, compile that code with hipcc, and link with object code from their preferred compiler. + +Can HIP API support C style application? What is the difference between C and C++? +---------------------------------------------------------------------------------- + +HIP is C++ runtime API that supports C style applications as well. + +Some C style applications (and interfaces to other languages (FORTRAN, Python)) would call certain HIP APIs but not use kernel programming. +They can be compiled with a C compiler and run correctly, however, small details must be considered in the code. For example, initialization, as shown in the simple application below, uses HIP structs dim3 with the file name "test.hip.cpp" + +.. code-block:: cpp + + #include "hip/hip_runtime_api.h" + #include "stdio.h" + + int main(int argc, char** argv) { + dim3 grid1; + printf("dim3 grid1; x=%d, y=%d, z=%d\n",grid1.x,grid1.y,grid1.z); + dim3 grid2 = {1,1,1}; + printf("dim3 grid2 = {1,1,1}; x=%d, y=%d, z=%d\n",grid2.x,grid2.y,grid2.z); + return 0; + } + +When using a C++ compiler, + +.. code-block:: shell + + $ gcc -x c++ $(hipconfig --cpp_config) test3.hip.cpp -o test + $ ./test + dim3 grid1; x=1, y=1, z=1 + dim3 grid2 = {1,1,1}; x=1, y=1, z=1 + +In which "dim3 grid1;" will yield a dim3 grid with all dimensional members x,y,z initialized to 1, as the default constructor behaves that way. +Further, if written: + +.. code-block:: cpp + + dim3 grid(2); // yields {2,1,1} + dim3 grid(2,3); yields {2,3,1} + +In comparison, when using the C compiler, + +.. code-block:: shell + + $ gcc -x c $(hipconfig --cpp_config) test.hip.cpp -o test + $ ./test + dim3 grid1; x=646881376, y=21975, z=1517277280 + dim3 grid2 = {1,1,1}; x=1, y=1, z=1 + +In which "dim3 grid;" does not imply any initialization, no constructor is called, and dimensional values x,y,z of grid are undefined. +NOTE: To get the C++ default behavior, C programmers must additionally specify the right-hand side as shown below, + +.. code-block:: cpp + + dim3 grid = {1,1,1}; // initialized as in C++ + +CUDA and OpenCL +=============== + Is HIP a drop-in replacement for CUDA? -====================================== +-------------------------------------- No. HIP provides porting tools which do most of the work to convert CUDA code into portable C++ code that uses the HIP APIs. Most developers will port their code from CUDA to HIP and then maintain the HIP version. HIP code provides the same performance as native CUDA code, plus the benefits of running on AMD platforms. What specific version of CUDA does HIP support? -=============================================== +----------------------------------------------- HIP APIs and features do not map to a specific CUDA version. HIP provides a strong subset of the functionality provided in CUDA, and the hipify tools can scan code to identify any unsupported CUDA functions - this is useful for identifying the specific features required by a given application. @@ -84,11 +168,11 @@ However, we can provide a rough summary of the features included in each CUDA SD * LUID (supported) * CUDA 11.0 : * CUDA 12.0 : - * Virtual memory management (supported) + * `Virtual memory management (supported) `_ * Revamped Dynamic Parallelism APIs (not supported) What libraries does HIP support? -================================ +-------------------------------- HIP includes growing support for the four key math libraries using hipBLAS, hipFFT, hipRAND and hipSPARSE, as well as MIOpen for machine intelligence applications. These offer pointer-based memory interfaces (as opposed to opaque buffers) and can be easily interfaced with other HIP applications. @@ -105,7 +189,7 @@ The hip interfaces support both ROCm and CUDA paths, with familiar library inter Additionally, some of the cuBLAS routines are automatically converted to hipblas equivalents by the HIPIFY tools. These APIs use cuBLAS or hcBLAS depending on the platform and replace the need to use conditional compilation. How does HIP compare with OpenCL? -================================= +--------------------------------- AMD supports OpenCL 2.2 and NVIDIA supports OpenCL 1.2 on their devices so that developers can write portable code. HIP offers several benefits over OpenCL: @@ -119,7 +203,7 @@ HIP offers several benefits over OpenCL: * HIP offers an offline compilation model. How does porting CUDA to HIP compare to porting CUDA to OpenCL? -=============================================================== +--------------------------------------------------------------- Both HIP and CUDA are dialects of C++, and thus porting between them is relatively straightforward. Both dialects support templates, classes, lambdas, and other C++ constructs. @@ -131,40 +215,89 @@ There have been several tools that have attempted to convert CUDA into OpenCL, s As a result, the OpenCL syntax is different from CUDA, and the porting tools have to perform some heroic transformations to bridge this gap. The tools also struggle with more complex CUDA applications, in particular, those that use templates, classes, or other C++ features inside the kernel. -What hardware does HIP support? -=============================== - -* For AMD platforms, see the :doc:`ROCm documentation `_ for the list of supported platforms. -* For NVIDIA platforms, HIP requires unified memory and should run on any device supporting CUDA SDK 6.0 or newer. We have tested the NVIDIA Titan and Tesla K40. - Do HIPIFY tools automatically convert all source code? -====================================================== +------------------------------------------------------ -Typically, HIPIFY tools can automatically convert almost all run-time code. +Typically, `HIPIFY `_ tools can automatically convert almost all run-time code. Most device code needs no additional conversion since HIP and CUDA have similar names for math and built-in functions. The hipify-clang tool will automatically modify the kernel signature as needed (automating a step that used to be done manually). Additional porting may be required to deal with architecture feature queries or with CUDA capabilities that HIP doesn't support. In general, developers should always expect to perform some platform-specific tuning and optimization. +Can I install both CUDA SDK and HIP-Clang on the same machine? +-------------------------------------------------------------- + +Yes. You can use HIP_PLATFORM to choose which path hipcc targets. This configuration can be useful when using HIP to develop an application which is portable to both AMD and NVIDIA. + +HIP detected my platform (HIP-Clang vs NVCC) incorrectly * what should I do? +---------------------------------------------------------------------------- + +HIP will set the platform to AMD and use HIP-Clang as compiler if it sees that the AMD graphics driver is installed and has detected an AMD GPU. +Sometimes this isn't what you want * you can force HIP to recognize the platform by setting the following, + +.. code-block:: shell + + export HIP_PLATFORM=amd + +HIP then set and use correct AMD compiler and runtime, +HIP_COMPILER=clang +HIP_RUNTIME=rocclr + +To choose NVIDIA platform, you can set, + +.. code-block:: shell + + export HIP_PLATFORM=nvidia + +In this case, HIP will set and use the following, + +.. code-block:: shell + + HIP_COMPILER=cuda + HIP_RUNTIME=nvcc + +One symptom of this problem is the message "error: 'unknown error'(11) at ``square.hipref.cpp:56``. This can occur if you have a CUDA installation on an AMD platform, and HIP incorrectly detects the platform as NVCC. HIP may be able to compile the application using the NVCC tool-chain but will generate this error at runtime since the platform does not have a CUDA device. + +On CUDA, can I mix CUDA code with HIP code? +------------------------------------------- + +Yes. Most HIP data structures (``hipStream_t``, ``hipEvent_t``) are typedefs to CUDA equivalents and can be intermixed. Both CUDA and HIP use integer device ids. +One notable exception is that ``hipError_t`` is a new type, and cannot be used where a ``cudaError_t`` is expected. In these cases, refactor the code to remove the expectation. Alternatively, hip_runtime_api.h defines functions which convert between the error code spaces: + +``hipErrorToCudaError`` +``hipCUDAErrorTohipError`` +``hipCUResultTohipError`` + +If platform portability is important, use ``#ifdef __HIP_PLATFORM_NVIDIA__`` to guard the CUDA-specific code. + +Hardware and platform +===================== + +What hardware does HIP support? +------------------------------- + +* For AMD platforms, see the :doc:`rocm-install-on-linux:reference/system-requirements` or :doc:`rocm-install-on-windows:reference/system-requirements` for the list of supported platforms. +* For NVIDIA platforms, HIP requires unified memory and should run on any device supporting CUDA SDK 6.0 or newer. We have tested the NVIDIA Titan and Tesla K40. + What is NVCC? -============= +------------- NVCC is NVIDIA's compiler driver for compiling "CUDA C++" code into PTX or device code for NVIDIA GPUs. It's a closed-source binary compiler that is provided by the CUDA SDK. What is HIP-Clang? -================== +------------------ HIP-Clang is a Clang/LLVM based compiler to compile HIP programs which can run on AMD platform. Why use HIP rather than supporting CUDA directly? -================================================= +------------------------------------------------- While HIP is a strong subset of the CUDA, it is a subset. The HIP layer allows that subset to be clearly defined and documented. Developers who code to the HIP API can be assured their code will remain portable across NVIDIA and AMD platforms. In addition, HIP defines portable mechanisms to query architectural features and supports a larger 64-bit ``WaveSize`` which expands the return type for cross-lane functions like ballot and shuffle from 32-bit integers to 64-bit integers. Can I develop HIP code on an NVIDIA CUDA platform? -================================================== +-------------------------------------------------- Yes. HIP's CUDA path only exposes the APIs and functionality that work on both NVCC and AMDGPU back-ends. "Extra" APIs, parameters, and features which exist in CUDA but not in HIP-Clang will typically result in compile-time or run-time errors. @@ -173,12 +306,12 @@ Developers concerned about portability should, of course, run on both platforms, In some cases, CUDA has a richer set of modes for some APIs, and some C++ capabilities such as virtual functions - see the HIP @API documentation for more details. Can I develop HIP code on an AMD HIP-Clang platform? -==================================================== +---------------------------------------------------- Yes. HIP's HIP-Clang path only exposes the APIs and functions that work on AMD runtime back ends. "Extra" APIs, parameters and features that appear in HIP-Clang but not CUDA will typically cause compile- or run-time errors. Developers must use the HIP API for most accelerator code and bracket any HIP-Clang specific code with preprocessor conditionals. Those concerned about portability should, of course, test their code on both platforms and should tune it for performance. Typically, HIP-Clang supports a more modern set of C++11/C++14/C++17 features, so HIP developers who want portability should be careful when using advanced C++ features on the HIP-Clang path. How to use HIP-Clang to build HIP programs? -=========================================== +------------------------------------------- The environment variable can be used to set compiler path: @@ -190,7 +323,7 @@ There is an alternative environment variable to set compiler path: NOTE: If HIP_ROCCLR_HOME is set, there is no need to set HIP_CLANG_PATH since hipcc will deduce them from HIP_ROCCLR_HOME. What is AMD clr? -================ +---------------- AMD `Common Language Runtime (CLR) `_ is a repository for the AMD platform, which contains source codes for AMD's compute languages runtimes as follows, @@ -199,156 +332,52 @@ AMD `Common Language Runtime (CLR) `_ is a reposito * opencl - contains implementation of OpenCLâ„¢ on the AMD platform. What is hipother? -================= +----------------- A new repository `'hipother' `_ is added in the ROCm 6.1 release, which is branched out from HIP. hipother supports the HIP back-end implementation on some non-AMD platforms, like NVIDIA. -Can I get HIP open source repository for Windows? -================================================= - -No, there is no HIP repository open publicly on Windows. - Can a HIP binary run on both AMD and NVIDIA platforms? -====================================================== +------------------------------------------------------ HIP is a source-portable language that can be compiled to run on either AMD or NVIDIA platform. HIP tools don't create a "fat binary" that can run on either platform, however. -On HIP-Clang, can I link HIP code with host code compiled with another compiler such as gcc, icc, or clang? -=========================================================================================================== - -Yes. HIP generates the object code which conforms to the GCC ABI, and also links with libstdc++. This means you can compile host code with the compiler of your choice and link the generated object code -with GPU code compiled with HIP. Larger projects often contain a mixture of accelerator code (initially written in CUDA with NVCC) and host code (compiled with gcc, icc, or clang). These projects -can convert the accelerator code to HIP, compile that code with hipcc, and link with object code from their preferred compiler. - -Can HIP API support C style application? What is the difference between C and C++? -================================================================================== - -HIP is C++ runtime API that supports C style applications as well. - -Some C style applications (and interfaces to other languages (FORTRAN, Python)) would call certain HIP APIs but not use kernel programming. -They can be compiled with a C compiler and run correctly, however, small details must be considered in the code. For example, initialization, as shown in the simple application below, uses HIP structs dim3 with the file name "test.hip.cpp" - -.. code-block:: cpp - - #include "hip/hip_runtime_api.h" - #include "stdio.h" - - int main(int argc, char** argv) { - dim3 grid1; - printf("dim3 grid1; x=%d, y=%d, z=%d\n",grid1.x,grid1.y,grid1.z); - dim3 grid2 = {1,1,1}; - printf("dim3 grid2 = {1,1,1}; x=%d, y=%d, z=%d\n",grid2.x,grid2.y,grid2.z); - return 0; - } - -When using a C++ compiler, - -.. code-block:: shell - - $ gcc -x c++ $(hipconfig --cpp_config) test3.hip.cpp -o test - $ ./test - dim3 grid1; x=1, y=1, z=1 - dim3 grid2 = {1,1,1}; x=1, y=1, z=1 - -In which "dim3 grid1;" will yield a dim3 grid with all dimensional members x,y,z initialized to 1, as the default constructor behaves that way. -Further, if written: - -.. code-block:: cpp - - dim3 grid(2); // yields {2,1,1} - dim3 grid(2,3); yields {2,3,1} - -In comparison, when using the C compiler, - -.. code-block:: shell - - $ gcc -x c $(hipconfig --cpp_config) test.hip.cpp -o test - $ ./test - dim3 grid1; x=646881376, y=21975, z=1517277280 - dim3 grid2 = {1,1,1}; x=1, y=1, z=1 - -In which "dim3 grid;" does not imply any initialization, no constructor is called, and dimensional values x,y,z of grid are undefined. -NOTE: To get the C++ default behavior, C programmers must additionally specify the right-hand side as shown below, - -.. code-block:: cpp - - dim3 grid = {1,1,1}; // initialized as in C++ - -Can I install both CUDA SDK and HIP-Clang on the same machine? -============================================================== - -Yes. You can use HIP_PLATFORM to choose which path hipcc targets. This configuration can be useful when using HIP to develop an application which is portable to both AMD and NVIDIA. - -HIP detected my platform (HIP-Clang vs NVCC) incorrectly * what should I do? -============================================================================ - -HIP will set the platform to AMD and use HIP-Clang as compiler if it sees that the AMD graphics driver is installed and has detected an AMD GPU. -Sometimes this isn't what you want * you can force HIP to recognize the platform by setting the following, - -.. code-block:: shell - - export HIP_PLATFORM=amd - -HIP then set and use correct AMD compiler and runtime, -HIP_COMPILER=clang -HIP_RUNTIME=rocclr - -To choose NVIDIA platform, you can set, - -.. code-block:: shell - - export HIP_PLATFORM=nvidia - -In this case, HIP will set and use the following, - -.. code-block:: shell - - HIP_COMPILER=cuda - HIP_RUNTIME=nvcc - -One symptom of this problem is the message "error: 'unknown error'(11) at ``square.hipref.cpp:56``. This can occur if you have a CUDA installation on an AMD platform, and HIP incorrectly detects the platform as NVCC. HIP may be able to compile the application using the NVCC tool-chain but will generate this error at runtime since the platform does not have a CUDA device. - -On CUDA, can I mix CUDA code with HIP code? -=========================================== - -Yes. Most HIP data structures (``hipStream_t``, ``hipEvent_t``) are typedefs to CUDA equivalents and can be intermixed. Both CUDA and HIP use integer device ids. -One notable exception is that ``hipError_t`` is a new type, and cannot be used where a ``cudaError_t`` is expected. In these cases, refactor the code to remove the expectation. Alternatively, hip_runtime_api.h defines functions which convert between the error code spaces: +Can I get HIP open source repository for Windows? +------------------------------------------------- -``hipErrorToCudaError`` -``hipCUDAErrorTohipError`` -``hipCUResultTohipError`` +No, there is no HIP repository open publicly on Windows. -If platform portability is important, use ``#ifdef __HIP_PLATFORM_NVIDIA__`` to guard the CUDA-specific code. +Miscellaneous +============= How do I trace HIP application flow? -==================================== +------------------------------------ See :doc:`/how-to/logging` for more information. What are the maximum limits of kernel launch parameters? -======================================================== +-------------------------------------------------------- Product of block.x, block.y, and block.z should be less than 1024. Please note, HIP does not support kernel launch with total work items defined in dimension with size ``gridDim x blockDim >= 2^32``, so ``gridDim.x * blockDim.x, gridDim.y * blockDim.y and gridDim.z * blockDim.z`` are always less than 2^32. Are ``__shfl_*_sync`` functions supported on HIP platform? -========================================================== +---------------------------------------------------------- ``__shfl_*_sync`` is not supported on HIP but for NVCC path CUDA 9.0 and above all shuffle calls get redirected to it's sync version. How to create a guard for code that is specific to the host or the GPU? -======================================================================= +----------------------------------------------------------------------= The compiler defines the ``__HIP_DEVICE_COMPILE__`` macro only when compiling the code for the GPU. It could be used to guard code that is specific to the host or the GPU. Why _OpenMP is undefined when compiling with ``-fopenmp``? -======================================================== +-------------------------------------------------------- When compiling an OpenMP source file with ``hipcc -fopenmp``, the compiler may generate error if there is a reference to the ``_OPENMP`` macro. This is due to a limitation in hipcc that treats any source file type (for example ``.cpp``) as an HIP translation unit leading to some conflicts with the OpenMP language switch. If the OpenMP source file doesn't contain any HIP language constructs you could work around this issue by adding the ``-x c++`` switch to force the compiler to treat the file as regular C++. Another approach would be to guard the OpenMP code with ``#ifdef _OPENMP`` so that the code block is disabled when compiling for the GPU. The ``__HIP_DEVICE_COMPILE__`` macro defined by the HIP compiler when compiling GPU code could also be used for guarding code paths specific to the host or the GPU. Does the HIP-Clang compiler support extern shared declarations? -=============================================================== +--------------------------------------------------------------- Previously, it was essential to declare dynamic shared memory using the HIP_DYNAMIC_SHARED macro for accuracy, as using static shared memory in the same kernel could result in overlapping memory ranges and data-races. @@ -356,7 +385,7 @@ Now, the HIP-Clang compiler provides support for extern shared declarations, and extern __shared__ type var[]; I have multiple HIP enabled devices and I am getting an error code ``hipErrorSharedObjectInitFailed`` with the message "Error: shared object initialization failed"? -================================================================================================================================================================== +------------------------------------------------------------------------------------------------------------------------------------------------------------------ This error message is seen due to the fact that you do not have valid code object for all of your devices. @@ -371,7 +400,7 @@ Note: In previous releases, the error code is ``hipErrorNoBinaryForGpu`` with me The error code handling behavior is changed. HIP runtime shows the error code ``hipErrorSharedObjectInitFailed`` with message "Error: shared object initialization failed" on unsupported GPU. How to use per-thread default stream in HIP? -============================================ +-------------------------------------------- The per-thread default stream is an implicit stream local to both the thread and the current device. It does not do any implicit synchronization with other streams (like explicitly created streams), or default per-thread stream on other threads. @@ -384,7 +413,7 @@ Once source is compiled with per-thread default stream enabled, all APIs will be Besides, per-thread default stream be enabled per translation unit, users can compile some files with feature enabled and some with feature disabled. Feature enabled translation unit will have default stream as per thread and there will not be any implicit synchronization done but other modules will have legacy default stream which will do implicit synchronization. How to use complex multiplication and division operations? -========================================================== +---------------------------------------------------------- In HIP, ``hipFloatComplex`` and ``hipDoubleComplex`` are defined as complex data types, @@ -401,13 +430,13 @@ Any application uses complex multiplication and division operations, need to rep Note: These complex operations are equivalent to corresponding types/functions on the NVIDIA platform. Can I develop applications with HIP APIs on Windows the same on Linux? -====================================================================== +---------------------------------------------------------------------- Yes, HIP APIs are available to use on both Linux and Windows. Due to different working mechanisms on operating systems like Windows vs Linux, HIP APIs call corresponding lower level backend runtime libraries and kernel drivers for the OS, in order to control the executions on GPU hardware accordingly. There might be a few differences on the related backend software and driver support, which might affect usage of HIP APIs. See OS support details in HIP API document. Does HIP support LUID? -====================== +---------------------- Starting ROCm 6.0, HIP runtime supports Locally Unique Identifier (LUID). This feature enables the local physical device(s) to interoperate with other devices. For example, DirectX 12. @@ -417,7 +446,7 @@ HIP runtime sets device LUID properties so the driver can query LUID to identify Note: HIP supports LUID only on Windows OS. How can I know the version of HIP? -================================== +---------------------------------- HIP version definition has been updated since ROCm 4.2 release as the following: