Add 'projects/hip/' from commit 'e74b05a7bd9454b97dc04d7cc4b66d1fe6c534a7'
git-subtree-dir: projects/hip git-subtree-mainline:64df0940b8git-subtree-split:e74b05a7bd
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
.. meta::
|
||||
:description: Maps CUDA API syntax to HIP API syntax with an example
|
||||
:keywords: AMD, ROCm, HIP, CUDA, syntax, HIP syntax
|
||||
|
||||
********************************************************************************
|
||||
CUDA to HIP API Function Comparison
|
||||
********************************************************************************
|
||||
|
||||
This page introduces key syntax differences between CUDA and HIP APIs with a focused code
|
||||
example and comparison table. For a complete list of mappings, visit :ref:`HIPIFY <HIPIFY:index>`.
|
||||
|
||||
The following CUDA code example illustrates several CUDA API syntaxes.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
__global__ void block_reduction(const float* input, float* output, int num_elements)
|
||||
{
|
||||
extern __shared__ float s_data[];
|
||||
|
||||
int tid = threadIdx.x;
|
||||
int global_id = blockDim.x * blockIdx.x + tid;
|
||||
|
||||
if (global_id < num_elements)
|
||||
{
|
||||
s_data[tid] = input[global_id];
|
||||
}
|
||||
else
|
||||
{
|
||||
s_data[tid] = 0.0f;
|
||||
}
|
||||
__syncthreads();
|
||||
|
||||
for (int stride = blockDim.x / 2; stride > 0; stride >>= 1)
|
||||
{
|
||||
if (tid < stride)
|
||||
{
|
||||
s_data[tid] += s_data[tid + stride];
|
||||
}
|
||||
__syncthreads();
|
||||
}
|
||||
|
||||
if (tid == 0)
|
||||
{
|
||||
output[blockIdx.x] = s_data[0];
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int threads = 256;
|
||||
const int num_elements = 50000;
|
||||
|
||||
std::vector<float> h_a(num_elements);
|
||||
std::vector<float> h_b((num_elements + threads - 1) / threads);
|
||||
|
||||
for (int i = 0; i < num_elements; ++i)
|
||||
{
|
||||
h_a[i] = rand() / static_cast<float>(RAND_MAX);
|
||||
}
|
||||
|
||||
float *d_a, *d_b;
|
||||
cudaMalloc(&d_a, h_a.size() * sizeof(float));
|
||||
cudaMalloc(&d_b, h_b.size() * sizeof(float));
|
||||
|
||||
cudaStream_t stream;
|
||||
cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking);
|
||||
|
||||
cudaEvent_t start_event, stop_event;
|
||||
cudaEventCreate(&start_event);
|
||||
cudaEventCreate(&stop_event);
|
||||
|
||||
cudaMemcpyAsync(d_a, h_a.data(), h_a.size() * sizeof(float), cudaMemcpyHostToDevice, stream);
|
||||
|
||||
cudaEventRecord(start_event, stream);
|
||||
|
||||
int blocks = (num_elements + threads - 1) / threads;
|
||||
block_reduction<<<blocks, threads, threads * sizeof(float), stream>>>(d_a, d_b, num_elements);
|
||||
|
||||
cudaMemcpyAsync(h_b.data(), d_b, h_b.size() * sizeof(float), cudaMemcpyDeviceToHost, stream);
|
||||
|
||||
cudaEventRecord(stop_event, stream);
|
||||
cudaEventSynchronize(stop_event);
|
||||
|
||||
cudaEventElapsedTime(&milliseconds, start_event, stop_event);
|
||||
std::cout << "Kernel execution time: " << milliseconds << " ms\n";
|
||||
|
||||
cudaFree(d_a);
|
||||
cudaFree(d_b);
|
||||
|
||||
cudaEventDestroy(start_event);
|
||||
cudaEventDestroy(stop_event);
|
||||
cudaStreamDestroy(stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
The following table maps CUDA API functions to corresponding HIP API functions, as demonstrated in the
|
||||
preceding code examples.
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:name: syntax-mapping-table
|
||||
|
||||
*
|
||||
- CUDA
|
||||
- HIP
|
||||
|
||||
*
|
||||
- ``#include <cuda_runtime.h>``
|
||||
- ``#include <hip/hip_runtime.h>``
|
||||
|
||||
*
|
||||
- ``cudaError_t``
|
||||
- ``hipError_t``
|
||||
|
||||
*
|
||||
- ``cudaEvent_t``
|
||||
- ``hipEvent_t``
|
||||
|
||||
*
|
||||
- ``cudaStream_t``
|
||||
- ``hipStream_t``
|
||||
|
||||
*
|
||||
- ``cudaMalloc``
|
||||
- ``hipMalloc``
|
||||
|
||||
*
|
||||
- ``cudaStreamCreateWithFlags``
|
||||
- ``hipStreamCreateWithFlags``
|
||||
|
||||
*
|
||||
- ``cudaStreamNonBlocking``
|
||||
- ``hipStreamNonBlocking``
|
||||
|
||||
*
|
||||
- ``cudaEventCreate``
|
||||
- ``hipEventCreate``
|
||||
|
||||
*
|
||||
- ``cudaMemcpyAsync``
|
||||
- ``hipMemcpyAsync``
|
||||
|
||||
*
|
||||
- ``cudaMemcpyHostToDevice``
|
||||
- ``hipMemcpyHostToDevice``
|
||||
|
||||
*
|
||||
- ``cudaEventRecord``
|
||||
- ``hipEventRecord``
|
||||
|
||||
*
|
||||
- ``cudaEventSynchronize``
|
||||
- ``hipEventSynchronize``
|
||||
|
||||
*
|
||||
- ``cudaEventElapsedTime``
|
||||
- ``hipEventElapsedTime``
|
||||
|
||||
*
|
||||
- ``cudaFree``
|
||||
- ``hipFree``
|
||||
|
||||
*
|
||||
- ``cudaEventDestroy``
|
||||
- ``hipEventDestroy``
|
||||
|
||||
*
|
||||
- ``cudaStreamDestroy``
|
||||
- ``hipStreamDestroy``
|
||||
|
||||
In summary, this comparison highlights the primary differences between CUDA and HIP APIs.
|
||||
@@ -0,0 +1,446 @@
|
||||
.. meta::
|
||||
:description: This chapter describes the complex math functions that are accessible in HIP.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, complex math functions, HIP complex math functions
|
||||
|
||||
.. _complex_math_api_reference:
|
||||
|
||||
********************************************************************************
|
||||
HIP complex math API
|
||||
********************************************************************************
|
||||
|
||||
HIP provides built-in support for complex number operations through specialized types and functions,
|
||||
available for both single-precision (float) and double-precision (double) calculations. All complex types
|
||||
and functions are available on both host and device.
|
||||
|
||||
For any complex number ``z``, the form is:
|
||||
|
||||
.. math::
|
||||
|
||||
z = x + yi
|
||||
|
||||
where ``x`` is the real part and ``y`` is the imaginary part.
|
||||
|
||||
Complex Number Types
|
||||
====================
|
||||
|
||||
A brief overview of the specialized data types used to represent complex numbers in HIP, available
|
||||
in both single and double precision formats.
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 40 60
|
||||
|
||||
* - Type
|
||||
- Description
|
||||
|
||||
* - ``hipFloatComplex``
|
||||
- | Complex number using single-precision (float) values
|
||||
| (note: ``hipComplex`` is an alias of ``hipFloatComplex``)
|
||||
|
||||
* - ``hipDoubleComplex``
|
||||
- Complex number using double-precision (double) values
|
||||
|
||||
Complex Number Functions
|
||||
========================
|
||||
|
||||
A comprehensive collection of functions for creating and manipulating complex numbers, organized by
|
||||
functional categories for easy reference.
|
||||
|
||||
Type Construction
|
||||
-----------------
|
||||
|
||||
Functions for creating complex number objects and extracting their real and imaginary components.
|
||||
|
||||
.. tab-set::
|
||||
|
||||
.. tab-item:: Single Precision
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 40 60
|
||||
|
||||
* - Function
|
||||
- Description
|
||||
|
||||
* - | ``hipFloatComplex``
|
||||
| ``make_hipFloatComplex(``
|
||||
| ``float a,``
|
||||
| ``float b``
|
||||
| ``)``
|
||||
- | Creates a complex number
|
||||
| (note: ``make_hipComplex`` is an alias of ``make_hipFloatComplex``)
|
||||
| :math:`z = a + bi`
|
||||
|
||||
* - | ``float``
|
||||
| ``hipCrealf(``
|
||||
| ``hipFloatComplex z``
|
||||
| ``)``
|
||||
- | Returns real part of z
|
||||
| :math:`\Re(z) = x`
|
||||
|
||||
* - | ``float``
|
||||
| ``hipCimagf(``
|
||||
| ``hipFloatComplex z``
|
||||
| ``)``
|
||||
- | Returns imaginary part of z
|
||||
| :math:`\Im(z) = y`
|
||||
|
||||
.. tab-item:: Double Precision
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 40 60
|
||||
|
||||
* - Function
|
||||
- Description
|
||||
|
||||
* - | ``hipDoubleComplex``
|
||||
| ``make_hipDoubleComplex(``
|
||||
| ``double a,``
|
||||
| ``double b``
|
||||
| ``)``
|
||||
- | Creates a complex number
|
||||
| :math:`z = a + bi`
|
||||
|
||||
* - | ``double``
|
||||
| ``hipCreal(``
|
||||
| ``hipDoubleComplex z``
|
||||
| ``)``
|
||||
- | Returns real part of z
|
||||
| :math:`\Re(z) = x`
|
||||
|
||||
* - | ``double``
|
||||
| ``hipCimag(``
|
||||
| ``hipDoubleComplex z``
|
||||
| ``)``
|
||||
- | Returns imaginary part of z
|
||||
| :math:`\Im(z) = y`
|
||||
|
||||
Basic Arithmetic
|
||||
----------------
|
||||
|
||||
Operations for performing standard arithmetic with complex numbers, including addition,
|
||||
subtraction, multiplication, division, and fused multiply-add.
|
||||
|
||||
.. tab-set::
|
||||
|
||||
.. tab-item:: Single Precision
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 40 60
|
||||
|
||||
* - Function
|
||||
- Description
|
||||
|
||||
* - | ``hipFloatComplex``
|
||||
| ``hipCaddf(``
|
||||
| ``hipFloatComplex p,``
|
||||
| ``hipFloatComplex q``
|
||||
| ``)``
|
||||
- | Addition of two single-precision complex values
|
||||
| :math:`(a + bi) + (c + di) = (a + c) + (b + d)i`
|
||||
|
||||
* - | ``hipFloatComplex``
|
||||
| ``hipCsubf(``
|
||||
| ``hipFloatComplex p,``
|
||||
| ``hipFloatComplex q``
|
||||
| ``)``
|
||||
- | Subtraction of two single-precision complex values
|
||||
| :math:`(a + bi) - (c + di) = (a - c) + (b - d)i`
|
||||
|
||||
* - | ``hipFloatComplex``
|
||||
| ``hipCmulf(``
|
||||
| ``hipFloatComplex p,``
|
||||
| ``hipFloatComplex q``
|
||||
| ``)``
|
||||
- | Multiplication of two single-precision complex values
|
||||
| :math:`(a + bi)(c + di) = (ac - bd) + (bc + ad)i`
|
||||
|
||||
* - | ``hipFloatComplex``
|
||||
| ``hipCdivf(``
|
||||
| ``hipFloatComplex p,``
|
||||
| ``hipFloatComplex q``
|
||||
| ``)``
|
||||
- | Division of two single-precision complex values
|
||||
| :math:`\frac{a + bi}{c + di} = \frac{(ac + bd) + (bc - ad)i}{c^2 + d^2}`
|
||||
|
||||
* - | ``hipFloatComplex``
|
||||
| ``hipCfmaf(``
|
||||
| ``hipComplex p,``
|
||||
| ``hipComplex q,``
|
||||
| ``hipComplex r``
|
||||
| ``)``
|
||||
- | Fused multiply-add of three single-precision complex values
|
||||
| :math:`(a + bi)(c + di) + (e + fi)`
|
||||
|
||||
.. tab-item:: Double Precision
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 40 60
|
||||
|
||||
* - Function
|
||||
- Description
|
||||
|
||||
* - | ``hipDoubleComplex``
|
||||
| ``hipCadd(``
|
||||
| ``hipDoubleComplex p,``
|
||||
| ``hipDoubleComplex q``
|
||||
| ``)``
|
||||
- | Addition of two double-precision complex values
|
||||
| :math:`(a + bi) + (c + di) = (a + c) + (b + d)i`
|
||||
|
||||
* - | ``hipDoubleComplex``
|
||||
| ``hipCsub(``
|
||||
| ``hipDoubleComplex p,``
|
||||
| ``hipDoubleComplex q``
|
||||
| ``)``
|
||||
- | Subtraction of two double-precision complex values
|
||||
| :math:`(a + bi) - (c + di) = (a - c) + (b - d)i`
|
||||
|
||||
* - | ``hipDoubleComplex``
|
||||
| ``hipCmul(``
|
||||
| ``hipDoubleComplex p,``
|
||||
| ``hipDoubleComplex q``
|
||||
| ``)``
|
||||
- | Multiplication of two double-precision complex values
|
||||
| :math:`(a + bi)(c + di) = (ac - bd) + (bc + ad)i`
|
||||
|
||||
* - | ``hipDoubleComplex``
|
||||
| ``hipCdiv(``
|
||||
| ``hipDoubleComplex p,``
|
||||
| ``hipDoubleComplex q``
|
||||
| ``)``
|
||||
- | Division of two double-precision complex values
|
||||
| :math:`\frac{a + bi}{c + di} = \frac{(ac + bd) + (bc - ad)i}{c^2 + d^2}`
|
||||
|
||||
* - | ``hipDoubleComplex``
|
||||
| ``hipCfma(``
|
||||
| ``hipDoubleComplex p,``
|
||||
| ``hipDoubleComplex q,``
|
||||
| ``hipDoubleComplex r``
|
||||
| ``)``
|
||||
- | Fused multiply-add of three double-precision complex values
|
||||
| :math:`(a + bi)(c + di) + (e + fi)`
|
||||
|
||||
Complex Operations
|
||||
------------------
|
||||
|
||||
Functions for complex-specific calculations, including conjugate determination and magnitude
|
||||
(absolute value) computation.
|
||||
|
||||
.. tab-set::
|
||||
|
||||
.. tab-item:: Single Precision
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 40 60
|
||||
|
||||
* - Function
|
||||
- Description
|
||||
|
||||
* - | ``hipFloatComplex``
|
||||
| ``hipConjf(``
|
||||
| ``hipFloatComplex z``
|
||||
| ``)``
|
||||
- | Complex conjugate
|
||||
| :math:`\overline{a + bi} = a - bi`
|
||||
|
||||
* - | ``float``
|
||||
| ``hipCabsf(``
|
||||
| ``hipFloatComplex z``
|
||||
| ``)``
|
||||
- | Absolute value (magnitude)
|
||||
| :math:`|a + bi| = \sqrt{a^2 + b^2}`
|
||||
|
||||
* - | ``float``
|
||||
| ``hipCsqabsf(``
|
||||
| ``hipFloatComplex z``
|
||||
| ``)``
|
||||
- | Squared absolute value
|
||||
| :math:`|a + bi|^2 = a^2 + b^2`
|
||||
|
||||
.. tab-item:: Double Precision
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 40 60
|
||||
|
||||
* - Function
|
||||
- Description
|
||||
|
||||
* - | ``hipDoubleComplex``
|
||||
| ``hipConj(``
|
||||
| ``hipDoubleComplex z``
|
||||
| ``)``
|
||||
- | Complex conjugate
|
||||
| :math:`\overline{a + bi} = a - bi`
|
||||
|
||||
* - | ``double``
|
||||
| ``hipCabs(``
|
||||
| ``hipDoubleComplex z``
|
||||
| ``)``
|
||||
- | Absolute value (magnitude)
|
||||
| :math:`|a + bi| = \sqrt{a^2 + b^2}`
|
||||
|
||||
* - | ``double``
|
||||
| ``hipCsqabs(``
|
||||
| ``hipDoubleComplex z``
|
||||
| ``)``
|
||||
- | Squared absolute value
|
||||
| :math:`|a + bi|^2 = a^2 + b^2`
|
||||
|
||||
Type Conversion
|
||||
---------------
|
||||
|
||||
Utility functions for conversion between single-precision and double-precision complex number formats.
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 40 60
|
||||
|
||||
* - Function
|
||||
- Description
|
||||
|
||||
* - | ``hipFloatComplex``
|
||||
| ``hipComplexDoubleToFloat(``
|
||||
| ``hipDoubleComplex z``
|
||||
| ``)``
|
||||
- Converts double-precision to single-precision complex
|
||||
|
||||
* - | ``hipDoubleComplex``
|
||||
| ``hipComplexFloatToDouble(``
|
||||
| ``hipFloatComplex z``
|
||||
| ``)``
|
||||
- Converts single-precision to double-precision complex
|
||||
|
||||
Example Usage
|
||||
=============
|
||||
|
||||
The following example demonstrates using complex numbers to compute the Discrete Fourier Transform (DFT)
|
||||
of a simple signal on the GPU. The DFT converts a signal from the time domain to the frequency domain.
|
||||
The kernel function ``computeDFT`` shows various HIP complex math operations in action:
|
||||
|
||||
* Creating complex numbers with ``make_hipFloatComplex``
|
||||
* Performing complex multiplication with ``hipCmulf``
|
||||
* Accumulating complex values with ``hipCaddf``
|
||||
|
||||
The example also demonstrates proper use of complex number handling on both host and device, including
|
||||
memory allocation, transfer, and validation of results between CPU and GPU implementations.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_complex.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
#define HIP_CHECK(expression) \
|
||||
{ \
|
||||
const hipError_t err = expression; \
|
||||
if (err != hipSuccess) { \
|
||||
std::cerr << "HIP error: " \
|
||||
<< hipGetErrorString(err) \
|
||||
<< " at " << __LINE__ << "\n"; \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
}
|
||||
|
||||
// Kernel to compute DFT
|
||||
__global__ void computeDFT(const float* input,
|
||||
hipFloatComplex* output,
|
||||
const int N)
|
||||
{
|
||||
int k = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (k >= N) return;
|
||||
|
||||
hipFloatComplex sum = make_hipFloatComplex(0.0f, 0.0f);
|
||||
|
||||
for (int n = 0; n < N; n++) {
|
||||
float angle = -2.0f * M_PI * k * n / N;
|
||||
hipFloatComplex w = make_hipFloatComplex(cosf(angle), sinf(angle));
|
||||
hipFloatComplex x = make_hipFloatComplex(input[n], 0.0f);
|
||||
sum = hipCaddf(sum, hipCmulf(x, w));
|
||||
}
|
||||
|
||||
output[k] = sum;
|
||||
}
|
||||
|
||||
// CPU implementation of DFT for verification
|
||||
std::vector<hipFloatComplex> cpuDFT(const std::vector<float>& input) {
|
||||
const int N = input.size();
|
||||
std::vector<hipFloatComplex> result(N);
|
||||
|
||||
for (int k = 0; k < N; k++) {
|
||||
hipFloatComplex sum = make_hipFloatComplex(0.0f, 0.0f);
|
||||
for (int n = 0; n < N; n++) {
|
||||
float angle = -2.0f * M_PI * k * n / N;
|
||||
hipFloatComplex w = make_hipFloatComplex(cosf(angle), sinf(angle));
|
||||
hipFloatComplex x = make_hipFloatComplex(input[n], 0.0f);
|
||||
sum = hipCaddf(sum, hipCmulf(x, w));
|
||||
}
|
||||
result[k] = sum;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const int N = 256; // Signal length
|
||||
const int blockSize = 256;
|
||||
|
||||
// Generate input signal: sum of two sine waves
|
||||
std::vector<float> signal(N);
|
||||
for (int i = 0; i < N; i++) {
|
||||
float t = static_cast<float>(i) / N;
|
||||
signal[i] = sinf(2.0f * M_PI * 10.0f * t) + // 10 Hz component
|
||||
0.5f * sinf(2.0f * M_PI * 20.0f * t); // 20 Hz component
|
||||
}
|
||||
|
||||
// Compute reference solution on CPU
|
||||
std::vector<hipFloatComplex> cpu_output = cpuDFT(signal);
|
||||
|
||||
// Allocate device memory
|
||||
float* d_signal;
|
||||
hipFloatComplex* d_output;
|
||||
HIP_CHECK(hipMalloc(&d_signal, N * sizeof(float)));
|
||||
HIP_CHECK(hipMalloc(&d_output, N * sizeof(hipFloatComplex)));
|
||||
|
||||
// Copy input to device
|
||||
HIP_CHECK(hipMemcpy(d_signal, signal.data(), N * sizeof(float),
|
||||
hipMemcpyHostToDevice));
|
||||
|
||||
// Launch kernel
|
||||
dim3 grid((N + blockSize - 1) / blockSize);
|
||||
dim3 block(blockSize);
|
||||
computeDFT<<<grid, block>>>(d_signal, d_output, N);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
|
||||
// Get GPU results
|
||||
std::vector<hipFloatComplex> gpu_output(N);
|
||||
HIP_CHECK(hipMemcpy(gpu_output.data(), d_output, N * sizeof(hipFloatComplex),
|
||||
hipMemcpyDeviceToHost));
|
||||
|
||||
// Verify results
|
||||
bool passed = true;
|
||||
const float tolerance = 1e-5f; // Adjust based on precision requirements
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
float diff_real = std::abs(hipCrealf(gpu_output[i]) - hipCrealf(cpu_output[i]));
|
||||
float diff_imag = std::abs(hipCimagf(gpu_output[i]) - hipCimagf(cpu_output[i]));
|
||||
|
||||
if (diff_real > tolerance || diff_imag > tolerance) {
|
||||
passed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "DFT Verification: " << (passed ? "PASSED" : "FAILED") << "\n";
|
||||
|
||||
// Cleanup
|
||||
HIP_CHECK(hipFree(d_signal));
|
||||
HIP_CHECK(hipFree(d_output));
|
||||
return passed ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
.. meta::
|
||||
:description: HIP deprecated runtime API functions.
|
||||
:keywords: AMD, ROCm, HIP, deprecated, API
|
||||
|
||||
**********************************************************************************************
|
||||
HIP deprecated runtime API functions
|
||||
**********************************************************************************************
|
||||
|
||||
Several of our API functions have been flagged for deprecation. Using the
|
||||
following functions results in errors and unexpected results, so we encourage
|
||||
you to update your code accordingly.
|
||||
|
||||
Deprecated since ROCm 6.1.0
|
||||
============================================================
|
||||
|
||||
Deprecated texture management functions.
|
||||
|
||||
.. list-table::
|
||||
:widths: 40
|
||||
:header-rows: 1
|
||||
:align: left
|
||||
|
||||
* - function
|
||||
* - :cpp:func:`hipTexRefGetBorderColor`
|
||||
* - :cpp:func:`hipTexRefGetArray`
|
||||
|
||||
Deprecated since ROCm 5.7.0
|
||||
============================================================
|
||||
|
||||
Deprecated texture management functions.
|
||||
|
||||
.. list-table::
|
||||
:widths: 40
|
||||
:header-rows: 1
|
||||
:align: left
|
||||
|
||||
* - function
|
||||
* - :cpp:func:`hipBindTextureToMipmappedArray`
|
||||
|
||||
Deprecated since ROCm 5.3.0
|
||||
============================================================
|
||||
|
||||
Deprecated texture management functions.
|
||||
|
||||
.. list-table::
|
||||
:widths: 40
|
||||
:header-rows: 1
|
||||
:align: left
|
||||
|
||||
* - function
|
||||
* - :cpp:func:`hipGetTextureReference`
|
||||
* - :cpp:func:`hipTexRefSetAddressMode`
|
||||
* - :cpp:func:`hipTexRefSetArray`
|
||||
* - :cpp:func:`hipTexRefSetFlags`
|
||||
* - :cpp:func:`hipTexRefSetFilterMode`
|
||||
* - :cpp:func:`hipTexRefSetFormat`
|
||||
* - :cpp:func:`hipTexRefSetMipmapFilterMode`
|
||||
* - :cpp:func:`hipTexRefSetMipmapLevelBias`
|
||||
* - :cpp:func:`hipTexRefSetMipmapLevelClamp`
|
||||
* - :cpp:func:`hipTexRefSetMipmappedArray`
|
||||
|
||||
Deprecated since ROCm 4.3.0
|
||||
============================================================
|
||||
|
||||
Deprecated texture management functions.
|
||||
|
||||
.. list-table::
|
||||
:widths: 40
|
||||
:header-rows: 1
|
||||
:align: left
|
||||
|
||||
* - function
|
||||
* - :cpp:func:`hipTexRefGetAddress`
|
||||
* - :cpp:func:`hipTexRefGetAddressMode`
|
||||
* - :cpp:func:`hipTexRefGetFilterMode`
|
||||
* - :cpp:func:`hipTexRefGetFlags`
|
||||
* - :cpp:func:`hipTexRefGetFormat`
|
||||
* - :cpp:func:`hipTexRefGetMaxAnisotropy`
|
||||
* - :cpp:func:`hipTexRefGetMipmapFilterMode`
|
||||
* - :cpp:func:`hipTexRefGetMipmapLevelBias`
|
||||
* - :cpp:func:`hipTexRefGetMipmapLevelClamp`
|
||||
* - :cpp:func:`hipTexRefGetMipMappedArray`
|
||||
* - :cpp:func:`hipTexRefSetAddress`
|
||||
* - :cpp:func:`hipTexRefSetAddress2D`
|
||||
* - :cpp:func:`hipTexRefSetBorderColor`
|
||||
* - :cpp:func:`hipTexRefSetMaxAnisotropy`
|
||||
|
||||
Deprecated since ROCm 3.8.0
|
||||
============================================================
|
||||
|
||||
Deprecated memory management and texture management functions.
|
||||
|
||||
.. list-table::
|
||||
:widths: 40
|
||||
:header-rows: 1
|
||||
:align: left
|
||||
|
||||
* - function
|
||||
* - :cpp:func:`hipBindTexture`
|
||||
* - :cpp:func:`hipBindTexture2D`
|
||||
* - :cpp:func:`hipBindTextureToArray`
|
||||
* - :cpp:func:`hipGetTextureAlignmentOffset`
|
||||
* - :cpp:func:`hipUnbindTexture`
|
||||
* - :cpp:func:`hipMemcpyToArray`
|
||||
* - :cpp:func:`hipMemcpyFromArray`
|
||||
|
||||
Deprecated since ROCm 3.1.0
|
||||
============================================================
|
||||
|
||||
Deprecated memory management functions.
|
||||
|
||||
.. list-table::
|
||||
:widths: 40, 60
|
||||
:header-rows: 1
|
||||
:align: left
|
||||
|
||||
* - function
|
||||
-
|
||||
* - :cpp:func:`hipMallocHost`
|
||||
- replaced with :cpp:func:`hipHostAlloc`
|
||||
* - :cpp:func:`hipMemAllocHost`
|
||||
- replaced with :cpp:func:`hipHostAlloc`
|
||||
|
||||
Deprecated since ROCm 3.0.0
|
||||
============================================================
|
||||
|
||||
The ``hipProfilerStart`` and ``hipProfilerStop`` functions are deprecated.
|
||||
Instead, you can use ``roctracer`` or ``rocTX`` for profiling which provide more
|
||||
flexibility and detailed profiling capabilities.
|
||||
|
||||
.. list-table::
|
||||
:widths: 40
|
||||
:header-rows: 1
|
||||
:align: left
|
||||
|
||||
* - function
|
||||
* - :cpp:func:`hipProfilerStart`
|
||||
* - :cpp:func:`hipProfilerStop`
|
||||
|
||||
Deprecated since ROCm 1.9.0
|
||||
============================================================
|
||||
|
||||
CUDA supports cuCtx API, which is the driver API that defines "Context" and
|
||||
"Devices" as separate entities. Context contains a single device, and a device
|
||||
can theoretically have multiple contexts. HIP initially added limited support
|
||||
for context APIs in order to facilitate porting from existing driver codes. These
|
||||
APIs are now marked as deprecated because there are better alternate interfaces
|
||||
(such as ``hipSetDevice`` or the stream API) to achieve these functions.
|
||||
|
||||
.. list-table::
|
||||
:widths: 40
|
||||
:header-rows: 1
|
||||
:align: left
|
||||
|
||||
* - function
|
||||
* - :cpp:func:`hipCtxCreate`
|
||||
* - :cpp:func:`hipCtxDestroy`
|
||||
* - :cpp:func:`hipCtxPopCurrent`
|
||||
* - :cpp:func:`hipCtxPushCurrent`
|
||||
* - :cpp:func:`hipCtxSetCurrent`
|
||||
* - :cpp:func:`hipCtxGetCurrent`
|
||||
* - :cpp:func:`hipCtxGetDevice`
|
||||
* - :cpp:func:`hipCtxGetApiVersion`
|
||||
* - :cpp:func:`hipCtxGetCacheConfig`
|
||||
* - :cpp:func:`hipCtxSetCacheConfig`
|
||||
* - :cpp:func:`hipCtxSetSharedMemConfig`
|
||||
* - :cpp:func:`hipCtxGetSharedMemConfig`
|
||||
* - :cpp:func:`hipCtxSynchronize`
|
||||
* - :cpp:func:`hipCtxGetFlags`
|
||||
* - :cpp:func:`hipCtxEnablePeerAccess`
|
||||
* - :cpp:func:`hipCtxDisablePeerAccess`
|
||||
* - :cpp:func:`hipDevicePrimaryCtxGetState`
|
||||
* - :cpp:func:`hipDevicePrimaryCtxRelease`
|
||||
* - :cpp:func:`hipDevicePrimaryCtxRetain`
|
||||
* - :cpp:func:`hipDevicePrimaryCtxReset`
|
||||
* - :cpp:func:`hipDevicePrimaryCtxSetFlags`
|
||||
@@ -0,0 +1,55 @@
|
||||
.. meta::
|
||||
:description: HIP environment variables reference
|
||||
:keywords: AMD, HIP, environment variables, environment, reference
|
||||
|
||||
********************************************************************************
|
||||
HIP environment variables
|
||||
********************************************************************************
|
||||
|
||||
In this section, the reader can find all the important HIP environment variables
|
||||
on AMD platform, which are grouped by functionality.
|
||||
|
||||
GPU isolation variables
|
||||
================================================================================
|
||||
|
||||
The GPU isolation environment variables in HIP are collected in the following table.
|
||||
For more information, check :doc:`GPU isolation page <rocm:conceptual/gpu-isolation>`.
|
||||
|
||||
.. include-table:: data/env_variables_hip.rst
|
||||
:table: hip-env-isolation
|
||||
|
||||
Profiling variables
|
||||
================================================================================
|
||||
|
||||
The profiling environment variables in HIP are collected in the following table. For
|
||||
more information, check :doc:`setting the number of CUs page <rocm:how-to/setting-cus>`.
|
||||
|
||||
.. include-table:: data/env_variables_hip.rst
|
||||
:table: hip-env-prof
|
||||
|
||||
Debug variables
|
||||
================================================================================
|
||||
|
||||
The debugging environment variables in HIP are collected in the following table. For
|
||||
more information, check :ref:`debugging_with_hip`.
|
||||
|
||||
.. include-table:: data/env_variables_hip.rst
|
||||
:table: hip-env-debug
|
||||
|
||||
Memory management related variables
|
||||
================================================================================
|
||||
|
||||
The memory management related environment variables in HIP are collected in the
|
||||
following table.
|
||||
|
||||
.. include-table:: data/env_variables_hip.rst
|
||||
:table: hip-env-memory
|
||||
|
||||
Other useful variables
|
||||
================================================================================
|
||||
|
||||
The following table lists environment variables that are useful but relate to
|
||||
different features.
|
||||
|
||||
.. include-table:: data/env_variables_hip.rst
|
||||
:table: hip-env-other
|
||||
File diff ditekan karena terlalu besar
Load Diff
@@ -0,0 +1,249 @@
|
||||
.. meta::
|
||||
:description: This chapter describes the hardware features of the different hardware architectures.
|
||||
:keywords: AMD, ROCm, HIP, hardware, hardware features, hardware architectures
|
||||
|
||||
*******************************************************************************
|
||||
Hardware features
|
||||
*******************************************************************************
|
||||
|
||||
This page gives an overview of the different hardware architectures and the
|
||||
features they implement. Hardware features do not imply performance, that
|
||||
depends on the specifications found in the :doc:`rocm:reference/gpu-arch-specs`
|
||||
page.
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:name: hardware-features-table
|
||||
|
||||
*
|
||||
- Hardware feature support
|
||||
- RDNA1
|
||||
- CDNA1
|
||||
- RDNA2
|
||||
- CDNA2
|
||||
- RDNA3
|
||||
- CDNA3
|
||||
*
|
||||
- :ref:`atomic functions` on 32-bit integer values in global and shared memory
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- Atomic functions on 64-bit integer values in global and shared memory
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- Atomic addition on 32-bit floating point values in global and shared memory
|
||||
- ❌
|
||||
- ❌
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- Atomic addition on 64-bit floating point values in global memory and shared memory
|
||||
- ❌
|
||||
- ❌
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- :ref:`Warp vote functions <warp_vote_functions>`
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- :ref:`Memory fence instructions <memory_fence_instructions>`
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- :ref:`Synchronization functions <synchronization_functions>`
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- :ref:`Surface functions <surface_object_reference>`
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- :ref:`float16 half precision IEEE-conformant floating-point operations<rocm:precision_support_floating_point_types>`
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- :ref:`bfloat16 16-bit floating-point operations<rocm:precision_support_floating_point_types>`
|
||||
- ❌
|
||||
- ✅
|
||||
- ❌
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- Support for :ref:`8-bit floating-point types <rocm:precision_support_floating_point_types>`
|
||||
- ❌
|
||||
- ❌
|
||||
- ❌
|
||||
- ❌
|
||||
- ❌
|
||||
- ✅
|
||||
*
|
||||
- Support for :ref:`tensor float32 <rocm:precision_support_floating_point_types>`
|
||||
- ❌
|
||||
- ❌
|
||||
- ❌
|
||||
- ❌
|
||||
- ❌
|
||||
- ✅
|
||||
*
|
||||
- Packed math with 16-bit floating point values
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- Packed math with 32-bit floating point values
|
||||
- ❌
|
||||
- ❌
|
||||
- ❌
|
||||
- ✅
|
||||
- ❌
|
||||
- ✅
|
||||
*
|
||||
- Matrix Cores
|
||||
- ❌
|
||||
- ✅
|
||||
- ❌
|
||||
- ✅
|
||||
- ❌
|
||||
- ✅
|
||||
*
|
||||
- On-Chip Error Correcting Code (ECC)
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
- ✅
|
||||
*
|
||||
- Maximum dimensionality of grid
|
||||
- 3
|
||||
- 3
|
||||
- 3
|
||||
- 3
|
||||
- 3
|
||||
- 3
|
||||
*
|
||||
- Maximum x-, y- and z-dimension of a grid
|
||||
- x - :math:`2^{32}-1` y - :math:`2^{16}-1` z - :math:`2^{16}-1`
|
||||
- x - :math:`2^{32}-1` y - :math:`2^{16}-1` z - :math:`2^{16}-1`
|
||||
- x - :math:`2^{32}-1` y - :math:`2^{16}-1` z - :math:`2^{16}-1`
|
||||
- x - :math:`2^{32}-1` y - :math:`2^{16}-1` z - :math:`2^{16}-1`
|
||||
- x - :math:`2^{32}-1` y - :math:`2^{16}-1` z - :math:`2^{16}-1`
|
||||
- x - :math:`2^{32}-1` y - :math:`2^{16}-1` z - :math:`2^{16}-1`
|
||||
*
|
||||
- Maximum number of threads per grid
|
||||
- :math:`2^{32} - 1`
|
||||
- :math:`2^{32} - 1`
|
||||
- :math:`2^{32} - 1`
|
||||
- :math:`2^{32} - 1`
|
||||
- :math:`2^{32} - 1`
|
||||
- :math:`2^{32} - 1`
|
||||
*
|
||||
- Maximum x-, y- and z-dimension of a block
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
*
|
||||
- Maximum number of threads per block
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
- :math:`1024`
|
||||
*
|
||||
- Wavefront size
|
||||
- 32 [1]_
|
||||
- 64
|
||||
- 32 [1]_
|
||||
- 64
|
||||
- 32 [1]_
|
||||
- 64
|
||||
*
|
||||
- Maximum number of resident blocks per compute unit
|
||||
- 40 [1]_
|
||||
- 32
|
||||
- 32 [1]_
|
||||
- 32
|
||||
- 32 [1]_
|
||||
- 32
|
||||
*
|
||||
- Maximum number of resident wavefronts per compute unit
|
||||
- 40 [1]_
|
||||
- 32
|
||||
- 32 [1]_
|
||||
- 32
|
||||
- 32 [1]_
|
||||
- 32
|
||||
*
|
||||
- Maximum number of resident threads per compute unit
|
||||
- 1280 [2]_
|
||||
- 2048
|
||||
- 1024 [2]_
|
||||
- 2048
|
||||
- 1024 [2]_
|
||||
- 2048
|
||||
*
|
||||
- Maximum number of 32-bit vector registers per thread
|
||||
- 256
|
||||
- 256 (vector) + 256 (matrix)
|
||||
- 256
|
||||
- 256 (vector) + 256 (matrix)
|
||||
- 256
|
||||
- 256 (vector) + 256 (matrix)
|
||||
*
|
||||
- Maximum number of 32-bit scalar accumulation registers per thread
|
||||
- 106
|
||||
- 104
|
||||
- 106
|
||||
- 104
|
||||
- 106
|
||||
- 104
|
||||
|
||||
.. [1] RDNA architectures have a configurable wavefront size. The native
|
||||
wavefront size is 32, but they can run in "CU mode", which has an effective
|
||||
wavefront size of 64. This affects the number of resident wavefronts and
|
||||
blocks per compute Unit.
|
||||
.. [2] RDNA architectures expand the concept of the traditional compute unit
|
||||
with the so-called work group processor, which effectively includes two
|
||||
compute units, within which all threads can cooperate.
|
||||
@@ -0,0 +1,15 @@
|
||||
.. meta::
|
||||
:description: The global defines, enum, structs and files reference page.
|
||||
|
||||
.. _global_defines_enums_structs_files_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Global defines, enums, structs and files
|
||||
*******************************************************************************
|
||||
|
||||
The structs, define macros, enums and files in the HIP runtime API.
|
||||
|
||||
* :ref:`global_enum_defines_reference`
|
||||
* :ref:`driver_types_reference`
|
||||
* :doc:`../../doxygen/html/annotated`
|
||||
* :doc:`../../doxygen/html/files`
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The driver types reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, driver types
|
||||
|
||||
.. _driver_types_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Driver types
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: DriverTypes
|
||||
:content-only:
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The global enum and defines reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, global enum, defines
|
||||
|
||||
.. _global_enum_defines_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Global enum and defines
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: GlobalDefs
|
||||
:content-only:
|
||||
@@ -0,0 +1,42 @@
|
||||
.. meta::
|
||||
:description: The HIP runtime API modules reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, HIP runtime API modules, modules
|
||||
|
||||
.. _modules_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Modules
|
||||
*******************************************************************************
|
||||
|
||||
The API is organized into modules based on functionality.
|
||||
|
||||
* :ref:`initialization_version_reference`
|
||||
* :ref:`device_management_reference`
|
||||
* :ref:`execution_control_reference`
|
||||
* :ref:`error_handling_reference`
|
||||
* :ref:`stream_management_reference`
|
||||
* :ref:`stream_memory_operations_reference`
|
||||
* :ref:`event_management_reference`
|
||||
* :ref:`memory_management_reference`
|
||||
|
||||
* :ref:`memory_management_deprecated_reference`
|
||||
* :ref:`external_resource_interoperability_reference`
|
||||
* :ref:`stream_ordered_memory_allocator_reference`
|
||||
* :ref:`unified_memory_reference`
|
||||
* :ref:`virtual_memory_reference`
|
||||
* :ref:`texture_management_reference`
|
||||
* :ref:`texture_management_deprecated_reference`
|
||||
* :ref:`surface_object_reference`
|
||||
|
||||
* :ref:`peer_to_peer_device_memory_access_reference`
|
||||
* :ref:`context_management_reference`
|
||||
* :ref:`module_management_reference`
|
||||
* :ref:`occupancy_reference`
|
||||
* :ref:`profiler_control_reference`
|
||||
* :ref:`launch_api_reference`
|
||||
* :ref:`runtime_compilation_reference`
|
||||
* :ref:`callback_activity_apis_reference`
|
||||
* :ref:`graph_management_reference`
|
||||
* :ref:`opengl_interoperability_reference`
|
||||
* :ref:`graphics_interoperability_reference`
|
||||
* :ref:`cooperative_groups_reference`
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The callback activity APIs reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, callback activity APIs, callback activity
|
||||
|
||||
.. _callback_activity_apis_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Callback activity APIs
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Callback
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The context management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, context management, context
|
||||
|
||||
.. _context_management_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Context management [deprecated]
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Context
|
||||
:content-only:
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
.. meta::
|
||||
:description: This chapter lists types and device API wrappers related to the
|
||||
Cooperative Group feature. Programmers can directly use these
|
||||
API features in their kernels.
|
||||
:keywords: AMD, ROCm, HIP, cooperative groups
|
||||
|
||||
.. _cooperative_groups_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Cooperative groups
|
||||
*******************************************************************************
|
||||
|
||||
Cooperative kernel launches
|
||||
===========================
|
||||
|
||||
The following host-side functions are used for cooperative kernel launches.
|
||||
|
||||
.. doxygengroup:: ModuleCooperativeG
|
||||
:content-only:
|
||||
|
||||
Cooperative groups classes
|
||||
==========================
|
||||
|
||||
The following cooperative groups classes can be used on the device side.
|
||||
|
||||
.. _thread_group_ref:
|
||||
|
||||
.. doxygenclass:: cooperative_groups::thread_group
|
||||
:members:
|
||||
|
||||
.. _thread_block_ref:
|
||||
|
||||
.. doxygenclass:: cooperative_groups::thread_block
|
||||
:members:
|
||||
|
||||
.. _grid_group_ref:
|
||||
|
||||
.. doxygenclass:: cooperative_groups::grid_group
|
||||
:members:
|
||||
|
||||
.. _multi_grid_group_ref:
|
||||
|
||||
.. doxygenclass:: cooperative_groups::multi_grid_group
|
||||
:members:
|
||||
|
||||
.. _thread_block_tile_ref:
|
||||
|
||||
.. doxygenclass:: cooperative_groups::thread_block_tile
|
||||
:members:
|
||||
|
||||
.. _coalesced_group_ref:
|
||||
|
||||
.. doxygenclass:: cooperative_groups::coalesced_group
|
||||
:members:
|
||||
|
||||
Cooperative groups construct functions
|
||||
======================================
|
||||
|
||||
The following functions are used to construct different group-type instances on the device side.
|
||||
|
||||
.. doxygengroup:: CooperativeGConstruct
|
||||
:content-only:
|
||||
|
||||
Cooperative groups exposed API functions
|
||||
========================================
|
||||
|
||||
The following functions are the exposed API for different group-type instances on the device side.
|
||||
|
||||
.. doxygengroup:: CooperativeGAPI
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The device management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, device management, device
|
||||
|
||||
.. _device_management_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Device management
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Device
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The error handling reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, error handling, error
|
||||
|
||||
.. _error_handling_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Error handling
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Error
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The event management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, event management, event
|
||||
|
||||
.. _event_management_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Event management
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Event
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The execution control reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, execution control, execution
|
||||
|
||||
.. _execution_control_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Execution control
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Execution
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The graph management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, graph management, graph
|
||||
|
||||
.. _graph_management_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Graph management
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Graph
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The Graphics interoperability reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, Graphics interoperability
|
||||
|
||||
.. _graphics_interoperability_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Graphics interoperability
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: GraphicsInterop
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The initialization and version reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, initialization, version
|
||||
|
||||
.. _initialization_version_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Initialization and version
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Driver
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The launch API reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, launch API, triple-chevron
|
||||
|
||||
.. _launch_api_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Launch API
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Clang
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The memory management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, memory management, memory
|
||||
|
||||
.. _memory_management_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Memory management
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Memory
|
||||
:content-only:
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The external resource interoperability reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, external resource interoperability
|
||||
|
||||
.. _external_resource_interoperability_reference:
|
||||
|
||||
*******************************************************************************
|
||||
External resource interoperability
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: External
|
||||
:content-only:
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
.. meta::
|
||||
:description: The deprecated memory management reference page.
|
||||
|
||||
.. _memory_management_deprecated_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Memory management (deprecated)
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: MemoryD
|
||||
:content-only:
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The stream ordered memory allocator reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, stream ordered memory allocator
|
||||
|
||||
.. _stream_ordered_memory_allocator_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Stream ordered memory allocator
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: StreamO
|
||||
:content-only:
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
.. meta::
|
||||
:description: The surface object reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, surface object, surface
|
||||
|
||||
.. _surface_object_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Surface object
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Surface
|
||||
:content-only:
|
||||
|
||||
.. doxygengroup:: SurfaceAPI
|
||||
:content-only:
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The texture management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, texture management, texture
|
||||
|
||||
.. _texture_management_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Texture management
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Texture
|
||||
:content-only:
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The deprecated texture management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, deprecated texture management
|
||||
|
||||
.. _texture_management_deprecated_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Texture management (deprecated)
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: TextureD
|
||||
:content-only:
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The managed memory reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, unified memory, unified, memory, UM, APU
|
||||
|
||||
.. _unified_memory_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Managed memory
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: MemoryM
|
||||
:content-only:
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The virtual memory (VM) management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, virtual memory, virtual, memory, VM
|
||||
|
||||
.. _virtual_memory_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Virtual memory management
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Virtual
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The module management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, module management, module
|
||||
|
||||
.. _module_management_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Module management
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Module
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The occupancy reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, occupancy
|
||||
|
||||
.. _occupancy_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Occupancy
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Occupancy
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The OpenGL interoperability reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, OpenGL interoperability, OpenGL interop
|
||||
|
||||
.. _opengl_interoperability_reference:
|
||||
|
||||
*******************************************************************************
|
||||
OpenGL interoperability
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: GL
|
||||
:content-only:
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The peer to peer device memory access reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, peer to peer device memory access, peer to peer
|
||||
|
||||
.. _peer_to_peer_device_memory_access_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Peer to peer device memory access
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: PeerToPeer
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The profiler control reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, profiler control, profiler
|
||||
|
||||
.. _profiler_control_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Profiler control
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Profiler
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The runtime compilation reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, runtime compilation
|
||||
|
||||
.. _runtime_compilation_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Runtime compilation
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Runtime
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The stream management reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, stream management, stream
|
||||
|
||||
.. _stream_management_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Stream management
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: Stream
|
||||
:content-only:
|
||||
@@ -0,0 +1,12 @@
|
||||
.. meta::
|
||||
:description: The stream memory operations reference page.
|
||||
:keywords: AMD, ROCm, HIP, CUDA, stream memory operations
|
||||
|
||||
.. _stream_memory_operations_reference:
|
||||
|
||||
*******************************************************************************
|
||||
Stream memory operations
|
||||
*******************************************************************************
|
||||
|
||||
.. doxygengroup:: StreamM
|
||||
:content-only:
|
||||
@@ -0,0 +1,14 @@
|
||||
.. meta::
|
||||
:description: HIP runtime API reference page
|
||||
:keywords: AMD, ROCm, HIP, CUDA, HIP runtime API, HIP runtime
|
||||
|
||||
.. _runtime_api_reference:
|
||||
|
||||
********************************************************************************
|
||||
HIP runtime API
|
||||
********************************************************************************
|
||||
|
||||
The HIP Runtime API reference:
|
||||
|
||||
* :ref:`modules_reference`
|
||||
* :ref:`global_defines_enums_structs_files_reference`
|
||||
@@ -0,0 +1,470 @@
|
||||
.. meta::
|
||||
:description: This page describes the FP8 and FP16 types present in HIP.
|
||||
:keywords: AMD, ROCm, HIP, fp8, fnuz, ocp
|
||||
|
||||
*******************************************************************************
|
||||
Low precision floating point types
|
||||
*******************************************************************************
|
||||
|
||||
Modern computing tasks often require balancing numerical precision against hardware resources
|
||||
and processing speed. Low precision floating point number formats in HIP include FP8 (Quarter Precision)
|
||||
and FP16 (Half Precision), which reduce memory and bandwidth requirements compared to traditional
|
||||
32-bit or 64-bit formats. The following sections detail their specifications, variants, and provide
|
||||
practical guidance for implementation in HIP.
|
||||
|
||||
FP8 (Quarter Precision)
|
||||
=======================
|
||||
|
||||
`FP8 (Floating Point 8-bit) numbers <https://arxiv.org/pdf/2209.05433>`_ were introduced
|
||||
as a compact numerical format specifically tailored for deep learning inference. By reducing
|
||||
precision while maintaining computational effectiveness, FP8 allows for significant memory
|
||||
savings and improved processing speed. This makes it particularly beneficial for deploying
|
||||
large-scale models with strict efficiency constraints.
|
||||
|
||||
Unlike traditional floating-point formats such as FP32 or even FP16, FP8 further optimizes
|
||||
performance by enabling a higher volume of matrix operations per second. Its reduced bit-width
|
||||
minimizes bandwidth requirements, making it an attractive choice for hardware accelerators
|
||||
in deep learning applications.
|
||||
|
||||
There are two primary FP8 formats:
|
||||
|
||||
- **E4M3 Format**
|
||||
|
||||
- Sign: 1 bit
|
||||
- Exponent: 4 bits
|
||||
- Mantissa: 3 bits
|
||||
|
||||
- **E5M2 Format**
|
||||
|
||||
- Sign: 1 bit
|
||||
- Exponent: 5 bits
|
||||
- Mantissa: 2 bits
|
||||
|
||||
The E4M3 format offers higher precision with a narrower range, while the E5M2 format provides
|
||||
a wider range at the cost of some precision.
|
||||
|
||||
Additionally, FP8 numbers have two representations:
|
||||
|
||||
- **FP8-OCP (Open Compute Project)**
|
||||
|
||||
- `This <https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1>`_
|
||||
is a standardized format developed by the Open Compute Project to ensure compatibility
|
||||
across various hardware and software implementations.
|
||||
|
||||
- **FP8-FNUZ (Finite and NaN Only)**
|
||||
|
||||
- A specialized format optimized for specific computations, supporting only finite and NaN values
|
||||
(no Inf support).
|
||||
- This provides one extra value of exponent and adds to the range of supported FP8 numbers.
|
||||
- **NaN Definition**: When the sign bit is set, and all other exponent and mantissa bits are zero.
|
||||
|
||||
The FNUZ representation provides an extra exponent value, expanding the range of representable
|
||||
numbers compared to standard FP8 formats.
|
||||
|
||||
|
||||
HIP Header
|
||||
----------
|
||||
|
||||
The `HIP FP8 header <https://github.com/ROCm/clr/blob/develop/hipamd/include/hip/amd_detail/amd_hip_fp8.h>`_
|
||||
defines the FP8 ocp/fnuz numbers.
|
||||
|
||||
Supported Devices
|
||||
-----------------
|
||||
|
||||
Different GPU models support different FP8 formats. Here's a breakdown:
|
||||
|
||||
.. list-table:: Supported devices for fp8 numbers
|
||||
:header-rows: 1
|
||||
|
||||
* - Device Type
|
||||
- FNUZ FP8
|
||||
- OCP FP8
|
||||
* - Host
|
||||
- Yes
|
||||
- Yes
|
||||
* - CDNA1
|
||||
- No
|
||||
- No
|
||||
* - CDNA2
|
||||
- No
|
||||
- No
|
||||
* - CDNA3
|
||||
- Yes
|
||||
- No
|
||||
* - RDNA2
|
||||
- No
|
||||
- No
|
||||
* - RDNA3
|
||||
- No
|
||||
- No
|
||||
|
||||
Using FP8 Numbers in HIP Programs
|
||||
---------------------------------
|
||||
|
||||
To use the FP8 numbers inside HIP programs.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <hip/hip_fp8.h>
|
||||
|
||||
FP8 numbers can be used on CPU side:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
__hip_fp8_storage_t convert_float_to_fp8(
|
||||
float in, /* Input val */
|
||||
__hip_fp8_interpretation_t interpret, /* interpretation of number E4M3/E5M2 */
|
||||
__hip_saturation_t sat /* Saturation behavior */
|
||||
) {
|
||||
return __hip_cvt_float_to_fp8(in, sat, interpret);
|
||||
}
|
||||
|
||||
The same can be done in kernels as well.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
__device__ __hip_fp8_storage_t d_convert_float_to_fp8(
|
||||
float in,
|
||||
__hip_fp8_interpretation_t interpret,
|
||||
__hip_saturation_t sat) {
|
||||
return __hip_cvt_float_to_fp8(in, sat, interpret);
|
||||
}
|
||||
|
||||
Note: On a gfx94x GPU, the type will default to the fnuz type.
|
||||
|
||||
The following code example does roundtrip FP8 conversions on both the CPU and GPU and compares the results.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <hip/hip_fp8.h>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define hip_check(hip_call) \
|
||||
{ \
|
||||
auto hip_res = hip_call; \
|
||||
if (hip_res != hipSuccess) { \
|
||||
std::cerr << "Failed in HIP call: " << #hip_call \
|
||||
<< " at " << __FILE__ << ":" << __LINE__ \
|
||||
<< " with error: " << hipGetErrorString(hip_res) << std::endl; \
|
||||
std::abort(); \
|
||||
} \
|
||||
}
|
||||
|
||||
__device__ __hip_fp8_storage_t d_convert_float_to_fp8(
|
||||
float in, __hip_fp8_interpretation_t interpret, __hip_saturation_t sat) {
|
||||
return __hip_cvt_float_to_fp8(in, sat, interpret);
|
||||
}
|
||||
|
||||
__device__ float d_convert_fp8_to_float(float in,
|
||||
__hip_fp8_interpretation_t interpret) {
|
||||
__half hf = __hip_cvt_fp8_to_halfraw(in, interpret);
|
||||
return hf;
|
||||
}
|
||||
|
||||
__global__ void float_to_fp8_to_float(float *in,
|
||||
__hip_fp8_interpretation_t interpret,
|
||||
__hip_saturation_t sat, float *out,
|
||||
size_t size) {
|
||||
int i = threadIdx.x;
|
||||
if (i < size) {
|
||||
auto fp8 = d_convert_float_to_fp8(in[i], interpret, sat);
|
||||
out[i] = d_convert_fp8_to_float(fp8, interpret);
|
||||
}
|
||||
}
|
||||
|
||||
__hip_fp8_storage_t
|
||||
convert_float_to_fp8(float in, /* Input val */
|
||||
__hip_fp8_interpretation_t
|
||||
interpret, /* interpretation of number E4M3/E5M2 */
|
||||
__hip_saturation_t sat /* Saturation behavior */
|
||||
) {
|
||||
return __hip_cvt_float_to_fp8(in, sat, interpret);
|
||||
}
|
||||
|
||||
float convert_fp8_to_float(
|
||||
__hip_fp8_storage_t in, /* Input val */
|
||||
__hip_fp8_interpretation_t
|
||||
interpret /* interpretation of number E4M3/E5M2 */
|
||||
) {
|
||||
__half hf = __hip_cvt_fp8_to_halfraw(in, interpret);
|
||||
return hf;
|
||||
}
|
||||
|
||||
int main() {
|
||||
constexpr size_t size = 32;
|
||||
hipDeviceProp_t prop;
|
||||
hip_check(hipGetDeviceProperties(&prop, 0));
|
||||
bool is_supported = (std::string(prop.gcnArchName).find("gfx94") != std::string::npos); // gfx94x
|
||||
if(!is_supported) {
|
||||
std::cerr << "Need a gfx94x, but found: " << prop.gcnArchName << std::endl;
|
||||
std::cerr << "No device conversions are supported, only host conversions are supported." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const __hip_fp8_interpretation_t interpret = (std::string(prop.gcnArchName).find("gfx94") != std::string::npos)
|
||||
? __HIP_E4M3_FNUZ // gfx94x
|
||||
: __HIP_E4M3;
|
||||
constexpr __hip_saturation_t sat = __HIP_SATFINITE;
|
||||
|
||||
std::vector<float> in;
|
||||
in.reserve(size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
in.push_back(i + 1.1f);
|
||||
}
|
||||
|
||||
std::cout << "Converting float to fp8 and back..." << std::endl;
|
||||
// CPU convert
|
||||
std::vector<float> cpu_out;
|
||||
cpu_out.reserve(size);
|
||||
for (const auto &fval : in) {
|
||||
auto fp8 = convert_float_to_fp8(fval, interpret, sat);
|
||||
cpu_out.push_back(convert_fp8_to_float(fp8, interpret));
|
||||
}
|
||||
|
||||
// GPU convert
|
||||
float *d_in, *d_out;
|
||||
hip_check(hipMalloc(&d_in, sizeof(float) * size));
|
||||
hip_check(hipMalloc(&d_out, sizeof(float) * size));
|
||||
|
||||
hip_check(hipMemcpy(d_in, in.data(), sizeof(float) * in.size(),
|
||||
hipMemcpyHostToDevice));
|
||||
|
||||
float_to_fp8_to_float<<<1, size>>>(d_in, interpret, sat, d_out, size);
|
||||
|
||||
std::vector<float> gpu_out(size, 0.0f);
|
||||
hip_check(hipMemcpy(gpu_out.data(), d_out, sizeof(float) * gpu_out.size(),
|
||||
hipMemcpyDeviceToHost));
|
||||
|
||||
hip_check(hipFree(d_in));
|
||||
hip_check(hipFree(d_out));
|
||||
|
||||
// Validation
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (cpu_out[i] != gpu_out[i]) {
|
||||
std::cerr << "cpu round trip result: " << cpu_out[i]
|
||||
<< " - gpu round trip result: " << gpu_out[i] << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
std::cout << "...CPU and GPU round trip convert matches." << std::endl;
|
||||
}
|
||||
|
||||
There are C++ style classes available as well.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
__hip_fp8_e4m3_fnuz fp8_val(1.1f); // gfx94x
|
||||
__hip_fp8_e4m3 fp8_val(1.1f);
|
||||
|
||||
Each type of FP8 number has its own class:
|
||||
|
||||
- __hip_fp8_e4m3
|
||||
- __hip_fp8_e5m2
|
||||
- __hip_fp8_e4m3_fnuz
|
||||
- __hip_fp8_e5m2_fnuz
|
||||
|
||||
There is support of vector of FP8 types.
|
||||
|
||||
- __hip_fp8x2_e4m3: holds 2 values of OCP FP8 e4m3 numbers
|
||||
- __hip_fp8x4_e4m3: holds 4 values of OCP FP8 e4m3 numbers
|
||||
- __hip_fp8x2_e5m2: holds 2 values of OCP FP8 e5m2 numbers
|
||||
- __hip_fp8x4_e5m2: holds 4 values of OCP FP8 e5m2 numbers
|
||||
- __hip_fp8x2_e4m3_fnuz: holds 2 values of FP8 fnuz e4m3 numbers
|
||||
- __hip_fp8x4_e4m3_fnuz: holds 4 values of FP8 fnuz e4m3 numbers
|
||||
- __hip_fp8x2_e5m2_fnuz: holds 2 values of FP8 fnuz e5m2 numbers
|
||||
- __hip_fp8x4_e5m2_fnuz: holds 4 values of FP8 fnuz e5m2 numbers
|
||||
|
||||
FNUZ extensions will be available on gfx94x only.
|
||||
|
||||
FP16 (Half Precision)
|
||||
=====================
|
||||
|
||||
FP16 (Floating Point 16-bit) numbers offer a balance between precision and
|
||||
efficiency, making them a widely adopted standard for accelerating deep learning
|
||||
inference. With higher precision than FP8 but lower memory requirements than FP32,
|
||||
FP16 enables faster computations while preserving model accuracy.
|
||||
|
||||
Deep learning workloads often involve massive datasets and complex calculations,
|
||||
making FP32 computationally expensive. FP16 helps mitigate these costs by reducing
|
||||
storage and bandwidth demands, allowing for increased throughput without significant
|
||||
loss of numerical stability. This format is particularly useful for training and
|
||||
inference in GPUs and TPUs optimized for half-precision arithmetic.
|
||||
|
||||
There are two primary FP16 formats:
|
||||
|
||||
- **float16 Format**
|
||||
|
||||
- Sign: 1 bit
|
||||
- Exponent: 5 bits
|
||||
- Mantissa: 10 bits
|
||||
|
||||
- **bfloat16 Format**
|
||||
|
||||
- Sign: 1 bit
|
||||
- Exponent: 8 bits
|
||||
- Mantissa: 7 bits
|
||||
|
||||
The float16 format offers higher precision with a narrower range, while the bfloat16
|
||||
format provides a wider range at the cost of some precision.
|
||||
|
||||
Additionally, FP16 numbers have standardized representations developed by industry
|
||||
initiatives to ensure compatibility across various hardware and software implementations.
|
||||
Unlike FP8, which has specific representations like OCP and FNUZ, FP16 is more uniformly
|
||||
supported with its two main formats, float16 and bfloat16.
|
||||
|
||||
HIP Header
|
||||
----------
|
||||
|
||||
The `HIP FP16 header <https://github.com/ROCm/clr/blob/develop/hipamd/include/hip/amd_detail/amd_hip_fp16.h>`_
|
||||
defines the float16 format.
|
||||
|
||||
The `HIP BF16 header <https://github.com/ROCm/clr/blob/develop/hipamd/include/hip/amd_detail/amd_hip_bf16.h>`_
|
||||
defines the bfloat16 format.
|
||||
|
||||
Supported Devices
|
||||
-----------------
|
||||
|
||||
Different GPU models support different FP16 formats. Here's a breakdown:
|
||||
|
||||
.. list-table:: Supported devices for fp16 numbers
|
||||
:header-rows: 1
|
||||
|
||||
* - Device Type
|
||||
- float16
|
||||
- bfloat16
|
||||
* - Host
|
||||
- Yes
|
||||
- Yes
|
||||
* - CDNA1
|
||||
- Yes
|
||||
- Yes
|
||||
* - CDNA2
|
||||
- Yes
|
||||
- Yes
|
||||
* - CDNA3
|
||||
- Yes
|
||||
- Yes
|
||||
* - RDNA2
|
||||
- Yes
|
||||
- Yes
|
||||
* - RDNA3
|
||||
- Yes
|
||||
- Yes
|
||||
|
||||
Using FP16 Numbers in HIP Programs
|
||||
----------------------------------
|
||||
|
||||
To use the FP16 numbers inside HIP programs.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <hip/hip_fp16.h> // for float16
|
||||
#include <hip/hip_bf16.h> // for bfloat16
|
||||
|
||||
The following code example adds two float16 values on the GPU and compares the results
|
||||
against summed float values on the CPU.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
#include <hip/hip_fp16.h>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define hip_check(hip_call) \
|
||||
{ \
|
||||
auto hip_res = hip_call; \
|
||||
if (hip_res != hipSuccess) { \
|
||||
std::cerr << "Failed in HIP call: " << #hip_call \
|
||||
<< " at " << __FILE__ << ":" << __LINE__ \
|
||||
<< " with error: " << hipGetErrorString(hip_res) << std::endl; \
|
||||
std::abort(); \
|
||||
} \
|
||||
}
|
||||
|
||||
__global__ void add_half_precision(__half* in1, __half* in2, float* out, size_t size) {
|
||||
int idx = threadIdx.x;
|
||||
if (idx < size) {
|
||||
// Load as half, perform addition in float, store as float
|
||||
float sum = __half2float(in1[idx] + in2[idx]);
|
||||
out[idx] = sum;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
constexpr size_t size = 32;
|
||||
constexpr float tolerance = 1e-1f; // Allowable numerical difference
|
||||
|
||||
// Initialize input vectors as floats
|
||||
std::vector<float> in1(size), in2(size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
in1[i] = i + 1.1f;
|
||||
in2[i] = i + 2.2f;
|
||||
}
|
||||
|
||||
// Compute expected results in full precision on CPU
|
||||
std::vector<float> cpu_out(size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
cpu_out[i] = in1[i] + in2[i]; // Direct float addition
|
||||
}
|
||||
|
||||
// Allocate device memory (store input as half, output as float)
|
||||
__half *d_in1, *d_in2;
|
||||
float *d_out;
|
||||
hip_check(hipMalloc(&d_in1, sizeof(__half) * size));
|
||||
hip_check(hipMalloc(&d_in2, sizeof(__half) * size));
|
||||
hip_check(hipMalloc(&d_out, sizeof(float) * size));
|
||||
|
||||
// Convert input to half and copy to device
|
||||
std::vector<__half> in1_half(size), in2_half(size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
in1_half[i] = __float2half(in1[i]);
|
||||
in2_half[i] = __float2half(in2[i]);
|
||||
}
|
||||
|
||||
hip_check(hipMemcpy(d_in1, in1_half.data(), sizeof(__half) * size, hipMemcpyHostToDevice));
|
||||
hip_check(hipMemcpy(d_in2, in2_half.data(), sizeof(__half) * size, hipMemcpyHostToDevice));
|
||||
|
||||
// Launch kernel
|
||||
add_half_precision<<<1, size>>>(d_in1, d_in2, d_out, size);
|
||||
|
||||
// Copy result back to host
|
||||
std::vector<float> gpu_out(size, 0.0f);
|
||||
hip_check(hipMemcpy(gpu_out.data(), d_out, sizeof(float) * size, hipMemcpyDeviceToHost));
|
||||
|
||||
// Free device memory
|
||||
hip_check(hipFree(d_in1));
|
||||
hip_check(hipFree(d_in2));
|
||||
hip_check(hipFree(d_out));
|
||||
|
||||
// Validation with tolerance
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (std::fabs(cpu_out[i] - gpu_out[i]) > tolerance) {
|
||||
std::cerr << "Mismatch at index " << i << ": CPU result = " << cpu_out[i]
|
||||
<< ", GPU result = " << gpu_out[i] << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Success: CPU and GPU half-precision addition match within tolerance!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
There are C++ style classes available as well.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
__half fp16_val(1.1f); // float16
|
||||
__hip_bfloat16 fp16_val(1.1f); // bfloat16
|
||||
|
||||
Each type of FP16 number has its own class:
|
||||
|
||||
- __half
|
||||
- __hip_bfloat16
|
||||
|
||||
There is support of vector of FP16 types.
|
||||
|
||||
- __half2: holds 2 values of float16 numbers
|
||||
- __hip_bfloat162: holds 2 values of bfloat16 numbers
|
||||
File diff ditekan karena terlalu besar
Load Diff
Reference in New Issue
Block a user