Commit a07588df authored by pruthvi's avatar pruthvi

- move Allocator abstract class to runtime namespace

- provide default implementation for allocator and deallocators
parent 43b1b2cd
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// 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.
//*****************************************************************************
#include "ngraph/runtime/allocator.hpp"
void* ngraph::runtime::Allocator::Malloc(void*, size_t size, size_t alignment)
{
void* ptr = malloc(size);
// check for exception
if (size != 0 && !ptr)
{
throw ngraph_error("malloc failed to allocate memory of size " + std::to_string(size));
throw std::bad_alloc();
}
return ptr;
}
void ngraph::runtime::Allocator::Free(void* ptr, void*)
{
if (ptr)
{
free(ptr);
}
}
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// 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.
//*****************************************************************************
#pragma once
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include "ngraph/except.hpp"
#include "ngraph/util.hpp"
namespace ngraph
{
namespace runtime
{
class Allocator;
}
}
// Abstarct class for the allocator, for allocating and deallocating device memory
class ngraph::runtime::Allocator
{
public:
virtual ~Allocator() = default;
virtual void* Malloc(void*, size_t size, size_t alignment);
virtual void Free(void* ptr, void*);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment