Advanced Multi-Physics (AMP)
On-Line Documentation
Helper_Hip.h
Go to the documentation of this file.
1#ifndef AMP_HipHelpers
2#define AMP_HipHelpers
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8#include <hip/hip_runtime.h>
9
10#include "AMP/utils/UtilityMacros.h"
11#include "StackTrace/source_location.h"
12
13#define hostDeviceId hipCpuDeviceId
14
15#define deviceMemAttachGlobal hipMemAttachGlobal
16
17#define deviceMemcpyHostToDevice hipMemcpyHostToDevice
18#define deviceMemcpyDeviceToHost hipMemcpyDeviceToHost
19#define deviceMemcpyDeviceToDevice hipMemcpyDeviceToDevice
20
21#define deviceInit( ... ) checkHipErrors( hipInit( __VA_ARGS__ ) )
22#define deviceGetCount( ... ) checkHipErrors( hipGetDeviceCount( __VA_ARGS__ ) )
23#define deviceBind( ... ) checkHipErrors( hipSetDevice( __VA_ARGS__ ) )
24#define deviceId( ... ) checkHipErrors( hipGetDevice( __VA_ARGS__ ) )
25#define deviceSynchronize() checkHipErrors( hipDeviceSynchronize() )
26#define deviceMalloc( ... ) checkHipErrors( hipMalloc( __VA_ARGS__ ) )
27#define deviceMallocManaged( ... ) checkHipErrors( hipMallocManaged( __VA_ARGS__ ) )
28#define deviceMemcpy( ... ) checkHipErrors( hipMemcpy( __VA_ARGS__ ) )
29#define deviceMemset( ... ) checkHipErrors( hipMemset( __VA_ARGS__ ) )
30#define deviceFree( ... ) checkHipErrors( hipFree( __VA_ARGS__ ) )
31#define deviceMemPrefetchAsync( ... ) checkHipErrors( hipMemPrefetchAsync( __VA_ARGS__ ) )
32
33namespace AMP::Utilities {
34enum class MemoryType : int8_t;
35}
36
37// Get the pointer type from hip
39
40// Get the name of a return code
41template<typename T>
42const char *hipGetName( T result );
43
44// Check the return code
45template<typename T>
46void checkHipErrors( T result,
47 const StackTrace::source_location &source = SOURCE_LOCATION_CURRENT() );
48
49// Get the last hip error
50void getLastDeviceError( const char *errorMessage,
51 const StackTrace::source_location &source = SOURCE_LOCATION_CURRENT() );
52
53static void inline setKernelDims( size_t n, dim3 &BlockDim, dim3 &GridDim )
54{
55 // ORNL Ref:
56 // https://www.olcf.ornl.gov/wp-content/uploads/2019/10/ORNL_Application_Readiness_Workshop-AMD_GPU_Basics.pdf
57 // AMD Specs
58 // https://rocm.docs.amd.com/en/latest/reference/gpu-arch-specs.html
59 // Parameters for AMD MI250/300 series.
60 // This should change to using occupancy API at
61 // https://rocm.docs.amd.com/projects/HIP/en/docs-develop/reference/hip_runtime_api/modules/occupancy.html
62 constexpr int waveFrontSize = 64;
63 // MI250 CUs (SMs) = 104, max wavefronts/CU = 8
64 // MI300 CUs (SMs) = 228, max wavefronts/CU = 10
65 // For now go with MI 300 values
66 constexpr int maxGridSize = 228 * 10;
67
68 int warpCount = ( n / waveFrontSize ) + ( ( ( n % waveFrontSize ) == 0 ) ? 0 : 1 );
69 int warpPerBlock = std::max( 1, std::min( 4, warpCount ) );
70 int threadCount = waveFrontSize * warpPerBlock;
71 int blockCount = std::min( maxGridSize, std::max( 1, warpCount / warpPerBlock ) );
72 BlockDim = dim3( threadCount, 1, 1 );
73 GridDim = dim3( blockCount, 1, 1 );
74 return;
75}
76
77#endif
static void setKernelDims(size_t n, dim3 &BlockDim, dim3 &GridDim)
Definition Helper_Hip.h:53
AMP::Utilities::MemoryType getHipMemoryType(const void *ptr)
const char * hipGetName(T result)
void getLastDeviceError(const char *errorMessage, const StackTrace::source_location &source=SOURCE_LOCATION_CURRENT())
void checkHipErrors(T result, const StackTrace::source_location &source=SOURCE_LOCATION_CURRENT())
MemoryType
Enum to store pointer type.
Definition Memory.h:21



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page