clr/hipamd/include/hip/amd_detail/amd_surface_functions.h Source File

clr/hipamd/include/hip/amd_detail/amd_surface_functions.h Source File#

HIP Runtime API Reference: clr/hipamd/include/hip/amd_detail/amd_surface_functions.h Source File
amd_surface_functions.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#ifndef HIP_INCLUDE_HIP_AMD_DETAIL_SURFACE_FUNCTIONS_H
8#define HIP_INCLUDE_HIP_AMD_DETAIL_SURFACE_FUNCTIONS_H
9
10#if defined(__cplusplus)
11
12#if !defined(__HIPCC_RTC__)
13#include <hip/surface_types.h>
15#include <hip/amd_detail/texture_fetch_functions.h>
16#include <hip/amd_detail/ockl_image.h>
17#endif
18
19#if defined(__HIPCC_RTC__)
20#define __HOST_DEVICE__ __device__
21#else
22#define __HOST_DEVICE__ __host__ __device__
23#endif
24
25#define __HIP_SURFACE_OBJECT_PARAMETERS_INIT \
26 unsigned int ADDRESS_SPACE_CONSTANT* i = (unsigned int ADDRESS_SPACE_CONSTANT*)surfObj;
27
33// CUDA is using byte address, need map to pixel address for HIP
34static __HOST_DEVICE__ __forceinline__ int __hipGetPixelAddr(int x, int format, int order) {
35 /*
36 * use below format index to generate format LUT
37 typedef enum {
38 HSA_EXT_IMAGE_CHANNEL_TYPE_SNORM_INT8 = 0,
39 HSA_EXT_IMAGE_CHANNEL_TYPE_SNORM_INT16 = 1,
40 HSA_EXT_IMAGE_CHANNEL_TYPE_UNORM_INT8 = 2,
41 HSA_EXT_IMAGE_CHANNEL_TYPE_UNORM_INT16 = 3,
42 HSA_EXT_IMAGE_CHANNEL_TYPE_UNORM_INT24 = 4,
43 HSA_EXT_IMAGE_CHANNEL_TYPE_UNORM_SHORT_555 = 5,
44 HSA_EXT_IMAGE_CHANNEL_TYPE_UNORM_SHORT_565 = 6,
45 HSA_EXT_IMAGE_CHANNEL_TYPE_UNORM_SHORT_101010 = 7,
46 HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT8 = 8,
47 HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT16 = 9,
48 HSA_EXT_IMAGE_CHANNEL_TYPE_SIGNED_INT32 = 10,
49 HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT8 = 11,
50 HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT16 = 12,
51 HSA_EXT_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32 = 13,
52 HSA_EXT_IMAGE_CHANNEL_TYPE_HALF_FLOAT = 14,
53 HSA_EXT_IMAGE_CHANNEL_TYPE_FLOAT = 15
54 } hsa_ext_image_channel_type_t;
55 */
56 static const int FormatLUT[] = {0, 1, 0, 1, 3, 1, 1, 1, 0, 1, 2, 0, 1, 2, 1, 2};
57 x = FormatLUT[format] == 3 ? x / FormatLUT[format] : x >> FormatLUT[format];
58
59 /*
60 * use below order index to generate order LUT
61 typedef enum {
62 HSA_EXT_IMAGE_CHANNEL_ORDER_A = 0,
63 HSA_EXT_IMAGE_CHANNEL_ORDER_R = 1,
64 HSA_EXT_IMAGE_CHANNEL_ORDER_RX = 2,
65 HSA_EXT_IMAGE_CHANNEL_ORDER_RG = 3,
66 HSA_EXT_IMAGE_CHANNEL_ORDER_RGX = 4,
67 HSA_EXT_IMAGE_CHANNEL_ORDER_RA = 5,
68 HSA_EXT_IMAGE_CHANNEL_ORDER_RGB = 6,
69 HSA_EXT_IMAGE_CHANNEL_ORDER_RGBX = 7,
70 HSA_EXT_IMAGE_CHANNEL_ORDER_RGBA = 8,
71 HSA_EXT_IMAGE_CHANNEL_ORDER_BGRA = 9,
72 HSA_EXT_IMAGE_CHANNEL_ORDER_ARGB = 10,
73 HSA_EXT_IMAGE_CHANNEL_ORDER_ABGR = 11,
74 HSA_EXT_IMAGE_CHANNEL_ORDER_SRGB = 12,
75 HSA_EXT_IMAGE_CHANNEL_ORDER_SRGBX = 13,
76 HSA_EXT_IMAGE_CHANNEL_ORDER_SRGBA = 14,
77 HSA_EXT_IMAGE_CHANNEL_ORDER_SBGRA = 15,
78 HSA_EXT_IMAGE_CHANNEL_ORDER_INTENSITY = 16,
79 HSA_EXT_IMAGE_CHANNEL_ORDER_LUMINANCE = 17,
80 HSA_EXT_IMAGE_CHANNEL_ORDER_DEPTH = 18,
81 HSA_EXT_IMAGE_CHANNEL_ORDER_DEPTH_STENCIL = 19
82 } hsa_ext_image_channel_order_t;
83 */
84 static const int OrderLUT[] = {0, 0, 1, 1, 3, 1, 3, 2, 2, 2, 2, 2, 3, 2, 2, 2, 0, 0, 0, 0};
85 return x = OrderLUT[order] == 3 ? x / OrderLUT[order] : x >> OrderLUT[order];
86}
87
96template <typename T, typename __hip_internal::enable_if<
97 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
98static __device__ __hip_img_chk__ void surf1Dread(T* data, hipSurfaceObject_t surfObj, int x,
99 int boundaryMode = hipBoundaryModeZero) {
101 (void)boundaryMode;
102 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
103 auto tmp = __ockl_image_load_1D(i, x);
104 *data = __hipMapFrom<T>(tmp);
105}
106
114template <typename T, typename __hip_internal::enable_if<
115 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
116static __device__ __hip_img_chk__ void surf1Dwrite(T data, hipSurfaceObject_t surfObj, int x) {
118 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
119 auto tmp = __hipMapTo<float4::Native_vec_>(data);
120 __ockl_image_store_1D(i, x, tmp);
121}
122
123
132template <typename T, typename __hip_internal::enable_if<
133 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
134static __device__ __hip_img_chk__ void surf2Dread(T* data, hipSurfaceObject_t surfObj, int x,
135 int y) {
137 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
138 int2 coords{x, y};
139 auto tmp = __ockl_image_load_2D(i, get_native_vector(coords));
140 *data = __hipMapFrom<T>(tmp);
141}
142
152template <typename T, typename __hip_internal::enable_if<
153 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
154static __device__ __hip_img_chk__ void surf2Dwrite(T data, hipSurfaceObject_t surfObj, int x,
155 int y) {
157 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
158 int2 coords{x, y};
159 auto tmp = __hipMapTo<float4::Native_vec_>(data);
160 __ockl_image_store_2D(i, get_native_vector(coords), tmp);
161}
162
173template <typename T, typename __hip_internal::enable_if<
174 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
175static __device__ __hip_img_chk__ void surf3Dread(T* data, hipSurfaceObject_t surfObj, int x, int y,
176 int z) {
178 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_3D(i), __ockl_image_channel_order_3D(i));
179 int4 coords{x, y, z, 0};
180 auto tmp = __ockl_image_load_3D(i, get_native_vector(coords));
181 *data = __hipMapFrom<T>(tmp);
182}
183
194template <typename T, typename __hip_internal::enable_if<
195 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
196static __device__ __hip_img_chk__ void surf3Dwrite(T data, hipSurfaceObject_t surfObj, int x, int y,
197 int z) {
199 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_3D(i), __ockl_image_channel_order_3D(i));
200 int4 coords{x, y, z, 0};
201 auto tmp = __hipMapTo<float4::Native_vec_>(data);
202 __ockl_image_store_3D(i, get_native_vector(coords), tmp);
203}
204
214template <typename T, typename __hip_internal::enable_if<
215 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
216static __device__ __hip_img_chk__ void surf1DLayeredread(T* data, hipSurfaceObject_t surfObj, int x,
217 int layer) {
219 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1Da(i),
220 __ockl_image_channel_order_1Da(i));
221 int2 coords{x, layer};
222 auto tmp = __ockl_image_load_1Da(i, get_native_vector(coords));
223 *data = __hipMapFrom<T>(tmp);
224}
225
235template <typename T, typename __hip_internal::enable_if<
236 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
237static __device__ __hip_img_chk__ void surf1DLayeredwrite(T data, hipSurfaceObject_t surfObj, int x,
238 int layer) {
240 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1Da(i),
241 __ockl_image_channel_order_1Da(i));
242 int2 coords{x, layer};
243 auto tmp = __hipMapTo<float4::Native_vec_>(data);
244 __ockl_image_store_1Da(i, get_native_vector(coords), tmp);
245}
246
257template <typename T, typename __hip_internal::enable_if<
258 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
259static __device__ __hip_img_chk__ void surf2DLayeredread(T* data, hipSurfaceObject_t surfObj, int x,
260 int y, int layer) {
262 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2Da(i),
263 __ockl_image_channel_order_2Da(i));
264 int4 coords{x, y, layer, 0};
265 auto tmp = __ockl_image_load_2Da(i, get_native_vector(coords));
266 *data = __hipMapFrom<T>(tmp);
267}
268
279template <typename T, typename __hip_internal::enable_if<
280 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
281static __device__ __hip_img_chk__ void surf2DLayeredwrite(T data, hipSurfaceObject_t surfObj, int x,
282 int y, int layer) {
284 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2Da(i),
285 __ockl_image_channel_order_2Da(i));
286 int4 coords{x, y, layer, 0};
287 auto tmp = __hipMapTo<float4::Native_vec_>(data);
288 __ockl_image_store_2Da(i, get_native_vector(coords), tmp);
289}
290
301template <typename T, typename __hip_internal::enable_if<
302 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
303static __device__ __hip_img_chk__ void surfCubemapread(T* data, hipSurfaceObject_t surfObj, int x,
304 int y, int face) {
306 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
307 int2 coords{x, y};
308 auto tmp = __ockl_image_load_CM(i, get_native_vector(coords), face);
309 *data = __hipMapFrom<T>(tmp);
310}
311
322template <typename T, typename __hip_internal::enable_if<
323 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
324static __device__ __hip_img_chk__ void surfCubemapwrite(T data, hipSurfaceObject_t surfObj, int x,
325 int y, int face) {
327 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
328 int2 coords{x, y};
329 auto tmp = __hipMapTo<float4::Native_vec_>(data);
330 __ockl_image_store_CM(i, get_native_vector(coords), face, tmp);
331}
332
344template <typename T, typename __hip_internal::enable_if<
345 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
346static __device__ __hip_img_chk__ void surfCubemapLayeredread(T* data, hipSurfaceObject_t surfObj,
347 int x, int y, int face, int layer) {
349 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
350 int2 coords{x, y};
351 auto tmp = __ockl_image_load_lod_CM(i, get_native_vector(coords), face, layer);
352 *data = __hipMapFrom<T>(tmp);
353}
354
366template <typename T, typename __hip_internal::enable_if<
367 __hip_is_tex_surf_channel_type<T>::value>::type* = nullptr>
368static __device__ __hip_img_chk__ void surfCubemapLayeredwrite(T* data, hipSurfaceObject_t surfObj,
369 int x, int y, int face, int layer) {
371 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
372 int2 coords{x, y};
373 auto tmp = __hipMapTo<float4::Native_vec_>(data);
374 __ockl_image_store_lod_CM(i, get_native_vector(coords), face, layer, tmp);
375}
376
377// Doxygen end group SurfaceAPI
382#endif
383
384#endif
#define __HIP_SURFACE_OBJECT_PARAMETERS_INIT
Definition amd_surface_functions.h:25
#define __HOST_DEVICE__
Definition amd_surface_functions.h:22
Defines surface types for HIP runtime.
@ hipBoundaryModeZero
Definition surface_types.h:41
struct __hip_surface * hipSurfaceObject_t
Definition surface_types.h:28