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, 22> 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"},
49 {
"vk_create_context",
"vk_destroy_context",
true},
50 {
"vk_create_command_pool",
"vk_destroy_command_pool"},
51 {
"vk_create_command_buffer",
"vk_destroy_command_buffer"},
52 {
"vk_create_pipeline_layout",
"vk_destroy_pipeline_layout"},
53 {
"vk_create_compute_pipeline",
"vk_destroy_compute_pipeline"},
54 {
"vk_create_descriptor_pool",
"vk_destroy_descriptor_pool"},
55 {
"Vulkan: Allocated memory for device region",
"Vulkan: Deallocated memory for device region"},
56 {
"Vulkan: Created buffer",
"Vulkan: Destroyed buffer"},
59 {
"wgpuCreateInstance",
"wgpuInstanceRelease",
true},
60 {
"wgpuDeviceCreateBuffer",
"wgpuBufferRelease"},
61 {
"wgpuDeviceCreateComputePipeline",
"wgpuComputePipelineRelease"},
67 for (
auto &o : object_types) {
68 if (
strstr(str, o.created)) {
71 }
else if (
strstr(str, o.destroyed)) {
80 for (
auto &o : object_types) {
81 if (o.live_count != 0 &&
82 !(allow_globals && o.is_global)) {
83 printf(
"Error! %d objects created by %s still live\n",
84 o.live_count, o.created);
87 if (o.is_global && o.total_created > max_globals) {
88 printf(
"Error! %d global objects created by %s, max is %d\n",
89 o.total_created, o.created, max_globals);
93 total += o.total_created;
95 if (!allow_none && total == 0) {
96 printf(
"Error! No objects created. Ensure gpu_debug is set, ");
97 printf(
"and record_gpu_debug is called from halide_print.\n");