Download ei-cpp-export/edge-impulse-sdk/dsp/memory.hpp from luisomoreau/fomo-face-detection: direct link, hf CLI and curl.
- Browser
- Download file 8.05 kB
-
https://huggingface.co/luisomoreau/fomo-face-detection/resolve/main/ei-cpp-export/edge-impulse-sdk/dsp/memory.hpp
- Command line
-
hf download hf://luisomoreau/fomo-face-detection/ei-cpp-export/edge-impulse-sdk/dsp/memory.hpp
-
curl -L -o memory.hpp https://huggingface.co/luisomoreau/fomo-face-detection/resolve/main/ei-cpp-export/edge-impulse-sdk/dsp/memory.hpp
8.05 kB
| /* | |
| * Copyright (c) 2022 EdgeImpulse Inc. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, | |
| * software distributed under the License is distributed on an "AS | |
| * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | |
| * express or implied. See the License for the specific language | |
| * governing permissions and limitations under the License. | |
| * | |
| * SPDX-License-Identifier: Apache-2.0 | |
| */ | |
| // clang-format off | |
| extern size_t ei_memory_in_use; | |
| extern size_t ei_memory_peak_use; | |
| typedef std::unique_ptr<void, void(*)(void*)> ei_unique_ptr_t; | |
| namespace ei { | |
| /** | |
| * These are macros used to track allocations when running DSP processes. | |
| * Enable memory tracking through the EIDSP_TRACK_ALLOCATIONS macro. | |
| */ | |
| /** | |
| * Register a manual allocation (malloc or calloc). | |
| * Typically you want to use ei::matrix_t types, as they keep track automatically. | |
| * @param bytes Number of bytes allocated | |
| */ | |
| /** | |
| * Register a matrix allocation. Don't call this function yourself, | |
| * matrices already track this automatically. | |
| * @param rows Number of rows | |
| * @param cols Number of columns | |
| * @param type_size Size of the data type | |
| */ | |
| /** | |
| * Register free'ing manually allocated memory (allocated through malloc/calloc) | |
| * @param bytes Number of bytes free'd | |
| */ | |
| /** | |
| * Register a matrix free. Don't call this function yourself, | |
| * matrices already track this automatically. | |
| * @param rows Number of rows | |
| * @param cols Number of columns | |
| * @param type_size Size of the data type | |
| */ | |
| class memory { | |
| public: | |
| /** | |
| * Allocate a new block of memory | |
| * @param size The size of the memory block, in bytes. | |
| */ | |
| static void *ei_wrapped_malloc(const char *fn, const char *file, int line, size_t size) { | |
| void *ptr = ei_malloc(size); | |
| if (ptr) { | |
| ei_dsp_register_alloc_internal(fn, file, line, size, ptr); | |
| } | |
| return ptr; | |
| } | |
| /** | |
| * Allocates a block of memory for an array of num elements, each of them size bytes long, | |
| * and initializes all its bits to zero. | |
| * @param num Number of elements to allocate | |
| * @param size Size of each element | |
| */ | |
| static void *ei_wrapped_calloc(const char *fn, const char *file, int line, size_t num, size_t size) { | |
| void *ptr = ei_calloc(num, size); | |
| if (ptr) { | |
| ei_dsp_register_alloc_internal(fn, file, line, num * size, ptr); | |
| } | |
| return ptr; | |
| } | |
| /** | |
| * Deallocate memory previously allocated by a call to calloc, malloc, or realloc. | |
| * @param ptr Pointer to a memory block previously allocated with malloc, calloc or realloc. | |
| * @param size Size of the block of memory previously allocated. | |
| */ | |
| static void ei_wrapped_free(const char *fn, const char *file, int line, void *ptr, size_t size) { | |
| ei_free(ptr); | |
| ei_dsp_register_free_internal(fn, file, line, size, ptr); | |
| } | |
| }; | |
| } // namespace ei | |
| // clang-format on | |