-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved DeviceType and DeviceInfo to platform rather than scalars
- Loading branch information
1 parent
1523781
commit 3e42f3e
Showing
13 changed files
with
191 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// | ||
// Created by sam on 17/08/23. | ||
// | ||
|
||
#ifndef ROUGHPY_DEVICE_H | ||
#define ROUGHPY_DEVICE_H | ||
|
||
#include <roughpy/core/macros.h> | ||
#include <roughpy/core/types.h> | ||
|
||
#include "filesystem.h" | ||
|
||
#if defined(__NVCC__) | ||
# include <cuda.h> | ||
|
||
# define RPY_DEVICE __device__ | ||
# define RPY_HOST __host__ | ||
# define RPY_DEVICE_HOST __device__ __host__ | ||
# define RPY_KERNEL __global__ | ||
# define RPY_DEVICE_SHARED __shared__ | ||
# define RPY_STRONG_INLINE __inline__ | ||
|
||
#elif defined(__HIPCC__) | ||
|
||
# define RPY_DEVICE __device__ | ||
# define RPY_HOST __host__ | ||
# define RPY_DEVICE_HOST __device__ __host__ | ||
# define RPY_KERNEL __global__ | ||
# define RPY_DEVICE_SHARED __shared__ | ||
# define RPY_STRONG_INLINE | ||
|
||
#else | ||
# define RPY_DEVICE | ||
# define RPY_HOST | ||
# define RPY_DEVICE_HOST | ||
# define RPY_KERNEL | ||
# define RPY_DEVICE_SHARED | ||
# define RPY_STRONG_INLINE | ||
|
||
#endif | ||
|
||
|
||
|
||
namespace rpy { namespace platform { | ||
|
||
using dindex_t = int; | ||
using dsize_t = unsigned int; | ||
|
||
|
||
/** | ||
* @brief Code for different device types | ||
* | ||
* These codes are chosen to be compatible with the DLPack | ||
* array interchange protocol. They enumerate the various different | ||
* device types that scalar data may be allocated on. This code goes | ||
* with a 32bit integer device ID, which is implementation specific. | ||
*/ | ||
enum DeviceType : int32_t { | ||
CPU = 1, | ||
CUDA = 2, | ||
CUDAHost = 3, | ||
OpenCL = 4, | ||
Vulkan = 7, | ||
Metal = 8, | ||
VPI = 9, | ||
ROCM = 10, | ||
ROCMHost = 11, | ||
ExtDev = 12, | ||
CUDAManaged = 13, | ||
OneAPI = 14, | ||
WebGPU = 15, | ||
Hexagon = 16 | ||
}; | ||
|
||
/** | ||
* @brief Device type/id pair to identify a device | ||
* | ||
* | ||
*/ | ||
struct DeviceInfo { | ||
DeviceType device_type; | ||
int32_t device_id; | ||
}; | ||
|
||
|
||
class RPY_EXPORT DeviceHandle { | ||
DeviceInfo m_info; | ||
|
||
public: | ||
|
||
virtual ~DeviceHandle(); | ||
|
||
explicit DeviceHandle(DeviceInfo info) | ||
: m_info(info) | ||
{} | ||
|
||
explicit DeviceHandle(DeviceType type, int32_t device_id) | ||
: m_info {type, device_id} | ||
{} | ||
|
||
RPY_NO_DISCARD | ||
const DeviceInfo& info() const noexcept { return m_info; } | ||
|
||
RPY_NO_DISCARD | ||
virtual const fs::path& runtime_library() const noexcept = 0; | ||
|
||
|
||
virtual void launch_kernel(const void* kernel, | ||
const void* launch_config, | ||
void** args | ||
) = 0; | ||
|
||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
constexpr bool | ||
operator==(const DeviceInfo& lhs, const DeviceInfo& rhs) noexcept | ||
{ | ||
return lhs.device_type == rhs.device_type && lhs.device_id == rhs.device_id; | ||
} | ||
|
||
}} | ||
|
||
|
||
#endif// ROUGHPY_DEVICE_H |
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,13 @@ | ||
// | ||
// Created by sam on 17/08/23. | ||
// | ||
|
||
#include <roughpy/platform/device.h> | ||
|
||
|
||
using namespace rpy; | ||
using namespace rpy::platform; | ||
|
||
|
||
|
||
DeviceHandle::~DeviceHandle() = default; |
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
Oops, something went wrong.