2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-12-06 22:33:02 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "CL/cl.h"
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
class Device;
|
|
|
|
class GraphicsAllocation;
|
|
|
|
class CommandStreamReceiver;
|
|
|
|
class MemoryManager;
|
|
|
|
|
|
|
|
class SVMAllocsManager {
|
|
|
|
public:
|
|
|
|
class MapBasedAllocationTracker {
|
|
|
|
public:
|
|
|
|
void insert(GraphicsAllocation &);
|
|
|
|
void remove(GraphicsAllocation &);
|
|
|
|
GraphicsAllocation *get(const void *);
|
|
|
|
size_t getNumAllocs() const { return allocs.size(); };
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::map<const void *, GraphicsAllocation *> allocs;
|
|
|
|
};
|
|
|
|
|
|
|
|
SVMAllocsManager(MemoryManager *memoryManager);
|
2019-04-03 17:22:04 +08:00
|
|
|
void *createSVMAlloc(size_t size, cl_mem_flags flags);
|
2017-12-21 07:45:38 +08:00
|
|
|
GraphicsAllocation *getSVMAlloc(const void *ptr);
|
|
|
|
void freeSVMAlloc(void *ptr);
|
|
|
|
size_t getNumAllocs() const { return SVMAllocs.getNumAllocs(); }
|
2018-12-06 22:33:02 +08:00
|
|
|
static bool memFlagIsReadOnly(cl_svm_mem_flags flags);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
MapBasedAllocationTracker SVMAllocs;
|
|
|
|
MemoryManager *memoryManager;
|
|
|
|
std::mutex mtx;
|
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|