1/*******************************************************************************
2* Copyright 2019-2020 Intel Corporation
3*
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
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
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.
15*******************************************************************************/
16
17#include "memory_tracking.hpp"
18#include "primitive_exec_types.hpp"
19
20#include "engine.hpp"
21
22namespace dnnl {
23namespace impl {
24namespace memory_tracking {
25
26const void *registry_t::entry_t::compute_ptr(const void *base_ptr) const {
27 if (size == 0) return nullptr;
28 assert(base_ptr != nullptr);
29
30 char *ptr = (char *)base_ptr + offset;
31 char *aligned_ptr = utils::align_ptr<char>(ptr, get_alignment(alignment));
32
33 if (memory_debug::is_mem_debug_overflow() && size % getpagesize() != 0) {
34 // Align to end of page
35 size_t page_end_offset = utils::rnd_up(size, alignment) % getpagesize();
36 aligned_ptr += getpagesize() - page_end_offset;
37 if (aligned_ptr - getpagesize() > ptr) aligned_ptr -= getpagesize();
38 assert((size_t)aligned_ptr % alignment == 0);
39 }
40
41 assert(aligned_ptr + size <= ptr + capacity - buffer_protect_size());
42 return (const void *)aligned_ptr;
43}
44
45char *grantor_t::get_host_storage_ptr(const memory_storage_t *storage) const {
46 assert(storage != nullptr);
47 return (char *)exec_ctx_->host_ptr(storage);
48}
49
50bool grantor_t::is_cpu_engine(const memory_storage_t *mem_storage) const {
51 if (!mem_storage) return false;
52 auto engine = mem_storage->engine();
53 assert(engine);
54 if (engine->kind() == engine_kind::cpu) return true;
55 return false;
56}
57
58} // namespace memory_tracking
59} // namespace impl
60} // namespace dnnl
61