-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ERS fields definitions and CUDA util
* Doc added to ERS fields. Some fields now correctly parsed. * Cuda device initialization and separate cuda_util module. * Fix E2E problems when stashing E2E dir
- Loading branch information
1 parent
4e61011
commit bbaa0d3
Showing
22 changed files
with
506 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
list(APPEND CUDA_UTIL_INCLUDE_DIRS | ||
${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
list(APPEND CUDA_UTIL_SOURCES | ||
${CMAKE_CURRENT_LIST_DIR}/cuda_device.cu | ||
${CMAKE_CURRENT_LIST_DIR}/cuda_device_init.cu | ||
${CMAKE_CURRENT_LIST_DIR}/cufft_plan.cc | ||
${CMAKE_CURRENT_LIST_DIR}/device_padded_image.cu | ||
${CMAKE_CURRENT_LIST_DIR}/memory_policy.cc | ||
) | ||
|
||
add_library(cuda-util-static STATIC ${CUDA_UTIL_SOURCES}) | ||
target_include_directories(cuda-util-static | ||
PUBLIC | ||
${CUDA_UTIL_INCLUDE_DIRS} | ||
) | ||
target_link_libraries(cuda-util-static | ||
PUBLIC | ||
CUDA::cudart | ||
app-static | ||
) | ||
set_target_properties(cuda-util-static | ||
PROPERTIES | ||
OUTPUT_NAME cuda-util | ||
) |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* ENVISAT and ERS ASAR instrument focusser for QA4EO activity (c) by CGI Estonia AS | ||
* | ||
* ENVISAT and ERS ASAR instrument focusser for QA4EO activity is licensed under a | ||
* Creative Commons Attribution-ShareAlike 4.0 International License. | ||
* | ||
* You should have received a copy of the license along with this | ||
* work. If not, see http://creativecommons.org/licenses/by-sa/4.0/ | ||
*/ | ||
|
||
#include "cuda_device.h" | ||
|
||
#include <cuda_runtime_api.h> | ||
|
||
#include "cuda_util.h" | ||
|
||
namespace alus::cuda { | ||
|
||
CudaDevice::CudaDevice(int device_nr, void* device_prop) : device_nr_{device_nr} { | ||
cudaDeviceProp* dev = reinterpret_cast<cudaDeviceProp*>(device_prop); | ||
cc_major_ = dev->major; | ||
cc_minor_ = dev->minor; | ||
name_ = dev->name; | ||
sm_count_ = dev->multiProcessorCount; | ||
max_threads_per_sm_ = dev->maxThreadsPerMultiProcessor; | ||
warp_size_ = dev->warpSize; | ||
total_global_memory_ = dev->totalGlobalMem; | ||
alignment_ = dev->textureAlignment; | ||
} | ||
|
||
void CudaDevice::Set() const { | ||
CHECK_CUDA_ERR(cudaSetDevice(device_nr_)); | ||
} | ||
|
||
size_t CudaDevice::GetFreeGlobalMemory() const { | ||
Set(); | ||
size_t total; | ||
size_t free; | ||
CHECK_CUDA_ERR(cudaMemGetInfo(&free, &total)); | ||
|
||
return free; | ||
} | ||
|
||
} // namespace alus::cuda |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* ENVISAT and ERS ASAR instrument focusser for QA4EO activity (c) by CGI Estonia AS | ||
* | ||
* ENVISAT and ERS ASAR instrument focusser for QA4EO activity is licensed under a | ||
* Creative Commons Attribution-ShareAlike 4.0 International License. | ||
* | ||
* You should have received a copy of the license along with this | ||
* work. If not, see http://creativecommons.org/licenses/by-sa/4.0/ | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <string> | ||
#include <string_view> | ||
|
||
namespace alus::cuda { | ||
class CudaDevice final { | ||
public: | ||
CudaDevice() = delete; | ||
/* | ||
* Parses GPU device properties from 'cudaDeviceProp' struct pointer. | ||
* It is opaque one here in order to not include CUDA SDK headers to host compilation. | ||
*/ | ||
CudaDevice(int device_nr, void* device_prop); | ||
|
||
void Set() const; | ||
|
||
[[nodiscard]] int GetDeviceNr() const { return device_nr_; } | ||
[[nodiscard]] std::string_view GetName() const { return name_; } | ||
[[nodiscard]] size_t GetCcMajor() const { return cc_major_; } | ||
[[nodiscard]] size_t GetCcMinor() const { return cc_minor_; } | ||
[[nodiscard]] size_t GetSmCount() const { return sm_count_; } | ||
[[nodiscard]] size_t GetMaxThreadsPerSm() const { return max_threads_per_sm_; } | ||
[[nodiscard]] size_t GetWarpSize() const { return warp_size_; } | ||
[[nodiscard]] size_t GetTotalGlobalMemory() const { return total_global_memory_; }; | ||
[[nodiscard]] size_t GetFreeGlobalMemory() const; | ||
[[nodiscard]] size_t GetMemoryAlignment() const { return alignment_; } | ||
|
||
private: | ||
int device_nr_; | ||
size_t cc_major_; | ||
size_t cc_minor_; | ||
std::string name_; | ||
size_t sm_count_; | ||
size_t max_threads_per_sm_; | ||
size_t warp_size_; | ||
size_t total_global_memory_; | ||
size_t alignment_; | ||
}; | ||
} // namespace alus::cuda |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* ENVISAT and ERS ASAR instrument focusser for QA4EO activity (c) by CGI Estonia AS | ||
* | ||
* ENVISAT and ERS ASAR instrument focusser for QA4EO activity is licensed under a | ||
* Creative Commons Attribution-ShareAlike 4.0 International License. | ||
* | ||
* You should have received a copy of the license along with this | ||
* work. If not, see http://creativecommons.org/licenses/by-sa/4.0/ | ||
*/ | ||
|
||
#include "cuda_device_init.h" | ||
|
||
#include <stdexcept> | ||
#include <thread> | ||
|
||
#include <cuda_runtime.h> | ||
|
||
#include "cuda_util.h" | ||
|
||
namespace alus::cuda { | ||
CudaInit::CudaInit() { | ||
init_future_ = std::async(std::launch::async, [this]() { this->QueryDevices(); }); | ||
} | ||
|
||
bool CudaInit::IsFinished() const { | ||
if (!init_future_.valid()) { | ||
throw std::runtime_error("The future is already a past, invalid state queried."); | ||
} | ||
return init_future_.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready; | ||
} | ||
|
||
void CudaInit::QueryDevices() { | ||
int device_count{}; | ||
CHECK_CUDA_ERR(cudaGetDeviceCount(&device_count)); | ||
if (!device_count) { | ||
throw std::runtime_error("No GPU devices detected"); | ||
} | ||
for (int i{}; i < device_count; i++) { | ||
cudaDeviceProp deviceProp; | ||
CHECK_CUDA_ERR(cudaGetDeviceProperties(&deviceProp, i)); | ||
devices_.emplace_back(i, &deviceProp); | ||
// Whatever will first start invoking GPU, might be delayed if this thread does not finish. | ||
// But when waiting, a first invocation of GPU could be delayed by waiting here. | ||
// Also no error checking is done, because if there are errors, then sooner or later they will pop out | ||
// somewhere else. | ||
device_warmups_.emplace_back([i]() { | ||
cudaSetDevice(i); | ||
cudaFree(nullptr); | ||
}); | ||
} | ||
} | ||
|
||
void CudaInit::CheckErrors() { | ||
if (!init_future_.valid()) { | ||
throw std::runtime_error("The future is already a past, invalid state queried."); | ||
} | ||
init_future_.get(); | ||
} | ||
|
||
CudaInit::~CudaInit() { | ||
// Just in case wait if any left hanging. | ||
if (init_future_.valid()) { | ||
init_future_.wait_for(std::chrono::seconds(10)); | ||
} | ||
|
||
for (auto& t : device_warmups_) { | ||
if (t.joinable()) { | ||
t.join(); | ||
} | ||
} | ||
} | ||
|
||
} // namespace alus::cuda |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* ENVISAT and ERS ASAR instrument focusser for QA4EO activity (c) by CGI Estonia AS | ||
* | ||
* ENVISAT and ERS ASAR instrument focusser for QA4EO activity is licensed under a | ||
* Creative Commons Attribution-ShareAlike 4.0 International License. | ||
* | ||
* You should have received a copy of the license along with this | ||
* work. If not, see http://creativecommons.org/licenses/by-sa/4.0/ | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <future> | ||
#include <thread> | ||
#include <vector> | ||
|
||
#include "cuda_device.h" | ||
|
||
namespace alus::cuda { | ||
class CudaInit final { | ||
public: | ||
CudaInit(); | ||
|
||
[[nodiscard]] bool IsFinished() const; | ||
void CheckErrors(); | ||
|
||
[[nodiscard]] const std::vector<CudaDevice>& GetDevices() const { return devices_; } | ||
|
||
~CudaInit(); | ||
|
||
private: | ||
void QueryDevices(); | ||
|
||
std::vector<CudaDevice> devices_; | ||
std::future<void> init_future_; | ||
std::vector<std::thread> device_warmups_; | ||
}; | ||
} // namespace alus::cuda |
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.