1 #include "HalideRuntime.h" 2 3 /** \file JIT module reference counting support. */ 4 5 /* The runtime can manipulate a reference count on its code because 6 * some allocated data structures returned from the runtime may 7 * contain function pointers back to this code. For JIT, the module 8 * instantiation logic sets values into the globals below to allow 9 * tracking which JITModule the code is in. (The goal being to 10 * decouple the runtime from having to know details of the Halide JIT 11 * support.) 12 * 13 * The reference count is increased when a new device allocation is 14 * made through the device interface part of the runtime and decreased 15 * when such an allocation is freed. The mechanism could be used in 16 * other palces however. 17 */ 18 19 extern "C" { 20 21 WEAK void *halide_jit_module_argument = NULL; 22 WEAK void (*halide_jit_module_adjust_ref_count)(void *arg, int32_t count) = NULL; 23 halide_use_jit_module()24WEAK void halide_use_jit_module() { 25 if (halide_jit_module_adjust_ref_count == NULL) { 26 return; 27 } else { 28 (*halide_jit_module_adjust_ref_count)(halide_jit_module_argument, 1); 29 } 30 } 31 halide_release_jit_module()32WEAK void halide_release_jit_module() { 33 if (halide_jit_module_adjust_ref_count == NULL) { 34 return; 35 } else { 36 (*halide_jit_module_adjust_ref_count)(halide_jit_module_argument, -1); 37 } 38 } 39 } 40