2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <unordered_map>
33 MemoryTraits(size_t init_counter_value, size_t size_of_allocated_memory)
34 : ref_counter(init_counter_value), size(size_of_allocated_memory)
45 bool isActive() { return _is_trace_not_available || _is_recursion_detected; }
48 void markTraceAsReady() { _is_trace_not_available = false; }
49 void markTraceAsNotReady() { _is_trace_not_available = true; }
50 void signalizeAboutPossibleRecursion() { _is_recursion_detected = true; }
51 void signalizeThatDangerOfRecursionHasPassed() { _is_recursion_detected = false; }
54 static bool _is_trace_not_available;
55 static thread_local bool _is_recursion_detected;
60 Trace(const Trace &) = delete;
61 const Trace &operator=(const Trace &) = delete;
63 void logAllocationEvent(void *memory_ptr, size_t size_of_allocated_space_in_bytes);
64 void logAllocationEvent(cl_mem memory_ptr, size_t size_of_allocated_space_in_bytes);
65 void logDeallocationEvent(void *memory_ptr);
66 void logDeallocationEvent(cl_mem memory_ptr);
71 const char *getLogFileNameFromEnvVariable(const char *env_variable_name);
76 size_t _total_allocated_bytes_on_cpu = 0;
77 size_t _total_deallocated_bytes_on_cpu = 0;
78 size_t _peak_heap_usage_on_cpu = 0;
79 size_t _total_allocated_bytes_on_gpu = 0;
80 size_t _total_deallocated_bytes_on_gpu = 0;
81 size_t _peak_heap_usage_on_gpu = 0;
82 std::unordered_map<void *, size_t> _memory_in_use_on_cpu;
83 std::unordered_map<cl_mem, MemoryTraits> _memory_in_use_on_gpu;