Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
GPUPortability.hpp File Reference

Unified GPU portability layer between CUDA and HIP with host fallback stubs. More...

#include "core/CompilerPortability.hpp"
#include <cstddef>
#include <utility>
Include dependency graph for GPUPortability.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MemcpyParams
 Memory copy parameter struct for host fallback. More...
struct  dim3
 3D vector dimension descriptor for CUDA/HIP emulation. More...

Typedefs

using hipError_t = int
 Return error type for host fallback emulation.

Functions

hipError_t hipGetDeviceCount (int *count) noexcept
 Returns the number of compute-capable GPU devices.
template<typename T>
hipError_t hipMalloc (T **ptr, std::size_t size) noexcept
 Host fallback allocation stub returning failure when GPU support is disabled.
hipError_t hipFree (void *ptr) noexcept
 Host fallback deallocation stub.
hipError_t hipMemcpy (MemcpyParams params) noexcept
 Host fallback memory copy stub.
hipError_t hipMemcpy (void *dst, const void *src, std::size_t count, int kind) noexcept
 Host fallback memory copy overload.
hipError_t hipDeviceSynchronize () noexcept
 Host fallback device synchronization stub.
const char * hipGetErrorString (hipError_t err) noexcept
 Translates an error code to a human-readable description.
template<typename T, typename U>
T atomicAdd (T *addr, U val) noexcept
 Host fallback atomic addition.
template<typename K, typename Grid, typename Block, typename Shared, typename Stream, typename... Args>
constexpr void hipLaunchKernelGGL (K &&kernel, Grid &&grid, Block &&block, Shared &&shared, Stream &&stream, Args &&...args) noexcept
 Host fallback stub for kernel launch when GPU acceleration is disabled.

Variables

constexpr int hipSuccess = 0
 Successful execution code.
constexpr int hipErrorNoDevice = 100
 Device unavailable error code.
constexpr int hipErrorNotSupported = 801
 Operation not supported in host fallback mode.
constexpr int hipMemcpyHostToDevice = 0
 Host-to-device memory copy transfer direction flag.
constexpr int hipMemcpyDeviceToHost = 0
 Device-to-host memory copy transfer direction flag.
constexpr dim3 threadIdx
 Emulated thread index inside thread block.
constexpr dim3 blockIdx
 Emulated block index inside grid.
constexpr dim3 blockDim
 Emulated block dimension.

Detailed Description

Unified GPU portability layer between CUDA and HIP with host fallback stubs.

License
SPDX-License-Identifier: AGPL-3.0-only

Typedef Documentation

◆ hipError_t

using hipError_t = int

Return error type for host fallback emulation.

Function Documentation

◆ atomicAdd()

template<typename T, typename U>
T atomicAdd ( T * addr,
U val )
inlinenoexcept

Host fallback atomic addition.

Template Parameters
TAddress data type.
UIncrement value type.
Parameters
[in,out]addrTarget memory location.
[in]valValue to add.
Returns
Old value before addition.

◆ hipDeviceSynchronize()

hipError_t hipDeviceSynchronize ( )
inlinenoexcept

Host fallback device synchronization stub.

Returns
hipErrorNoDevice.

◆ hipFree()

hipError_t hipFree ( void * ptr)
inlinenoexcept

Host fallback deallocation stub.

Parameters
[in]ptrPointer to free (ignored in fallback mode).
Returns
hipSuccess.
Here is the caller graph for this function:

◆ hipGetDeviceCount()

hipError_t hipGetDeviceCount ( int * count)
inlinenoexcept

Returns the number of compute-capable GPU devices.

Parameters
[out]countPointer to integer receiving device count (always 0 in host fallback).
Returns
hipSuccess.

◆ hipGetErrorString()

const char * hipGetErrorString ( hipError_t err)
inlinenoexcept

Translates an error code to a human-readable description.

Parameters
[in]errError code.
Returns
Static string description of the error code.
Here is the caller graph for this function:

◆ hipLaunchKernelGGL()

template<typename K, typename Grid, typename Block, typename Shared, typename Stream, typename... Args>
void hipLaunchKernelGGL ( K && kernel,
Grid && grid,
Block && block,
Shared && shared,
Stream && stream,
Args &&... args )
constexprnoexcept

Host fallback stub for kernel launch when GPU acceleration is disabled.

Template Parameters
KKernel function type.
GridGrid dimension type.
BlockBlock dimension type.
SharedShared memory size type.
StreamStream type.
ArgsKernel argument types.
Parameters
[in]kernelKernel function pointer or callable.
[in]gridGrid dimensions.
[in]blockBlock dimensions.
[in]sharedShared memory allocation size in bytes.
[in]streamExecution stream.
[in]argsKernel launch arguments.

◆ hipMalloc()

template<typename T>
hipError_t hipMalloc ( T ** ptr,
std::size_t size )
inlinenoexcept

Host fallback allocation stub returning failure when GPU support is disabled.

Template Parameters
TPointer element type.
Parameters
[out]ptrOutput pointer set to nullptr.
[in]sizeRequested byte size.
Returns
hipErrorNoDevice indicating no GPU acceleration is compiled in.
Here is the caller graph for this function:

◆ hipMemcpy() [1/2]

hipError_t hipMemcpy ( MemcpyParams params)
inlinenoexcept

Host fallback memory copy stub.

Parameters
[in]paramsMemory copy parameters.
Returns
hipErrorNoDevice.
Here is the caller graph for this function:

◆ hipMemcpy() [2/2]

hipError_t hipMemcpy ( void * dst,
const void * src,
std::size_t count,
int kind )
inlinenoexcept

Host fallback memory copy overload.

Parameters
[out]dstDestination buffer pointer.
[in]srcSource buffer pointer.
[in]countByte count.
[in]kindTransfer direction.
Returns
hipErrorNoDevice.
Here is the call graph for this function:

Variable Documentation

◆ blockDim

dim3 blockDim
inlineconstexpr
Initial value:
{
.x = 1,
.y = 1,
.z = 1,
}

Emulated block dimension.

◆ blockIdx

dim3 blockIdx
inlineconstexpr
Initial value:
{
.x = 0,
.y = 0,
.z = 0,
}

Emulated block index inside grid.

◆ hipErrorNoDevice

int hipErrorNoDevice = 100
constexpr

Device unavailable error code.

◆ hipErrorNotSupported

int hipErrorNotSupported = 801
constexpr

Operation not supported in host fallback mode.

◆ hipMemcpyDeviceToHost

int hipMemcpyDeviceToHost = 0
constexpr

Device-to-host memory copy transfer direction flag.

◆ hipMemcpyHostToDevice

int hipMemcpyHostToDevice = 0
constexpr

Host-to-device memory copy transfer direction flag.

◆ hipSuccess

int hipSuccess = 0
constexpr

Successful execution code.

◆ threadIdx

dim3 threadIdx
inlineconstexpr
Initial value:
{
.x = 0,
.y = 0,
.z = 0,
}

Emulated thread index inside thread block.