mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00

This was neccessary in order to make the memory available via GDRcopy when multiple small allocations were made. cudaMalloc() would return multiple memory chunks located in the same GPU page, which GDRcopy pretty much dislikes (`gdrdrv:offset != 0 is not supported`). As a side effect, this will keep the number of BAR-mappings done via GDRcopy low, because they seem to be quite limited.
94 lines
1.7 KiB
C++
94 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <sstream>
|
|
|
|
#include <plugin.hpp>
|
|
#include <memory_manager.hpp>
|
|
#include <memory.hpp>
|
|
#include <villas/log.hpp>
|
|
|
|
|
|
namespace villas {
|
|
namespace gpu {
|
|
|
|
class GpuAllocator;
|
|
|
|
class Gpu {
|
|
friend GpuAllocator;
|
|
public:
|
|
Gpu(int gpuId);
|
|
~Gpu();
|
|
|
|
bool init();
|
|
|
|
std::string getName() const;
|
|
|
|
GpuAllocator& getAllocator() const
|
|
{ return *allocator; }
|
|
|
|
|
|
bool makeAccessibleToPCIeAndVA(const MemoryBlock& mem);
|
|
|
|
/// Make some memory block accssible for this GPU
|
|
bool makeAccessibleFromPCIeOrHostRam(const MemoryBlock& mem);
|
|
|
|
void memcpySync(const MemoryBlock& src, const MemoryBlock& dst, size_t size);
|
|
|
|
void memcpyKernel(const MemoryBlock& src, const MemoryBlock& dst, size_t size);
|
|
|
|
MemoryTranslation
|
|
translate(const MemoryBlock& dst);
|
|
|
|
private:
|
|
bool registerIoMemory(const MemoryBlock& mem);
|
|
bool registerHostMemory(const MemoryBlock& mem);
|
|
|
|
private:
|
|
class impl;
|
|
std::unique_ptr<impl> pImpl;
|
|
|
|
// master, will be used to derived slave addr spaces for allocation
|
|
MemoryManager::AddressSpaceId masterPciEAddrSpaceId;
|
|
|
|
MemoryManager::AddressSpaceId slaveMemoryAddrSpaceId;
|
|
|
|
SpdLogger logger;
|
|
|
|
int gpuId;
|
|
|
|
std::unique_ptr<GpuAllocator> allocator;
|
|
};
|
|
|
|
|
|
class GpuAllocator : public BaseAllocator<GpuAllocator> {
|
|
public:
|
|
static constexpr size_t GpuPageSize = 64UL << 10;
|
|
|
|
GpuAllocator(Gpu& gpu);
|
|
|
|
std::string getName() const;
|
|
|
|
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
|
|
allocateBlock(size_t size);
|
|
|
|
private:
|
|
Gpu& gpu;
|
|
// TODO: replace by multimap (key is available memory)
|
|
std::list<std::unique_ptr<LinearAllocator>> chunks;
|
|
};
|
|
|
|
class GpuFactory : public Plugin {
|
|
public:
|
|
GpuFactory();
|
|
|
|
std::list<std::unique_ptr<Gpu>>
|
|
make();
|
|
|
|
void run(void*);
|
|
|
|
private:
|
|
SpdLogger logger;
|
|
};
|
|
|
|
} // namespace villas
|
|
} // namespace gpu
|