-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into dev-hardware
- Loading branch information
Showing
33 changed files
with
403 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,49 @@ | ||
#include "functions.cuh" | ||
#include "hardware/devices/nvidia.h" | ||
#include "hardware/devices/nvidia.h" | ||
#include "hardware/mem_pool.h" | ||
#include "memory.cuh" | ||
|
||
#ifdef USE_CUDA | ||
#include "memory.hh" | ||
#include <cuda_runtime.h> | ||
|
||
#define CUDA_ASSERT(STATUS) \ | ||
if (auto status = (STATUS); status != cudaSuccess) { \ | ||
RUNTIME_ERROR(fmt::format("cuda failed on \"" #STATUS "\" with \"{}\" ({})", \ | ||
cudaGetErrorString(status), (int) status)); \ | ||
} | ||
#endif | ||
|
||
namespace refactor::hardware { | ||
|
||
static Arc<Memory> cudaMemory(int32_t card) { | ||
#ifdef USE_CUDA | ||
ASSERT(0 <= card && card < getDeviceCount(), "Invalid card id: {}", card); | ||
setDevice(card); | ||
auto [free, total] = getMemInfo(); | ||
int deviceCount; | ||
CUDA_ASSERT(cudaGetDeviceCount(&deviceCount)); | ||
ASSERT(0 <= card && card < deviceCount, "Invalid card id: {}", card); | ||
CUDA_ASSERT(cudaSetDevice(card)); | ||
|
||
size_t free, total; | ||
CUDA_ASSERT(cudaMemGetInfo(&free, &total)); | ||
auto size = std::min(free, std::max(5ul << 30, total * 4 / 5)); | ||
fmt::println("initializing Nvidia GPU {}, memory {} / {}, alloc {}", | ||
card, free, total, size); | ||
cudaDeviceProp prop; | ||
CUDA_ASSERT(cudaGetDeviceProperties(&prop, 0)); | ||
size_t alignment = prop.textureAlignment; | ||
fmt::println("initializing Nvidia GPU {}, memory {} / {}, alloc {}, alignment {}", | ||
card, free, total, size, alignment); | ||
return std::make_shared<MemPool>( | ||
std::make_shared<NvidiaMemory>(), | ||
size, | ||
256ul); | ||
alignment); | ||
#else | ||
return nullptr; | ||
#endif | ||
} | ||
|
||
Nvidia::Nvidia(int32_t card) : Device(card, cudaMemory(card)) {} | ||
|
||
void Nvidia::setContext() const noexcept { | ||
setDevice(_card); | ||
void Nvidia::setContext() const { | ||
#ifdef USE_CUDA | ||
CUDA_ASSERT(cudaSetDevice(_card)); | ||
#endif | ||
} | ||
|
||
}// namespace refactor::hardware |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.