Skip to content

Commit

Permalink
feat: log errors from cudaGetDeviceCount (PROOF-924) (#209)
Browse files Browse the repository at this point in the history
log errors from cudaGetDeviceCount
  • Loading branch information
rnburn authored Jan 6, 2025
1 parent ff56d21 commit af4bf60
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions sxt/base/device/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ sxt_cc_component(
name = "property",
impl_deps = [
"//sxt/base/error:panic",
"//sxt/base/log:log",
],
test_deps = [
"//sxt/base/test:unit_test",
Expand Down
4 changes: 3 additions & 1 deletion sxt/base/device/property.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
#include <cuda_runtime.h>

#include "sxt/base/error/panic.h"
#include "sxt/base/log/log.h"

namespace sxt::basdv {
//--------------------------------------------------------------------------------------------------
// get_num_devices
//--------------------------------------------------------------------------------------------------
unsigned get_num_devices() noexcept {
static int num_devices = []() noexcept {
static unsigned num_devices = []() noexcept {
int res;
auto rcode = cudaGetDeviceCount(&res);
if (rcode != cudaSuccess) {
basl::error("cudaGetDeviceCount failed: {}", cudaGetErrorString(rcode));
return 0u;
}
return static_cast<unsigned>(res);
Expand Down
9 changes: 9 additions & 0 deletions sxt/base/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ inline void info(std::string_view s) noexcept { info_impl(s); }
template <class... Args> void info(std::format_string<Args...> fmt, Args&&... args) noexcept {
info_impl(std::format(fmt, std::forward<Args>(args)...));
}

//--------------------------------------------------------------------------------------------------
// error
//--------------------------------------------------------------------------------------------------
inline void error(std::string_view s) noexcept { error_impl(s); }

template <class... Args> void error(std::format_string<Args...> fmt, Args&&... args) noexcept {
error_impl(std::format(fmt, std::forward<Args>(args)...));
}
} // namespace sxt::basl
8 changes: 8 additions & 0 deletions sxt/base/log/log_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ void info_impl(std::string_view s) noexcept {
setup_logger();
spdlog::info(s);
}

//--------------------------------------------------------------------------------------------------
// error_impl
//--------------------------------------------------------------------------------------------------
void error_impl(std::string_view s) noexcept {
setup_logger();
spdlog::error(s);
}
} // namespace sxt::basl
5 changes: 5 additions & 0 deletions sxt/base/log/log_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ namespace sxt::basl {
// info_impl
//--------------------------------------------------------------------------------------------------
void info_impl(std::string_view s) noexcept;

//--------------------------------------------------------------------------------------------------
// error_impl
//--------------------------------------------------------------------------------------------------
void error_impl(std::string_view s) noexcept;
} // namespace sxt::basl

0 comments on commit af4bf60

Please sign in to comment.