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 int num_attributes, 38 float *vertex_buffer, 39 int num_coords_dim0, 40 int num_coords_dim1); 41 // @} 42 43 /** Set the underlying cuda device poiner for a buffer. The device 44 * pointer should be allocated using cuMemAlloc or similar and must 45 * have an extent large enough to cover that specified by the 46 * halide_buffer_t extent fields. The dev field of the halide_buffer_t 47 * must be NULL when this routine is called. This call can fail due to 48 * being passed an invalid device pointer. The device and host dirty 49 * bits are left unmodified. */ 50 extern int halide_cuda_wrap_device_ptr(void *user_context, struct halide_buffer_t *buf, uint64_t device_ptr); 51 52 /** Disconnect this halide_buffer_t from the device pointer it was 53 * previously wrapped around. Should only be called for a 54 * halide_buffer_t that halide_cuda_wrap_device_ptr was previously 55 * called on. The device field of the halide_buffer_t will be NULL on 56 * return. 57 */ 58 extern int halide_cuda_detach_device_ptr(void *user_context, struct halide_buffer_t *buf); 59 60 /** Return the underlying device pointer for a halide_buffer_t. This buffer 61 * must be valid on a Cuda device, or not have any associated device 62 * memory. If there is no device memory (dev field is NULL), this 63 * returns 0. 64 */ 65 extern uintptr_t halide_cuda_get_device_ptr(void *user_context, struct halide_buffer_t *buf); 66 67 /** Release any currently-unused device allocations back to the cuda 68 * driver. See halide_reuse_device_allocations. */ 69 extern int halide_cuda_release_unused_device_allocations(void *user_context); 70 71 #ifdef __cplusplus 72 } // End extern "C" 73 #endif 74 75 #endif // HALIDE_HALIDERUNTIMECUDA_H 76