1/*******************************************************************************
2* Copyright 2020-2022 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 "common/memory_storage.hpp"
18#include "common/engine.hpp"
19#include "common/memory.hpp"
20
21#include <assert.h>
22
23namespace dnnl {
24namespace impl {
25
26status_t memory_storage_t::init(unsigned flags, size_t size, void *handle) {
27 assert(flags & (memory_flags_t::alloc | memory_flags_t::use_runtime_ptr));
28 if (flags & memory_flags_t::alloc) {
29 assert(!handle);
30 if (size == 0) return status::success;
31 return init_allocate(size);
32 }
33
34 assert(flags & memory_flags_t::use_runtime_ptr);
35 return set_data_handle(handle);
36}
37
38memory_storage_t::memory_storage_t(
39 engine_t *engine, const memory_storage_t *parent_storage)
40 : parent_storage_(parent_storage) {
41 engine_ = engine;
42 if (engine_) engine_->retain();
43}
44
45memory_storage_t::~memory_storage_t() {
46 if (engine_) engine_->release();
47};
48
49} // namespace impl
50} // namespace dnnl
51