-
Notifications
You must be signed in to change notification settings - Fork 16
Dev mlu runtime #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Dev mlu runtime #87
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bd6ad6b
feat(hardware): 实现 mlu 硬件相关的函数;改变编译方式按照以硬件名称命名的目录名区分是否需要编译
kilinchange 02939c9
feat: 在 cmake 中增加 mlu 的相关环境编译
kilinchange 7f82d74
fix: 去掉 cncl 编译
kilinchange 0ebf34c
fix: format CMakeLists.txt
Chamberlain0w0 cc19556
feat(hardware): add cnnl
kilinchange d8a2dea
Merge branch 'dev' into dev-mlu-runtime
kilinchange b3b7d09
fix(hardware): fix file encoding bug and include bug
kilinchange File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ namespace refactor::hardware { | |
| enum class Type : int32_t { | ||
| Cpu, | ||
| Nvidia, | ||
| Mlu, | ||
| Kunlun, | ||
| }; | ||
|
|
||
| protected: | ||
|
|
||
This file contains hidden or 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 @@ | ||
| #ifndef HARDWARE_DEVICES_MLU_H | ||
| #define HARDWARE_DEVICES_MLU_H | ||
|
|
||
| #include "../device.h" | ||
|
|
||
| namespace refactor::hardware { | ||
|
|
||
| class Mlu final : public Device { | ||
| public: | ||
| explicit Mlu(int32_t card); | ||
| void setContext() const noexcept final; | ||
| Type type() const noexcept final { | ||
| return Type::Mlu; | ||
| } | ||
| }; | ||
|
|
||
| }// namespace refactor::hardware | ||
|
|
||
| #endif// HARDWARE_DEVICES_MLU_H |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,31 @@ | ||
| #include "functions.hh" | ||
| #include "hardware/devices/mlu.h" | ||
| #include "hardware/mem_pool.h" | ||
| #include "memory.hh" | ||
|
|
||
| namespace refactor::hardware { | ||
|
|
||
| static Arc<Memory> bangMemory(int32_t card) { | ||
| #ifdef USE_BANG | ||
| ASSERT(0 <= card && card < getDeviceCount(), "Invalid card id: {}", card); | ||
| setDevice(card); | ||
| auto [free, total] = getMemInfo(); | ||
| auto size = std::min(free, std::max(5ul << 30, total * 4 / 5)); | ||
| fmt::println("initializing Cambricon MLU {}, memory {} / {}, alloc {}", | ||
| card, free, total, size); | ||
| return std::make_shared<MemPool>( | ||
| std::make_shared<MluMemory>(), | ||
| size, | ||
| 256ul); | ||
| #else | ||
| return nullptr; | ||
| #endif | ||
| } | ||
|
|
||
| Mlu::Mlu(int32_t card) : Device(card, bangMemory(card)) {} | ||
|
|
||
| void Mlu::setContext() const noexcept { | ||
| setDevice(_card); | ||
| } | ||
|
|
||
| }// namespace refactor::hardware | ||
This file contains hidden or 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,21 @@ | ||
| #include "functions.hh" | ||
|
|
||
| namespace refactor::hardware { | ||
|
|
||
| #ifdef USE_BANG | ||
| int getDeviceCount() { | ||
| unsigned deviceCount; | ||
| BANG_ASSERT(cnrtGetDeviceCount(&deviceCount)); | ||
| return static_cast<int>(deviceCount); | ||
| } | ||
| void setDevice(int device) { | ||
| BANG_ASSERT(cnrtSetDevice(device)); | ||
| } | ||
| MemInfo getMemInfo() { | ||
| MemInfo memInfo; | ||
| BANG_ASSERT(cnrtMemGetInfo(&memInfo.free, &memInfo.total)); | ||
| return memInfo; | ||
| } | ||
| #endif | ||
|
|
||
| }// namespace refactor::hardware |
This file contains hidden or 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,28 @@ | ||
| #ifndef HARDWARE_DEVICES_MLU_FUNCTIONS_CUH | ||
| #define HARDWARE_DEVICES_MLU_FUNCTIONS_CUH | ||
|
|
||
| #include "common.h" | ||
|
|
||
| #ifdef USE_BANG | ||
| #include "cnrt.h" | ||
|
|
||
| #define BANG_ASSERT(STATUS) \ | ||
| if (auto status = (STATUS); status != CNRT_RET_SUCCESS) { \ | ||
| RUNTIME_ERROR(fmt::format("bang failed on \"" #STATUS "\" with \"{}\" ({})", \ | ||
| cnrtGetErrorStr(status), (int) status)); \ | ||
| } | ||
| #endif | ||
|
|
||
| namespace refactor::hardware { | ||
|
|
||
| struct MemInfo { | ||
| size_t free, total; | ||
| }; | ||
|
|
||
| int getDeviceCount(); | ||
| void setDevice(int device); | ||
| MemInfo getMemInfo(); | ||
|
|
||
| }// namespace refactor::hardware | ||
|
|
||
| #endif// HARDWARE_DEVICES_NVIDIA_FUNCTIONS_CUH |
This file contains hidden or 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 "memory.hh" | ||
| #include "functions.hh" | ||
|
|
||
| namespace refactor::hardware { | ||
| #ifdef USE_BANG | ||
| using M = MluMemory; | ||
|
|
||
| void *M::malloc(size_t size) { | ||
| void *ptr; | ||
| BANG_ASSERT(cnrtMalloc(&ptr, size)); | ||
| return ptr; | ||
| } | ||
| void M::free(void *ptr) { | ||
| BANG_ASSERT(cnrtFree(ptr)); | ||
| } | ||
| void *M::copyHD(void *dst, void const *src, size_t bytes) const { | ||
| BANG_ASSERT(cnrtMemcpy(dst, const_cast<void *>(src), bytes, | ||
| CNRT_MEM_TRANS_DIR_HOST2DEV)) | ||
| return dst; | ||
| } | ||
| void *M::copyDH(void *dst, void const *src, size_t bytes) const { | ||
| BANG_ASSERT(cnrtMemcpy(dst, const_cast<void *>(src), bytes, | ||
| CNRT_MEM_TRANS_DIR_DEV2HOST)); | ||
| return dst; | ||
| } | ||
| void *M::copyDD(void *dst, void const *src, size_t bytes) const { | ||
| BANG_ASSERT(cnrtMemcpy(dst, const_cast<void *>(src), bytes, | ||
| CNRT_MEM_TRANS_DIR_PEER2PEER)); | ||
| return dst; | ||
| } | ||
| #endif | ||
|
|
||
| }// namespace refactor::hardware |
This file contains hidden or 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,18 @@ | ||
| #ifndef HARDWARE_DEVICES_MLU_MEMORY_CUH | ||
| #define HARDWARE_DEVICES_MLU_MEMORY_CUH | ||
|
|
||
| #include "hardware/memory.h" | ||
|
|
||
| namespace refactor::hardware { | ||
|
|
||
| class MluMemory final : public Memory { | ||
| void *malloc(size_t) final; | ||
| void free(void *) final; | ||
| void *copyHD(void *dst, void const *src, size_t bytes) const final; | ||
| void *copyDH(void *dst, void const *src, size_t bytes) const final; | ||
| void *copyDD(void *dst, void const *src, size_t bytes) const final; | ||
| }; | ||
|
|
||
| }// namespace refactor::hardware | ||
|
|
||
| #endif// HARDWARE_DEVICES_MLU_MEMORY_HH |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.