-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "common.h" | ||
#include "cublaslt_context.hh" | ||
|
||
namespace refactor::kernel::cublas { | ||
|
||
CublasLtContext::CublasLtContext() : runtime::Resource() { | ||
if (cublasLtCreate(&handle) != CUBLAS_STATUS_SUCCESS) { | ||
RUNTIME_ERROR("Failed to create cublasLt handle"); | ||
} | ||
} | ||
CublasLtContext::~CublasLtContext() { | ||
if (cublasLtDestroy(handle) != CUBLAS_STATUS_SUCCESS) { | ||
fmt::println("Failed to destroy cublasLt handle"); | ||
abort(); | ||
} | ||
} | ||
|
||
auto CublasLtContext::typeId() noexcept -> size_t { | ||
static uint8_t ID = 1; | ||
return reinterpret_cast<size_t>(&ID); | ||
} | ||
auto CublasLtContext::build() noexcept -> runtime::ResourceBox { | ||
return std::make_unique<CublasLtContext>(); | ||
} | ||
|
||
auto CublasLtContext::resourceTypeId() const noexcept -> size_t { | ||
return typeId(); | ||
} | ||
auto CublasLtContext::description() const noexcept -> std::string_view { | ||
return "CublasLtContext"; | ||
} | ||
|
||
}// namespace refactor::kernel::cublas |
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,33 @@ | ||
#ifndef KERNEL_CUBLASLT_CONTEXT_HH | ||
#define KERNEL_CUBLASLT_CONTEXT_HH | ||
|
||
#include "runtime/resource.h" | ||
#include <cublasLt.h> | ||
|
||
#define CUBLAS_ASSERT(STATUS) \ | ||
if (auto status = (STATUS); status != CUBLAS_STATUS_SUCCESS) { \ | ||
fmt::println("cublas failed on \"" #STATUS "\" with {}", \ | ||
(int) status); \ | ||
abort(); \ | ||
} | ||
|
||
namespace refactor::kernel::cublas { | ||
|
||
struct CublasLtContext final : public runtime::Resource { | ||
cublasLtHandle_t handle; | ||
|
||
CublasLtContext(); | ||
~CublasLtContext(); | ||
CublasLtContext(CublasLtContext const &) noexcept = delete; | ||
CublasLtContext(CublasLtContext &&) noexcept = delete; | ||
|
||
static size_t typeId() noexcept; | ||
static runtime::ResourceBox build() noexcept; | ||
|
||
size_t resourceTypeId() const noexcept final; | ||
std::string_view description() const noexcept final; | ||
}; | ||
|
||
}// namespace refactor::kernel::cublas | ||
|
||
#endif// KERNEL_CUBLASLT_CONTEXT_HH |