Gromacs  2025-dev-20240612-66cb22e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Typedefs | Functions
devicebuffer_hip.h File Reference
#include "gromacs/gpu_utils/device_context.h"
#include "gromacs/gpu_utils/device_stream.h"
#include "gromacs/gpu_utils/devicebuffer_datatype.h"
#include "gromacs/gpu_utils/gpu_utils.h"
#include "gromacs/gpu_utils/gputraits_hip.h"
#include "gromacs/gpu_utils/hiputils.h"
#include "gromacs/utility/gmxassert.h"
+ Include dependency graph for devicebuffer_hip.h:

Description

Implements the DeviceBuffer type and routines for HIP. Should only be included directly by the main DeviceBuffer file devicebuffer.h. TODO: the intent is for DeviceBuffer to become a class.

Author
Paul Bauer paul..nosp@m.baue.nosp@m.r.q@g.nosp@m.mail.nosp@m..com
Julio Maia julio.nosp@m..mai.nosp@m.a@amd.nosp@m..com

Typedefs

using DeviceTexture = hipTextureObject_t
 Device texture wrapper.
 

Functions

template<typename ValueType >
void allocateDeviceBuffer (DeviceBuffer< ValueType > *buffer, size_t numValues, const DeviceContext &)
 Allocates a device-side buffer. It is currently a caller's responsibility to call it only on not-yet allocated buffers. More...
 
template<typename DeviceBuffer >
void freeDeviceBuffer (DeviceBuffer *buffer)
 Frees a device-side buffer. This does not reset separately stored size/capacity integers, as this is planned to be a destructor of DeviceBuffer as a proper class, and no calls on buffer should be made afterwards. More...
 
template<typename ValueType >
void copyToDeviceBuffer (DeviceBuffer< ValueType > *buffer, const ValueType *hostBuffer, size_t startingOffset, size_t numValues, const DeviceStream &deviceStream, GpuApiCallBehavior transferKind, CommandEvent *)
 Performs the host-to-device data copy, synchronous or asynchronously on request. More...
 
template<typename ValueType >
void copyFromDeviceBuffer (ValueType *hostBuffer, DeviceBuffer< ValueType > *buffer, size_t startingOffset, size_t numValues, const DeviceStream &deviceStream, GpuApiCallBehavior transferKind, CommandEvent *)
 Performs the device-to-host data copy, synchronous or asynchronously on request. More...
 
template<typename ValueType >
void copyBetweenDeviceBuffers (DeviceBuffer< ValueType > *destinationDeviceBuffer, DeviceBuffer< ValueType > *sourceDeviceBuffer, size_t numValues, const DeviceStream &deviceStream, GpuApiCallBehavior transferKind, CommandEvent *)
 Performs the device-to-device data copy, synchronous or asynchronously on request. More...
 
template<typename ValueType >
void clearDeviceBufferAsync (DeviceBuffer< ValueType > *buffer, size_t startingOffset, size_t numValues, const DeviceStream &deviceStream)
 Clears the device buffer asynchronously. More...
 
template<typename T >
static gmx_unused bool checkDeviceBuffer (DeviceBuffer< T > buffer, gmx_unused int requiredSize)
 Check the validity of the device buffer. More...
 
template<typename ValueType >
void initParamLookupTable (DeviceBuffer< ValueType > *deviceBuffer, DeviceTexture *, const ValueType *hostBuffer, int numValues, const DeviceContext &deviceContext)
 Create a texture object for an array of type ValueType. More...
 
template<typename ValueType >
void destroyParamLookupTable (DeviceBuffer< ValueType > *deviceBuffer, const DeviceTexture *)
 Unbind the texture and release the HIP texture object. More...
 
template<typename ValueType >
ValueType * asMpiPointer (DeviceBuffer< ValueType > &buffer)
 

Function Documentation

template<typename ValueType >
void allocateDeviceBuffer ( DeviceBuffer< ValueType > *  buffer,
size_t  numValues,
const DeviceContext &   
)

Allocates a device-side buffer. It is currently a caller's responsibility to call it only on not-yet allocated buffers.

Template Parameters
ValueTypeRaw value type of the buffer.
Parameters
[in,out]bufferPointer to the device-side buffer.
[in]numValuesNumber of values to accommodate.
template<typename T >
static gmx_unused bool checkDeviceBuffer ( DeviceBuffer< T >  buffer,
gmx_unused int  requiredSize 
)
static

Check the validity of the device buffer.

Checks if the buffer is not nullptr.

