1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
10 #include <details/ie_exception.hpp>
12 #include "gna_plugin_log.hpp"
14 void *AllocateMemory(uint32_t num_memory_bytes, const char *ptr_name) {
15 void *ptr_memory = _mm_malloc(num_memory_bytes, 64);
16 if (ptr_memory == NULL) {
17 THROW_GNA_EXCEPTION << "Memory allocation failed for " << ptr_name;
19 memset(ptr_memory, 0, num_memory_bytes);
24 void FreeMemory(void *ptr_memory) {
25 if (ptr_memory != NULL) {
31 int32_t MemoryOffset(void *ptr_target, void *ptr_base) {
32 uint64_t target = (uint64_t) ptr_target;
33 uint64_t base = (uint64_t) ptr_base;
34 if (target == 0) { // handle NULL pointers separately
36 } else if (target < base) {
37 THROW_GNA_EXCEPTION << "Error: target address value " << target<< " is less than base address " << base << " in MemoryOffset()";
39 uint64_t diff = target - base;
40 if (diff > 0x7fffffff) {
41 THROW_GNA_EXCEPTION << "Error: target address value " << target << " too far from base address " << base << " in MemoryOffset()!";
43 return ((int32_t) diff);