api/rpp.h Source File

api/rpp.h Source File#

RPP: api/rpp.h Source File
rpp.h
Go to the documentation of this file.
1 /*
2 MIT License
3 
4 Copyright (c) 2019 - 2025 Advanced Micro Devices, Inc.
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #ifndef RPP_H
26 #define RPP_H
27 
34 #if RPP_BACKEND_OPENCL
35 
36 #define CL_TARGET_OPENCL_VERSION 220
37 #if defined(__APPLE__) || defined(__MACOSX)
38 #include <OpenCL/cl.h>
39 #else
40 #include <CL/cl.h>
41 #endif
43 typedef cl_command_queue rppAcceleratorQueue_t;
44 
45 #elif RPP_BACKEND_HIP
46 
47 #include <hip/hip_runtime_api.h>
49 typedef hipStream_t rppAcceleratorQueue_t;
50 
51 #endif
52 
53 #if __cplusplus >= 201703L && __has_include(<filesystem>)
54 #include <filesystem>
55 namespace fs = std::filesystem;
56 #elif __has_include(<experimental/filesystem>)
57 #include <experimental/filesystem>
58 namespace fs = std::experimental::filesystem;
59 #endif
60 
64 #define RPP_DECLARE_OBJECT(name) \
65  struct name \
66  { \
67  }; \
68  typedef struct name* name##_t;
69 
73 RPP_DECLARE_OBJECT(rppHandle); // Create the rppHandle_t type
74 
78 typedef rppHandle_t RppHandle_t; // Create typedef for RppHandle_t
79 
80 #if _WIN32
81 #define SHARED_PUBLIC __declspec(dllexport)
82 #else
83 #define SHARED_PUBLIC __attribute__ ((visibility ("default")))
84 #endif
85 
86 #include "rppdefs.h"
87 #ifdef LEGACY_SUPPORT
88 #include "rppi.h"
89 #endif
90 #include "rppt.h"
91 #include "rpp_version.h"
92 
99 typedef void* (*rppAllocatorFunction)(void* context, size_t sizeBytes);
100 
107 typedef void (*rppDeallocatorFunction)(void* context, void* memory);
108 
109 #ifdef __cplusplus
110 extern "C" {
111 #endif
112 
132 extern "C" SHARED_PUBLIC rppStatus_t rppCreate(rppHandle_t* handle, size_t nBatchSize, Rpp32u numThreads = 0, void* stream = nullptr, RppBackend backend = RppBackend::RPP_HOST_BACKEND);
133 
150 extern "C" SHARED_PUBLIC rppStatus_t rppDestroy(rppHandle_t handle, RppBackend backend = RppBackend::RPP_HOST_BACKEND);
151 
168 extern "C" SHARED_PUBLIC rppStatus_t rppSetBatchSize(rppHandle_t handle, size_t batchSize);
169 
186 extern "C" SHARED_PUBLIC rppStatus_t rppGetBatchSize(rppHandle_t handle, size_t *batchSize);
187 
188 #if GPU_SUPPORT
189 
206 extern "C" SHARED_PUBLIC rppStatus_t rppSetStream(rppHandle_t handle, rppAcceleratorQueue_t streamID);
207 
224 extern "C" SHARED_PUBLIC rppStatus_t rppGetStream(rppHandle_t handle, rppAcceleratorQueue_t* streamID);
225 
244 extern "C" SHARED_PUBLIC rppStatus_t rppSetAllocator(rppHandle_t handle, rppAllocatorFunction allocator, rppDeallocatorFunction deallocator, void* allocatorContext);
245 
262 extern "C" SHARED_PUBLIC rppStatus_t rppGetKernelTime(rppHandle_t handle, float* time);
263 
280 extern "C" SHARED_PUBLIC rppStatus_t rppEnableProfiling(rppHandle_t handle, bool enable);
281 
282 #endif // GPU_SUPPORT
283 
284 #ifdef __cplusplus
285 }
286 #endif // __cplusplus
287 
288 #endif // RPP_H
#define RPP_DECLARE_OBJECT(name)
Construct type name from a struct.
Definition: rpp.h:64
SHARED_PUBLIC rppStatus_t rppSetBatchSize(rppHandle_t handle, size_t batchSize)
Set batch size given a RPP handle.
SHARED_PUBLIC rppStatus_t rppSetAllocator(rppHandle_t handle, rppAllocatorFunction allocator, rppDeallocatorFunction deallocator, void *allocatorContext)
Set allocator given a RPP handle.
hipStream_t rppAcceleratorQueue_t
Set rppAcceleratorQueue_t to hipStream_t if RPP_BACKEND_HIP.
Definition: rpp.h:49
void(* rppDeallocatorFunction)(void *context, void *memory)
Handles RPP context allocations.
Definition: rpp.h:107
SHARED_PUBLIC rppStatus_t rppCreate(rppHandle_t *handle, size_t nBatchSize, Rpp32u numThreads=0, void *stream=nullptr, RppBackend backend=RppBackend::RPP_HOST_BACKEND)
Creates RPP handle for HOST/HIP/OCL backend batch processing.
SHARED_PUBLIC rppStatus_t rppGetKernelTime(rppHandle_t handle, float *time)
Get time taken by previous kernel.
void *(* rppAllocatorFunction)(void *context, size_t sizeBytes)
Handles RPP context allocations.
Definition: rpp.h:99
SHARED_PUBLIC rppStatus_t rppSetStream(rppHandle_t handle, rppAcceleratorQueue_t streamID)
Set accelerator stream given a RPP handle.
SHARED_PUBLIC rppStatus_t rppGetStream(rppHandle_t handle, rppAcceleratorQueue_t *streamID)
Get accelerator stream given a RPP handle.
rppHandle_t RppHandle_t
RPP handle.
Definition: rpp.h:78
SHARED_PUBLIC rppStatus_t rppDestroy(rppHandle_t handle, RppBackend backend=RppBackend::RPP_HOST_BACKEND)
Destroys RPP handle for HOST/HIP/OCL backend batch processing.
SHARED_PUBLIC rppStatus_t rppGetBatchSize(rppHandle_t handle, size_t *batchSize)
Get batch size given a RPP Handle.
SHARED_PUBLIC rppStatus_t rppEnableProfiling(rppHandle_t handle, bool enable)
Enable Profiling.
unsigned int Rpp32u
32 bit unsigned int
Definition: rppdefs.h:97
RppBackend
RPP RppBackend type enums.
Definition: rppdefs.h:178
rppStatus_t
RPP rppStatus_t type enums.
Definition: rppdefs.h:188
ROCm Performance Primitives (RPP) version.
RPP common HOST/GPU typedef, enum and structure definitions.
RPP Image Operations - To be deprecated.
RPP Tensor Operations.