1 #ifndef GPU_OBJECT_LIFETIME_H
2 #define GPU_OBJECT_LIFETIME_H
13 const char *
const created;
14 const char *
const destroyed;
19 ObjectType(
const char *created,
const char *destroyed,
bool is_global =
false)
20 : created(created), destroyed(destroyed),
21 is_global(is_global), total_created(0), live_count(0) {
25 std::array<ObjectType, 11> object_types = {{
26 {
"Caching compiled kernel:",
"Releasing cached compilation:"},
29 {
"clCreateContext",
"clReleaseContext",
true},
30 {
"clCreateCommandQueue",
"clReleaseCommandQueue",
true},
33 {
"clCreateBuffer",
"clReleaseMemObject"},
34 {
"clCreateKernel",
"clReleaseKernel"},
37 {
"cuCtxCreate",
"cuCtxDestroy",
true},
38 {
"cuMemAlloc",
"cuMemFree"},
41 {
"Allocating: MTLCreateSystemDefaultDevice",
"Releasing: MTLCreateSystemDefaultDevice",
true},
42 {
"Allocating: new_command_queue",
"Releasing: new_command_queue"},
45 {
"halide_remote_load_library",
"halide_remote_release_library"},
46 {
"ion_alloc",
"ion_free"},
52 for (
auto &o : object_types) {
53 if (
strstr(str, o.created)) {
56 }
else if (
strstr(str, o.destroyed)) {
65 for (
auto &o : object_types) {
66 if (o.live_count != 0 &&
67 !(allow_globals && o.is_global)) {
68 printf(
"Error! %d objects created by %s still live\n",
69 o.live_count, o.created);
72 if (o.is_global && o.total_created > max_globals) {
73 printf(
"Error! %d global objects created by %s, max is %d\n",
74 o.total_created, o.created, max_globals);
78 total += o.total_created;
80 if (!allow_none && total == 0) {
81 printf(
"Error! No objects created. Ensure gpu_debug is set, ");
82 printf(
"and record_gpu_debug is called from halide_print.\n");
int validate_gpu_object_lifetime(bool allow_globals, bool allow_none, int max_globals)
void record_gpu_debug(const char *str)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
const char * strstr(const char *, const char *)