1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2021 NVIDIA Corporation & Affiliates
12 #include <rte_compat.h>
16 * Generic library to interact with GPU computing device.
18 * The API is not thread-safe.
19 * Device management must be done by a single thread.
22 * @b EXPERIMENTAL: this API may change without prior notice.
29 /** Maximum number of devices if rte_gpu_init() is not called. */
30 #define RTE_GPU_DEFAULT_MAX 32
32 /** Empty device ID. */
33 #define RTE_GPU_ID_NONE -1
34 /** Catch-all device ID. */
35 #define RTE_GPU_ID_ANY INT16_MIN
37 /** Catch-all callback data. */
38 #define RTE_GPU_CALLBACK_ANY_DATA ((void *)-1)
40 /** Store device info. */
42 /** Unique identifier name. */
46 /** Total processors available on device. */
47 uint32_t processor_count;
48 /** Total memory available on device. */
50 /* Local NUMA memory ID. -1 if unknown. */
54 /** Flags passed in notification callback. */
56 /** Device is just initialized. */
58 /** Device is going to be released. */
62 /** Prototype of event callback function. */
63 typedef void (rte_gpu_callback_t)(int16_t dev_id,
64 enum rte_gpu_event event, void *user_data);
68 * @b EXPERIMENTAL: this API may change without prior notice.
70 * Initialize the device array before probing devices.
71 * If not called, the maximum of probed devices is RTE_GPU_DEFAULT_MAX.
74 * Maximum number of devices.
77 * 0 on success, -rte_errno otherwise:
78 * - ENOMEM if out of memory
80 * - EBUSY if already initialized
83 int rte_gpu_init(size_t dev_max);
87 * @b EXPERIMENTAL: this API may change without prior notice.
89 * Return the number of GPU detected and associated to DPDK.
92 * The number of available computing devices.
95 uint16_t rte_gpu_count_avail(void);
99 * @b EXPERIMENTAL: this API may change without prior notice.
101 * Check if the device is valid and initialized in DPDK.
104 * The input device ID.
107 * - True if dev_id is a valid and initialized computing device.
111 bool rte_gpu_is_valid(int16_t dev_id);
115 * @b EXPERIMENTAL: this API may change without prior notice.
117 * Get the ID of the next valid GPU initialized in DPDK.
120 * The initial device ID to start the research.
123 * Next device ID corresponding to a valid and initialized computing device,
124 * RTE_GPU_ID_NONE if there is none.
127 int16_t rte_gpu_find_next(int16_t dev_id);
131 * @b EXPERIMENTAL: this API may change without prior notice.
133 * Macro to iterate over all valid GPU devices.
136 * The ID of the next possible valid device, usually 0 to iterate all.
138 #define RTE_GPU_FOREACH(dev_id) \
139 for (dev_id = rte_gpu_find_next(0); \
141 dev_id = rte_gpu_find_next(dev_id + 1))
145 * @b EXPERIMENTAL: this API may change without prior notice.
148 * All resources are released.
151 * Device ID to close.
154 * 0 on success, -rte_errno otherwise:
155 * - ENODEV if invalid dev_id
156 * - EPERM if driver error
159 int rte_gpu_close(int16_t dev_id);
163 * @b EXPERIMENTAL: this API may change without prior notice.
165 * Register a function as event callback.
166 * A function may be registered multiple times for different events.
169 * Device ID to get notified about.
170 * RTE_GPU_ID_ANY means all devices.
172 * Device event to be registered for.
174 * Callback function to be called on event.
176 * Optional parameter passed in the callback.
179 * 0 on success, -rte_errno otherwise:
180 * - ENODEV if invalid dev_id
181 * - EINVAL if NULL function
182 * - ENOMEM if out of memory
185 int rte_gpu_callback_register(int16_t dev_id, enum rte_gpu_event event,
186 rte_gpu_callback_t *function, void *user_data);
190 * @b EXPERIMENTAL: this API may change without prior notice.
192 * Unregister for an event.
195 * Device ID to be silenced.
196 * RTE_GPU_ID_ANY means all devices.
200 * Registered function.
202 * Optional parameter as registered.
203 * RTE_GPU_CALLBACK_ANY_DATA is a catch-all.
206 * 0 on success, -rte_errno otherwise:
207 * - ENODEV if invalid dev_id
208 * - EINVAL if NULL function
211 int rte_gpu_callback_unregister(int16_t dev_id, enum rte_gpu_event event,
212 rte_gpu_callback_t *function, void *user_data);
216 * @b EXPERIMENTAL: this API may change without prior notice.
218 * Return device specific info.
221 * Device ID to get info.
223 * Memory structure to fill with the info.
226 * 0 on success, -rte_errno otherwise:
227 * - ENODEV if invalid dev_id
228 * - EINVAL if NULL info
229 * - EPERM if driver error
232 int rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info);
238 #endif /* RTE_GPUDEV_H */