Halide
HalideRuntimeOpenCL.h
Go to the documentation of this file.
1 #ifndef HALIDE_HALIDERUNTIMEOPENCL_H
2 #define HALIDE_HALIDERUNTIMEOPENCL_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 OpenCL runtime.
17  */
18 
19 #define HALIDE_RUNTIME_OPENCL
20 
22 
23 /** These are forward declared here to allow clients to override the
24  * Halide OpenCL runtime. Do not call them. */
25 // @{
26 extern int halide_opencl_initialize_kernels(void *user_context, void **state_ptr,
27  const char *src, int size);
28 extern int halide_opencl_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  int num_attributes,
38  float *vertex_buffer,
39  int num_coords_dim0,
40  int num_coords_dim1);
41 // @}
42 
43 /** Set the platform name for OpenCL to use (e.g. "Intel" or
44  * "NVIDIA"). The argument is copied internally. The opencl runtime
45  * will select a platform that includes this as a substring. If never
46  * called, Halide uses the environment variable HL_OCL_PLATFORM_NAME,
47  * or defaults to the first available platform. */
48 extern void halide_opencl_set_platform_name(const char *n);
49 
50 /** Halide calls this to get the desired OpenCL platform
51  * name. Implement this yourself to use a different platform per
52  * user_context. The default implementation returns the value set by
53  * halide_set_ocl_platform_name, or the value of the environment
54  * variable HL_OCL_PLATFORM_NAME. The output is valid until the next
55  * call to halide_set_ocl_platform_name. */
56 extern const char *halide_opencl_get_platform_name(void *user_context);
57 
58 /** Set the device type for OpenCL to use. The argument is copied
59  * internally. It must be "cpu", "gpu", or "acc". If never called,
60  * Halide uses the environment variable HL_OCL_DEVICE_TYPE. */
61 extern void halide_opencl_set_device_type(const char *n);
62 
63 /** Halide calls this to gets the desired OpenCL device
64  * type. Implement this yourself to use a different device type per
65  * user_context. The default implementation returns the value set by
66  * halide_set_ocl_device_type, or the environment variable
67  * HL_OCL_DEVICE_TYPE. The result is valid until the next call to
68  * halide_set_ocl_device_type. */
69 extern const char *halide_opencl_get_device_type(void *user_context);
70 
71 /** Set the additional build options for OpenCL to use. The argument
72  * is copied internally. If never called,
73  * Halide uses the environment variable HL_OCL_BUILD_OPTIONS. */
74 extern void halide_opencl_set_build_options(const char *n);
75 
76 /** Halide calls this to gets the additional build options for OpenCL to
77  * use. Implement this yourself to use a different build options per
78  * user_context. The default implementation returns the value set by
79  * halide_opencl_set_build_options, or the environment variable
80  * HL_OCL_BUILD_OPTIONS. The result is valid until the next call to
81  * halide_opencl_set_build_options. */
82 extern const char *halide_opencl_get_build_options(void *user_context);
83 
84 /** Set the underlying cl_mem for a halide_buffer_t. This memory should be
85  * allocated using clCreateBuffer or similar and must have an extent
86  * large enough to cover that specified by the halide_buffer_t extent
87  * fields. The dev field of the halide_buffer_t must be NULL when this
88  * routine is called. This call can fail due to running out of memory
89  * or being passed an invalid device pointer. The device and host
90  * dirty bits are left unmodified. */
91 extern int halide_opencl_wrap_cl_mem(void *user_context, struct halide_buffer_t *buf, uint64_t device_ptr);
92 
93 /** Disconnect a halide_buffer_t from the memory it was previously
94  * wrapped around. Should only be called for a halide_buffer_t that
95  * halide_opencl_wrap_device_ptr was previously called on. Frees any
96  * storage associated with the binding of the halide_buffer_t and the
97  * device pointer, but does not free the cl_mem. The dev field of the
98  * halide_buffer_t will be NULL on return.
99  */
101 
102 /** Return the underlying cl_mem for a halide_buffer_t. This buffer must be
103  * valid on an OpenCL device, or not have any associated device
104  * memory. If there is no device memory (dev field is NULL), this
105  * returns 0.
106  */
107 extern uintptr_t halide_opencl_get_cl_mem(void *user_context, struct halide_buffer_t *buf);
108 
109 /** Returns the offset associated with the OpenCL memory allocation via device_crop or device_slice. */
111 
112 #ifdef __cplusplus
113 } // End extern "C"
114 #endif
115 
116 #endif // HALIDE_HALIDERUNTIMEOPENCL_H
int8_t
signed __INT8_TYPE__ int8_t
Definition: runtime_internal.h:24
halide_opencl_get_crop_offset
uint64_t halide_opencl_get_crop_offset(void *user_context, halide_buffer_t *buf)
Returns the offset associated with the OpenCL memory allocation via device_crop or device_slice.
halide_opencl_get_device_type
const char * halide_opencl_get_device_type(void *user_context)
Halide calls this to gets the desired OpenCL device type.
halide_opencl_get_build_options
const char * halide_opencl_get_build_options(void *user_context)
Halide calls this to gets the additional build options for OpenCL to use.
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:19
halide_opencl_set_platform_name
void halide_opencl_set_platform_name(const char *n)
Set the platform name for OpenCL to use (e.g.
halide_opencl_initialize_kernels
int halide_opencl_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 OpenCL runtime.
halide_opencl_device_interface
const struct halide_device_interface_t * halide_opencl_device_interface()
halide_opencl_get_platform_name
const char * halide_opencl_get_platform_name(void *user_context)
Halide calls this to get the desired OpenCL platform name.
halide_opencl_get_cl_mem
uintptr_t halide_opencl_get_cl_mem(void *user_context, struct halide_buffer_t *buf)
Return the underlying cl_mem for a halide_buffer_t.
halide_opencl_wrap_cl_mem
int halide_opencl_wrap_cl_mem(void *user_context, struct halide_buffer_t *buf, uint64_t device_ptr)
Set the underlying cl_mem for a halide_buffer_t.
halide_opencl_set_device_type
void halide_opencl_set_device_type(const char *n)
Set the device type for OpenCL to use.
HalideRuntime.h
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_opencl_detach_cl_mem
int halide_opencl_detach_cl_mem(void *user_context, struct halide_buffer_t *buf)
Disconnect a halide_buffer_t from the memory it was previously wrapped around.
halide_opencl_set_build_options
void halide_opencl_set_build_options(const char *n)
Set the additional build options for OpenCL to use.
user_context
void * user_context
Definition: printer.h:33
halide_opencl_run
int halide_opencl_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)