-
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.
initial HIP improvements, scope::system
- Loading branch information
Showing
12 changed files
with
296 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
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,3 @@ | ||
|
||
add_executable(system-graph system-graph.cpp) | ||
target_link_libraries(system-graph scope) |
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,29 @@ | ||
#include <iostream> | ||
|
||
#include "scope/system.hpp" | ||
#include "scope/init.hpp" | ||
|
||
int main(int argc, char **argv) { | ||
|
||
using TransferMethod = scope::system::TransferMethod; | ||
|
||
scope::initialize(&argc, argv); | ||
|
||
std::vector<MemorySpace> spaces = scope::system::memory_spaces(); | ||
|
||
for (const auto &space : spaces) { | ||
std::cout << space << "\n"; | ||
} | ||
|
||
for (size_t i = 0; i < spaces.size(); ++i) { | ||
for (size_t j = 0; j < spaces.size(); ++j) { | ||
std::cout << spaces[i] << " -> " << spaces[j] << "\n"; | ||
std::vector<TransferMethod> methods = scope::system::transfer_methods(spaces[i], spaces[j]); | ||
for (const auto &method : methods) { | ||
std::cout << "\t" << method << "\n"; | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
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,7 @@ | ||
``` | ||
cmake .. -DCMAKE_CXX_COMPILER=hipcc | ||
``` | ||
|
||
``` | ||
``` |
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,19 @@ | ||
#pragma once | ||
|
||
#include <sstream> | ||
|
||
#include <hip/hip_runtime.h> | ||
|
||
namespace scope { | ||
namespace detail { | ||
inline void success_or_throw(hipError_t err, const char *file, int line) { | ||
if (hipSuccess != err) { | ||
std::stringstream ss; | ||
ss << __FILE__ << ":" << __LINE__ << "HIP error " << hipGetErrorString(err); | ||
throw std::runtime_error(ss.str()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#define HIP_RUNTIME(x) scope::detail::success_or_throw(x, __FILE__, __LINE__) |
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,69 @@ | ||
#pragma once | ||
|
||
#include <ostream> | ||
|
||
class MemorySpace { | ||
public: | ||
enum class Kind { | ||
numa | ||
,hip_device | ||
,hip_managed | ||
,cuda_device | ||
}; | ||
|
||
static MemorySpace numa_space(int id) { | ||
MemorySpace ms; | ||
ms.kind_ = Kind::numa; | ||
ms.numaId_ = id; | ||
return ms; | ||
} | ||
|
||
#ifdef __HIP__ | ||
static MemorySpace hip_device_space(int id) { | ||
MemorySpace ms; | ||
ms.kind_ = Kind::hip_device; | ||
ms.deviceId_ = id; | ||
return ms; | ||
} | ||
static MemorySpace hip_managed_space() { | ||
MemorySpace ms; | ||
ms.kind_ = Kind::hip_managed; | ||
return ms; | ||
} | ||
#endif // __HIP__ | ||
|
||
const Kind &kind() const noexcept {return kind_;} | ||
|
||
friend std::ostream& operator<<(std::ostream& os, const MemorySpace& ms); | ||
|
||
private: | ||
Kind kind_; | ||
int deviceId_; | ||
int numaId_; | ||
}; | ||
|
||
|
||
inline std::ostream& operator<<(std::ostream& os, const MemorySpace& ms) | ||
{ | ||
using Kind = MemorySpace::Kind; | ||
|
||
switch(ms.kind_) { | ||
case Kind::numa: { | ||
os << "numa:" << ms.numaId_; | ||
break; | ||
} | ||
case Kind::hip_device: { | ||
os << "hip_device:" << ms.deviceId_; | ||
break; | ||
} | ||
case Kind::hip_managed: { | ||
os << "hip_managed"; | ||
break; | ||
} | ||
case Kind::cuda_device: { | ||
os << "cuda_device:" << ms.deviceId_; | ||
break; | ||
} | ||
} | ||
return os; | ||
} |
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,129 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "scope/memory_space.hpp" | ||
#include "scope/numa.hpp" | ||
|
||
#ifdef __HIP__ | ||
#include "scope/hip.hpp" | ||
#endif | ||
|
||
namespace scope { | ||
namespace system { | ||
|
||
inline std::vector<MemorySpace> hip_memory_spaces() { | ||
int ndev; | ||
HIP_RUNTIME(hipGetDeviceCount(&ndev)); | ||
|
||
std::vector<MemorySpace> ret; | ||
|
||
for (int i = 0; i < ndev; ++i) { | ||
ret.push_back(MemorySpace::hip_device_space(i)); | ||
} | ||
ret.push_back(MemorySpace::hip_managed_space()); | ||
return ret; | ||
} | ||
|
||
inline std::vector<MemorySpace> numa_memory_spaces() { | ||
|
||
auto nodes = numa::nodes(); | ||
|
||
std::vector<MemorySpace> ret; | ||
for (const auto &node : nodes) { | ||
ret.push_back(MemorySpace::numa_space(node)); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
|
||
std::vector<MemorySpace> memory_spaces() { | ||
|
||
std::vector<MemorySpace> spaces; | ||
|
||
auto numaSpaces = numa_memory_spaces(); | ||
spaces.insert(spaces.begin(), numaSpaces.begin(), numaSpaces.end()); | ||
|
||
#ifdef __HIP__ | ||
auto hipSpaces = hip_memory_spaces(); | ||
spaces.insert(spaces.begin(), hipSpaces.begin(), hipSpaces.end()); | ||
#endif | ||
|
||
return spaces; | ||
|
||
}; | ||
|
||
enum class TransferMethod { | ||
hip_memcpy, | ||
hip_memcpy_async, | ||
}; | ||
|
||
std::vector<TransferMethod> transfer_methods(const MemorySpace &src, const MemorySpace &dst) { | ||
|
||
using Kind = MemorySpace::Kind; | ||
|
||
switch(src.kind()) { | ||
case Kind::hip_device: { | ||
switch(dst.kind()) { | ||
case Kind::hip_device: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::hip_managed: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::numa: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::cuda_device: | ||
return {}; | ||
} | ||
} | ||
case Kind::hip_managed: { | ||
switch(dst.kind()) { | ||
case Kind::hip_device: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::hip_managed: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::numa: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::cuda_device: | ||
throw std::runtime_error("unimplemented"); | ||
} | ||
} | ||
case Kind::numa: { | ||
switch(dst.kind()) { | ||
case Kind::hip_device: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::hip_managed: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::numa: | ||
return {TransferMethod::hip_memcpy, TransferMethod::hip_memcpy_async}; | ||
case Kind::cuda_device: | ||
throw std::runtime_error("unimplemented"); | ||
} | ||
} | ||
case Kind::cuda_device: { | ||
throw std::runtime_error("unimplemented"); | ||
} | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
} // namespace system | ||
} // namespace scope | ||
|
||
std::ostream& operator<<(std::ostream& os, const scope::system::TransferMethod& tm) | ||
{ | ||
using TransferMethod = scope::system::TransferMethod; | ||
|
||
switch(tm) { | ||
case TransferMethod::hip_memcpy: { | ||
os << "hipMemcpy"; | ||
break; | ||
} | ||
case TransferMethod::hip_memcpy_async: { | ||
os << "hipMemcpyAsync"; | ||
break; | ||
} | ||
} | ||
return os; | ||
} |
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,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo_and_do() { | ||
echo "$@" | ||
"$@" | ||
} | ||
|
||
if [[ $(hostname) =~ rzvernal ]]; then | ||
|
||
echo_and_do module load cmake/3.24.2 | ||
echo_and_do module load rocm/5.2.0 | ||
|
||
else | ||
echo "UNRECOGNIZED PLATFORM $(hostname)" | ||
fi |
Empty file.
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