2023-09-08 11:35:18 +02:00
|
|
|
/* GPU managment.
|
2018-06-25 17:03:09 +02:00
|
|
|
*
|
2023-01-07 17:20:15 +01:00
|
|
|
* Author: Daniel Krebs <github@daniel-krebs.net>
|
2023-09-08 11:35:18 +02:00
|
|
|
* SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2023-01-07 17:20:15 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-09-08 11:35:18 +02:00
|
|
|
*/
|
2018-06-25 17:03:09 +02:00
|
|
|
|
2018-04-13 15:59:34 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-05-15 17:35:45 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <villas/log.hpp>
|
2024-02-29 19:34:27 +01:00
|
|
|
#include <villas/memory.hpp>
|
|
|
|
#include <villas/memory_manager.hpp>
|
|
|
|
#include <villas/plugin.hpp>
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2018-04-13 15:59:34 +02:00
|
|
|
namespace villas {
|
|
|
|
namespace gpu {
|
|
|
|
|
2018-05-15 17:35:45 +02:00
|
|
|
class GpuAllocator;
|
|
|
|
|
|
|
|
class Gpu {
|
2024-02-29 19:34:27 +01:00
|
|
|
friend GpuAllocator;
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
public:
|
|
|
|
Gpu(int gpuId);
|
|
|
|
~Gpu();
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
bool init();
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
std::string getName() const;
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
GpuAllocator &getAllocator() const { return *allocator; }
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
bool makeAccessibleToPCIeAndVA(const MemoryBlock &mem);
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
// Make some memory block accssible for this GPU
|
|
|
|
bool makeAccessibleFromPCIeOrHostRam(const MemoryBlock &mem);
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
void memcpySync(const MemoryBlock &src, const MemoryBlock &dst, size_t size);
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
void memcpyKernel(const MemoryBlock &src, const MemoryBlock &dst,
|
|
|
|
size_t size);
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
MemoryTranslation translate(const MemoryBlock &dst);
|
2018-06-06 09:55:14 +02:00
|
|
|
|
2018-05-15 17:35:45 +02:00
|
|
|
private:
|
2024-02-29 19:34:27 +01:00
|
|
|
bool registerIoMemory(const MemoryBlock &mem);
|
|
|
|
bool registerHostMemory(const MemoryBlock &mem);
|
2018-05-15 17:35:45 +02:00
|
|
|
|
|
|
|
private:
|
2024-02-29 19:34:27 +01:00
|
|
|
class impl;
|
|
|
|
std::unique_ptr<impl> pImpl;
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
// Master, will be used to derived slave addr spaces for allocation
|
|
|
|
MemoryManager::AddressSpaceId masterPciEAddrSpaceId;
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
MemoryManager::AddressSpaceId slaveMemoryAddrSpaceId;
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
Logger logger;
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
int gpuId;
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
std::unique_ptr<GpuAllocator> allocator;
|
2018-05-15 17:35:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class GpuAllocator : public BaseAllocator<GpuAllocator> {
|
|
|
|
public:
|
2024-02-29 19:34:27 +01:00
|
|
|
static constexpr size_t GpuPageSize = 64UL << 10;
|
2018-07-20 16:46:55 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
GpuAllocator(Gpu &gpu);
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
std::string getName() const;
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
|
|
|
|
allocateBlock(size_t size);
|
2018-05-15 17:35:45 +02:00
|
|
|
|
|
|
|
private:
|
2024-02-29 19:34:27 +01:00
|
|
|
Gpu &gpu;
|
|
|
|
// TODO: replace by multimap (key is available memory)
|
|
|
|
std::list<std::unique_ptr<LinearAllocator>> chunks;
|
2018-05-15 17:35:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class GpuFactory : public Plugin {
|
|
|
|
public:
|
2024-02-29 19:34:27 +01:00
|
|
|
GpuFactory();
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
std::list<std::unique_ptr<Gpu>> make();
|
2018-05-15 17:35:45 +02:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
void run(void *);
|
2018-05-15 17:35:45 +02:00
|
|
|
|
|
|
|
private:
|
2024-02-29 19:34:27 +01:00
|
|
|
Logger logger;
|
2018-05-15 17:35:45 +02:00
|
|
|
};
|
|
|
|
|
2023-09-08 11:35:18 +02:00
|
|
|
} // namespace gpu
|
2024-02-29 19:34:27 +01:00
|
|
|
} // namespace villas
|