Gromacs
2022.2
|
#include <utility>
#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/gmxsycl.h"
#include "gromacs/gpu_utils/gpu_utils.h"
#include "gromacs/gpu_utils/gputraits_sycl.h"
#include "gromacs/hardware/device_information.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/stringutil.h"
Implements the DeviceBuffer type and routines for SYCL. Should only be included directly by the main DeviceBuffer file devicebuffer.h. TODO: the intent is for DeviceBuffer to become a class.
Functions | |
template<typename T > | |
static gmx_unused bool | checkDeviceBuffer (const DeviceBuffer< T > &buffer, int requiredSize) |
Check the validity of the device buffer. More... | |
template<typename ValueType > | |
void | allocateDeviceBuffer (DeviceBuffer< ValueType > *buffer, size_t numValues, const DeviceContext &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 ValueType > | |
void | freeDeviceBuffer (DeviceBuffer< ValueType > *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 *gmx_unused timingEvent) |
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 *gmx_unused timingEvent) |
Performs the device-to-host data copy, synchronous or asynchronously on request. More... | |
template<typename ValueType > | |
void | copyBetweenDeviceBuffers (DeviceBuffer< ValueType > *, DeviceBuffer< ValueType > *, size_t, const DeviceStream &, GpuApiCallBehavior, CommandEvent *) |
Performs the device-to-device data copy, synchronous or asynchronously on request. More... | |
template<typename ValueType > | |
sycl::event | gmx::internal::fillSyclBufferWithNull (sycl::buffer< ValueType, 1 > &buffer, size_t startingOffset, size_t numValues, sycl::queue queue) |
Helper function to clear device buffer. More... | |
template<> | |
sycl::event | gmx::internal::fillSyclBufferWithNull (sycl::buffer< Float3, 1 > &buffer, size_t startingOffset, size_t numValues, sycl::queue queue) |
Helper function to clear device buffer of type Float3. | |
template<typename ValueType > | |
sycl::event | gmx::internal::fillSyclUsmWithNull (ValueType *buffer, size_t startingOffset, size_t numValues, sycl::queue queue) |
template<> | |
sycl::event | gmx::internal::fillSyclUsmWithNull (Float3 *buffer, size_t startingOffset, size_t numValues, sycl::queue queue) |
Helper function to clear device memory of type Float3. | |
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 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, DeviceTexture *) |
Release the OpenCL device buffer. More... | |
void allocateDeviceBuffer | ( | DeviceBuffer< ValueType > * | buffer, |
size_t | numValues, | ||
const DeviceContext & | deviceContext | ||
) |
Allocates a device-side buffer. It is currently a caller's responsibility to call it only on not-yet allocated buffers.
ValueType | Raw value type of the buffer . |
[in,out] | buffer | Pointer to the device-side buffer. |
[in] | numValues | Number of values to accommodate. |
[in] | deviceContext | The buffer's device context-to-be. |
|
static |
Check the validity of the device buffer.
Checks if the buffer is valid and if its allocation is big enough.
[in] | buffer | Device buffer to be checked. |
[in] | requiredSize | Number of elements that the buffer will have to accommodate. |
void clearDeviceBufferAsync | ( | DeviceBuffer< ValueType > * | buffer, |
size_t | startingOffset, | ||
size_t | numValues, | ||
const DeviceStream & | deviceStream | ||
) |
Clears the device buffer asynchronously.
ValueType | Raw value type of the buffer . |
[in,out] | buffer | Pointer to the device-side buffer. |
[in] | startingOffset | Offset (in values) at the device-side buffer to start clearing at. |
[in] | numValues | Number of values to clear. |
[in] | deviceStream | GPU stream. |
void copyBetweenDeviceBuffers | ( | DeviceBuffer< ValueType > * | , |
DeviceBuffer< ValueType > * | , | ||
size_t | , | ||
const DeviceStream & | , | ||
GpuApiCallBehavior | , | ||
CommandEvent * | |||
) |
Performs the device-to-device data copy, synchronous or asynchronously on request.
ValueType | Raw value type of the buffer . |
void copyFromDeviceBuffer | ( | ValueType * | hostBuffer, |
DeviceBuffer< ValueType > * | buffer, | ||
size_t | startingOffset, | ||
size_t | numValues, | ||
const DeviceStream & | deviceStream, | ||
GpuApiCallBehavior | transferKind, | ||
CommandEvent *gmx_unused | timingEvent | ||
) |
Performs the device-to-host data copy, synchronous or asynchronously on request.
Unlike in CUDA and OpenCL, synchronous call does not guarantee that all previously submitted operations are complete, only the ones that are required for buffer
consistency.
ValueType | Raw value type of the buffer . |
[in,out] | hostBuffer | Pointer to the raw host-side memory, also typed ValueType |
[in] | buffer | Pointer to the device-side buffer. |
[in] | startingOffset | Offset (in values) at the device-side buffer to copy from. |
[in] | numValues | Number of values to copy. |
[in] | deviceStream | GPU stream to perform asynchronous copy in. |
[in] | transferKind | Copy type: synchronous or asynchronous. |
[out] | timingEvent | A pointer to the H2D copy timing event to be filled in. Ignored in SYCL. |
void copyToDeviceBuffer | ( | DeviceBuffer< ValueType > * | buffer, |
const ValueType * | hostBuffer, | ||
size_t | startingOffset, | ||
size_t | numValues, | ||
const DeviceStream & | deviceStream, | ||
GpuApiCallBehavior | transferKind, | ||
CommandEvent *gmx_unused | timingEvent | ||
) |
Performs the host-to-device data copy, synchronous or asynchronously on request.
Unlike in CUDA and OpenCL, synchronous call does not guarantee that all previously submitted operations are complete, only the ones that are required for buffer
consistency.
ValueType | Raw value type of the buffer . |
[in,out] | buffer | Pointer to the device-side buffer. |
[in] | hostBuffer | Pointer to the raw host-side memory, also typed ValueType . |
[in] | startingOffset | Offset (in values) at the device-side buffer to copy into. |
[in] | numValues | Number of values to copy. |
[in] | deviceStream | GPU stream to perform asynchronous copy in. |
[in] | transferKind | Copy type: synchronous or asynchronous. |
[out] | timingEvent | A pointer to the H2D copy timing event to be filled in. Ignored in SYCL. |
void destroyParamLookupTable | ( | DeviceBuffer< ValueType > * | deviceBuffer, |
DeviceTexture * | |||
) |
Release the OpenCL device buffer.
ValueType | Raw data type. |
[in,out] | deviceBuffer | Device buffer to store data in. |
void freeDeviceBuffer | ( | DeviceBuffer< ValueType > * | 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.
[in] | buffer | Pointer to the buffer to free. |
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 and copies read-only data for an array of type ValueType. Like OpenCL, does not really do anything with textures, simply creates a buffer and initializes it.
ValueType | Raw data type. |
[out] | deviceBuffer | Device buffer to store data in. |
[in] | hostBuffer | Host buffer to get date from. |
[in] | numValues | Number of elements in the buffer. |
[in] | deviceContext | GPU device context. |