1 #ifndef HALIDE_DEVICE_INTERFACE_H
2 #define HALIDE_DEVICE_INTERFACE_H
3 
4 #ifndef WEAK
5 #include "runtime_internal.h"
6 #endif
7 
8 extern "C" {
9 
10 struct halide_device_interface_impl_t {
11     // These next two methods are used to reference count the runtime code
12     // these function pointers point to. They should always be initialized
13     // to halide_use_jit_module and halide_release_jit_module and Halide's JIT
14     // arranges for this to reference count the container for the code. In AOT
15     // compilation, these are empty functions which do nothing.
16     void (*use_module)();
17     void (*release_module)();
18     int (*device_malloc)(void *user_context, struct halide_buffer_t *buf);
19     int (*device_free)(void *user_context, struct halide_buffer_t *buf);
20     int (*device_sync)(void *user_context, struct halide_buffer_t *buf);
21     int (*device_release)(void *user_context);
22     int (*copy_to_host)(void *user_context, struct halide_buffer_t *buf);
23     int (*copy_to_device)(void *user_context, struct halide_buffer_t *buf);
24     int (*device_and_host_malloc)(void *user_context, struct halide_buffer_t *buf);
25     int (*device_and_host_free)(void *user_context, struct halide_buffer_t *buf);
26     int (*buffer_copy)(void *user_context, struct halide_buffer_t *src,
27                        const struct halide_device_interface_t *dst_device_interface, struct halide_buffer_t *dst);
28     int (*device_crop)(void *user_context,
29                        const struct halide_buffer_t *src,
30                        struct halide_buffer_t *dst);
31     int (*device_slice)(void *user_context,
32                         const struct halide_buffer_t *src,
33                         int slice_dim, int slice_pos,
34                         struct halide_buffer_t *dst);
35     int (*device_release_crop)(void *user_context,
36                                struct halide_buffer_t *buf);
37     int (*wrap_native)(void *user_context, struct halide_buffer_t *buf, uint64_t handle);
38     int (*detach_native)(void *user_context, struct halide_buffer_t *buf);
39 };
40 
41 extern WEAK int halide_default_device_and_host_malloc(void *user_context, struct halide_buffer_t *buf,
42                                                       const struct halide_device_interface_t *device_interface);
43 extern WEAK int halide_default_device_and_host_free(void *user_context, struct halide_buffer_t *buf,
44                                                     const struct halide_device_interface_t *device_interface);
45 extern WEAK int halide_default_buffer_copy(void *user_context, struct halide_buffer_t *src,
46                                            const struct halide_device_interface_t *dst_device_interface,
47                                            struct halide_buffer_t *dst);
48 extern WEAK int halide_default_device_crop(void *user_context, const struct halide_buffer_t *src,
49                                            struct halide_buffer_t *dst);
50 extern WEAK int halide_default_device_slice(void *user_context, const struct halide_buffer_t *src,
51                                             int slice_dim, int slice_pos, struct halide_buffer_t *dst);
52 extern WEAK int halide_default_device_release_crop(void *user_context, struct halide_buffer_t *buf);
53 extern WEAK int halide_default_device_wrap_native(void *user_context, struct halide_buffer_t *buf, uint64_t handle);
54 extern WEAK int halide_default_device_detach_native(void *user_context, struct halide_buffer_t *buf);
55 }
56 
57 #endif  // HALIDE_DEVICE_INTERFACE_H
58