Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
HalideRuntimeCuda.h
Go to the documentation of this file.
1#ifndef HALIDE_HALIDERUNTIMECUDA_H
2#define HALIDE_HALIDERUNTIMECUDA_H
3
4// Don't include HalideRuntime.h if the contents of it were already pasted into a generated header above this one
5#ifndef HALIDE_HALIDERUNTIME_H
6
7#include "HalideRuntime.h"
8
9#endif
10
11#ifdef __cplusplus
12 extern "C" {
13#endif
14
15/** \file
16 * Routines specific to the Halide Cuda runtime.
17 */
18
19#define HALIDE_RUNTIME_CUDA
20
21 extern const struct halide_device_interface_t *halide_cuda_device_interface();
22
23/** These are forward declared here to allow clients to override the
24 * Halide Cuda runtime. Do not call them. */
25// @{
26 extern int halide_cuda_initialize_kernels(void *user_context, void **state_ptr,
27 const char *src, int size);
28 extern int halide_cuda_run(void *user_context,
29 void *state_ptr,
30 const char *entry_name,
31 int blocksX, int blocksY, int blocksZ,
32 int threadsX, int threadsY, int threadsZ,
33 int shared_mem_bytes,
34 size_t arg_sizes[],
35 void *args[],
36 int8_t arg_is_buffer[]);
37 extern void halide_cuda_finalize_kernels(void *user_context, void *state_ptr);
38// @}
39
40/** Set the underlying cuda device poiner for a buffer. The device
41 * pointer should be allocated using cuMemAlloc or similar and must
42 * have an extent large enough to cover that specified by the
43 * halide_buffer_t extent fields. The dev field of the halide_buffer_t
44 * must be NULL when this routine is called. This call can fail due to
45 * being passed an invalid device pointer. The device and host dirty
46 * bits are left unmodified. */
47 extern int halide_cuda_wrap_device_ptr(void *user_context, struct halide_buffer_t *buf, uint64_t device_ptr);
48
49/** Disconnect this halide_buffer_t from the device pointer it was
50 * previously wrapped around. Should only be called for a
51 * halide_buffer_t that halide_cuda_wrap_device_ptr was previously
52 * called on. The device field of the halide_buffer_t will be NULL on
53 * return.
54 */
55 extern int halide_cuda_detach_device_ptr(void *user_context, struct halide_buffer_t *buf);
56
57/** Return the underlying device pointer for a halide_buffer_t. This buffer
58 * must be valid on a Cuda device, or not have any associated device
59 * memory. If there is no device memory (dev field is NULL), this
60 * returns 0.
61 */
62 extern uintptr_t halide_cuda_get_device_ptr(void *user_context, struct halide_buffer_t *buf);
63
64/** Release any currently-unused device allocations back to the cuda
65 * driver. See halide_reuse_device_allocations. */
66 extern int halide_cuda_release_unused_device_allocations(void *user_context);
67
68// These typedefs treat both a CUcontext and a CUstream as a void *,
69// to avoid dependencies on cuda headers.
70 typedef int (*halide_cuda_acquire_context_t)(void *, // user_context
71 void **, // cuda context out parameter
72 bool); // should create a context if none exist
73 typedef int (*halide_cuda_release_context_t)(void * /* user_context */);
74 typedef int (*halide_cuda_get_stream_t)(void *, // user_context
75 void *, // context
76 void **); // stream out parameter
77
78/** Set custom methods to acquire and release cuda contexts and streams */
79// @{
80 extern halide_cuda_acquire_context_t halide_set_cuda_acquire_context(halide_cuda_acquire_context_t handler);
81 extern halide_cuda_release_context_t halide_set_cuda_release_context(halide_cuda_release_context_t handler);
82 extern halide_cuda_get_stream_t halide_set_cuda_get_stream(halide_cuda_get_stream_t handler);
83// @}
84
85#ifdef __cplusplus
86} // End extern "C"
87#endif
88
89#endif // HALIDE_HALIDERUNTIMECUDA_H
HalideRuntime.h
This file declares the routines used by Halide internally in its runtime.
halide_cuda_get_device_ptr
uintptr_t halide_cuda_get_device_ptr(void *user_context, struct halide_buffer_t *buf)
Return the underlying device pointer for a halide_buffer_t.
halide_cuda_get_stream_t
int(* halide_cuda_get_stream_t)(void *, void *, void **)
Definition HalideRuntimeCuda.h:74
halide_cuda_wrap_device_ptr
int halide_cuda_wrap_device_ptr(void *user_context, struct halide_buffer_t *buf, uint64_t device_ptr)
Set the underlying cuda device poiner for a buffer.
halide_cuda_run
int halide_cuda_run(void *user_context, void *state_ptr, const char *entry_name, int blocksX, int blocksY, int blocksZ, int threadsX, int threadsY, int threadsZ, int shared_mem_bytes, size_t arg_sizes[], void *args[], int8_t arg_is_buffer[])
halide_cuda_release_unused_device_allocations
int halide_cuda_release_unused_device_allocations(void *user_context)
Release any currently-unused device allocations back to the cuda driver.
halide_cuda_initialize_kernels
int halide_cuda_initialize_kernels(void *user_context, void **state_ptr, const char *src, int size)
These are forward declared here to allow clients to override the Halide Cuda runtime.
halide_cuda_finalize_kernels
void halide_cuda_finalize_kernels(void *user_context, void *state_ptr)
halide_set_cuda_acquire_context
halide_cuda_acquire_context_t halide_set_cuda_acquire_context(halide_cuda_acquire_context_t handler)
Set custom methods to acquire and release cuda contexts and streams.
halide_cuda_release_context_t
int(* halide_cuda_release_context_t)(void *)
Definition HalideRuntimeCuda.h:73
halide_cuda_acquire_context_t
int(* halide_cuda_acquire_context_t)(void *, void **, bool)
Definition HalideRuntimeCuda.h:70
halide_set_cuda_release_context
halide_cuda_release_context_t halide_set_cuda_release_context(halide_cuda_release_context_t handler)
halide_cuda_detach_device_ptr
int halide_cuda_detach_device_ptr(void *user_context, struct halide_buffer_t *buf)
Disconnect this halide_buffer_t from the device pointer it was previously wrapped around.
halide_cuda_device_interface
const struct halide_device_interface_t * halide_cuda_device_interface()
halide_set_cuda_get_stream
halide_cuda_get_stream_t halide_set_cuda_get_stream(halide_cuda_get_stream_t handler)
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition runtime_internal.h:23
uintptr_t
__UINTPTR_TYPE__ uintptr_t
Definition runtime_internal.h:75
int8_t
signed __INT8_TYPE__ int8_t
Definition runtime_internal.h:28
halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Definition HalideRuntime.h:1569
halide_device_interface_t
Each GPU API provides a halide_device_interface_t struct pointing to the code that manages device all...
Definition HalideRuntime.h:797
user_context
void * user_context
Definition vulkan_resources.h:178