memory_manager.cpp 1.42 KB
Newer Older
Nagy Mostafa's avatar
Nagy Mostafa committed
1
//*****************************************************************************
nmostafa's avatar
nmostafa committed
2
// Copyright 2017-2019 Intel Corporation
Nagy Mostafa's avatar
Nagy Mostafa committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
//
// 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.
//*****************************************************************************

17 18 19
// NOTE: This file follows nGraph format style and MLIR naming convention since it does
// not expose public API to the rest of nGraph codebase and heavily depends on MLIR API.

20
#include "memory_manager.hpp"
21
#include <memory>
Diego Caballero's avatar
Diego Caballero committed
22
#include "ngraph/ngraph_visibility.hpp"
23

24
using namespace ngraph::runtime::ngmlir;
Nagy Mostafa's avatar
Nagy Mostafa committed
25 26

/// Call back to allocate memory for temps from JIT'ed code
27
extern "C" NGRAPH_API void* __mlir_allocate(MLIRMemMgr* memMgr, size_t size)
Nagy Mostafa's avatar
Nagy Mostafa committed
28
{
29
    return memMgr->allocate(size);
Nagy Mostafa's avatar
Nagy Mostafa committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
}

void* MLIRMemMgr::allocate(size_t size)
{
    void* ptr = malloc(size);
    ptrList.push_back(ptr);
    return ptr;
}

void MLIRMemMgr::freeAll()
{
    for (auto p : ptrList)
    {
        free(p);
    }
}