1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
4 // util.cpp : various utility functions for debugging, file i/o, etc.
12 #include <details/ie_exception.hpp>
14 #include "gna_plugin_log.hpp"
16 void *AllocateMemory(uint32_t num_memory_bytes, const char *ptr_name) {
17 void *ptr_memory = _mm_malloc(num_memory_bytes, 64);
18 if (ptr_memory == NULL) {
19 THROW_GNA_EXCEPTION << "Memory allocation failed for " << ptr_name;
21 memset(ptr_memory, 0, num_memory_bytes);
26 void FreeMemory(void *ptr_memory) {
27 if (ptr_memory != NULL) {
33 int32_t MemoryOffset(void *ptr_target, void *ptr_base) {
34 uint64_t target = (uint64_t) ptr_target;
35 uint64_t base = (uint64_t) ptr_base;
36 if (target == 0) { // handle NULL pointers separately
38 } else if (target < base) {
39 THROW_GNA_EXCEPTION << "Error: target address value " << target<< " is less than base address " << base << " in MemoryOffset()";
41 uint64_t diff = target - base;
42 if (diff > 0x7fffffff) {
43 THROW_GNA_EXCEPTION << "Error: target address value " << target << " too far from base address " << base << " in MemoryOffset()!";
45 return ((int32_t) diff);