Halide
HalideRuntimeMetal.h
Go to the documentation of this file.
1 #ifndef HALIDE_HALIDERUNTIMEMETAL_H
2 #define HALIDE_HALIDERUNTIMEMETAL_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 Metal runtime.
17  */
18 
19 #define HALIDE_RUNTIME_METAL
20 
22 
23 /** These are forward declared here to allow clients to override the
24  * Halide Metal runtime. Do not call them. */
25 // @{
26 extern int halide_metal_initialize_kernels(void *user_context, void **state_ptr,
27  const char *src, int size);
28 
29 extern int halide_metal_run(void *user_context,
30  void *state_ptr,
31  const char *entry_name,
32  int blocksX, int blocksY, int blocksZ,
33  int threadsX, int threadsY, int threadsZ,
34  int shared_mem_bytes,
35  size_t arg_sizes[],
36  void *args[],
37  int8_t arg_is_buffer[],
38  int num_attributes,
39  float *vertex_buffer,
40  int num_coords_dim0,
41  int num_coords_dim1);
42 // @}
43 
44 /** Set the underlying MTLBuffer for a halide_buffer_t. This memory should be
45  * allocated using newBufferWithLength:options or similar and must
46  * have an extent large enough to cover that specified by the halide_buffer_t
47  * extent fields. The dev field of the halide_buffer_t must be NULL when this
48  * routine is called. This call can fail due to running out of memory
49  * or being passed an invalid buffer. The device and host dirty bits
50  * are left unmodified. */
51 extern int halide_metal_wrap_buffer(void *user_context, struct halide_buffer_t *buf, uint64_t buffer);
52 
53 /** Disconnect a halide_buffer_t from the memory it was previously
54  * wrapped around. Should only be called for a halide_buffer_t that
55  * halide_metal_wrap_buffer was previously called on. Frees any
56  * storage associated with the binding of the halide_buffer_t and the
57  * buffer, but does not free the MTLBuffer. The dev field of the
58  * halide_buffer_t will be NULL on return.
59  */
61 
62 /** Return the underlying MTLBuffer for a halide_buffer_t. This buffer must be
63  * valid on an Metal device, or not have any associated device
64  * memory. If there is no device memory (dev field is NULL), this
65  * returns 0.
66  */
67 extern uintptr_t halide_metal_get_buffer(void *user_context, struct halide_buffer_t *buf);
68 
69 /** Returns the offset associated with the Metal Buffer allocation via device_crop or device_slice. */
71 
72 struct halide_metal_device;
73 struct halide_metal_command_queue;
74 
75 /** This prototype is exported as applications will typically need to
76  * replace it to get Halide filters to execute on the same device and
77  * command queue used for other purposes. The halide_metal_device is an
78  * id <MTLDevice> and halide_metal_command_queue is an id <MTLCommandQueue>.
79  * No reference counting is done by Halide on these objects. They must remain
80  * valid until all off the following are true:
81  * - A balancing halide_metal_release_context has occurred for each
82  * halide_metal_acquire_context which returned the device/queue
83  * - All Halide filters using the context information have completed
84  * - All halide_buffer_t objects on the device have had
85  * halide_device_free called or have been detached via
86  * halide_metal_detach_buffer.
87  * - halide_device_release has been called on the interface returned from
88  * halide_metal_device_interface(). (This releases the programs on the context.)
89  */
90 extern int halide_metal_acquire_context(void *user_context, struct halide_metal_device **device_ret,
91  struct halide_metal_command_queue **queue_ret, bool create);
92 
93 /** This call balances each successfull halide_metal_acquire_context call.
94  * If halide_metal_acquire_context is replaced, this routine must be replaced
95  * as well.
96  */
98 
99 #ifdef __cplusplus
100 } // End extern "C"
101 #endif
102 
103 #endif // HALIDE_HALIDERUNTIMEMETAL_H
int8_t
signed __INT8_TYPE__ int8_t
Definition: runtime_internal.h:24
halide_metal_release_context
int halide_metal_release_context(void *user_context)
This call balances each successfull halide_metal_acquire_context call.
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:19
halide_metal_device_interface
const struct halide_device_interface_t * halide_metal_device_interface()
halide_metal_detach_buffer
int halide_metal_detach_buffer(void *user_context, struct halide_buffer_t *buf)
Disconnect a halide_buffer_t from the memory it was previously wrapped around.
halide_metal_acquire_context
int halide_metal_acquire_context(void *user_context, struct halide_metal_device **device_ret, struct halide_metal_command_queue **queue_ret, bool create)
This prototype is exported as applications will typically need to replace it to get Halide filters to...
halide_metal_initialize_kernels
int halide_metal_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 Metal runtime.
halide_metal_get_buffer
uintptr_t halide_metal_get_buffer(void *user_context, struct halide_buffer_t *buf)
Return the underlying MTLBuffer for a halide_buffer_t.
halide_metal_run
int halide_metal_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[], int num_attributes, float *vertex_buffer, int num_coords_dim0, int num_coords_dim1)
HalideRuntime.h
halide_metal_get_crop_offset
uint64_t halide_metal_get_crop_offset(void *user_context, struct halide_buffer_t *buf)
Returns the offset associated with the Metal Buffer allocation via device_crop or device_slice.
halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Definition: HalideRuntime.h:1404
buf
char * buf
Definition: printer.h:32
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:721
halide_metal_wrap_buffer
int halide_metal_wrap_buffer(void *user_context, struct halide_buffer_t *buf, uint64_t buffer)
Set the underlying MTLBuffer for a halide_buffer_t.
user_context
void * user_context
Definition: printer.h:33