Todo:
Add checks on the buffer size when it will be possible.
Parameters
[in]bufferDevice buffer to be checked.
[in]requiredSizeNumber of elements that the buffer will have to accommodate.
Returns
Whether the device buffer can be set.
template<typename ValueType >
void clearDeviceBufferAsync ( DeviceBuffer< ValueType > *  buffer,
size_t  startingOffset,
size_t  numValues,
const DeviceStream deviceStream 
)

Clears the device buffer asynchronously.

Template Parameters
ValueTypeRaw value type of the buffer.
Parameters
[in,out]bufferPointer to the device-side buffer
[in]startingOffsetOffset (in values) at the device-side buffer to start clearing at.
[in]numValuesNumber of values to clear.
[in]deviceStreamGPU stream.
template<typename ValueType >
void copyBetweenDeviceBuffers ( DeviceBuffer< ValueType > *  destinationDeviceBuffer,
DeviceBuffer< ValueType > *  sourceDeviceBuffer,
size_t  numValues,
const DeviceStream deviceStream,
GpuApiCallBehavior  transferKind,
CommandEvent  
)

Performs the device-to-device data copy, synchronous or asynchronously on request.

Template Parameters
ValueTypeRaw value type of the buffer.
Parameters
[in,out]destinationDeviceBufferDevice-side buffer to copy to
[in]sourceDeviceBufferDevice-side buffer to copy from
[in]numValuesNumber of values to copy.
[in]deviceStreamGPU stream to perform asynchronous copy in.
[in]transferKindCopy type: synchronous or asynchronous.
template<typename ValueType >
void copyFromDeviceBuffer ( ValueType *  hostBuffer,
DeviceBuffer< ValueType > *  buffer,
size_t  startingOffset,
size_t  numValues,
const DeviceStream deviceStream,
GpuApiCallBehavior  transferKind,
CommandEvent  
)

Performs the device-to-host data copy, synchronous or asynchronously on request.

Template Parameters
ValueTypeRaw value type of the buffer.
Parameters
[in,out]hostBufferPointer to the raw host-side memory, also typed ValueType
[in]bufferPointer to the device-side buffer
[in]startingOffsetOffset (in values) at the device-side buffer to copy from.
[in]numValuesNumber of values to copy.
[in]deviceStreamGPU stream to perform asynchronous copy in.
[in]transferKindCopy type: synchronous or asynchronous.
template<typename ValueType >
void copyToDeviceBuffer ( DeviceBuffer< ValueType > *  buffer,
const ValueType *  hostBuffer,
size_t  startingOffset,
size_t  numValues,
const DeviceStream deviceStream,
GpuApiCallBehavior  transferKind,
CommandEvent  
)

Performs the host-to-device data copy, synchronous or asynchronously on request.

Template Parameters
ValueTypeRaw value type of the buffer.
Parameters
[in,out]bufferPointer to the device-side buffer
[in]hostBufferPointer to the raw host-side memory, also typed ValueType
[in]startingOffsetOffset (in values) at the device-side buffer to copy into.
[in]numValuesNumber of values to copy.
[in]deviceStreamGPU stream to perform asynchronous copy in.
[in]transferKindCopy type: synchronous or asynchronous.
template<typename ValueType >
void destroyParamLookupTable ( DeviceBuffer< ValueType > *  deviceBuffer,
const DeviceTexture  
)

Unbind the texture and release the HIP texture object.

Template Parameters
ValueTypeRaw data type
Parameters
[in,out]deviceBufferDevice buffer to store data in.
template<typename DeviceBuffer >
void freeDeviceBuffer ( DeviceBuffer buffer)

Frees a device-side buffer. This does not reset separately stored size/capacity integers, as this is planned to be a destructor of DeviceBuffer as a proper class, and no calls on buffer should be made afterwards.

Parameters
[in]bufferPointer to the buffer to free.
template<typename ValueType >
void initParamLookupTable ( DeviceBuffer< ValueType > *  deviceBuffer,
DeviceTexture ,
const ValueType *  hostBuffer,
int  numValues,
const DeviceContext &  deviceContext 
)

Create a texture object for an array of type ValueType.

Creates the device buffer, copies data and binds texture object for an array of type ValueType.

Todo:
Test if using textures is still relevant on modern hardware.
Template Parameters
ValueTypeRaw data type.
Parameters
[out]deviceBufferDevice buffer to store data in.
[in]hostBufferHost buffer to get date from
[in]numValuesNumber of elements in the buffer.
[in]deviceContextGPU device context.