-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from InfiniTensor/dev
Dev
- Loading branch information
Showing
205 changed files
with
5,037 additions
and
584 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ | |
[submodule "src/09python_ffi/pybind11"] | ||
path = src/09python_ffi/pybind11 | ||
url = [email protected]:pybind/pybind11.git | ||
[submodule "3rd-party/cccl"] | ||
path = 3rd-party/cccl | ||
url = [email protected]:NVIDIA/cccl.git |
Submodule backward-cpp
updated
7 files
+1 −0 | .gitignore | |
+55 −32 | BackwardConfig.cmake | |
+54 −17 | CMakeLists.txt | |
+57 −23 | README.md | |
+79 −47 | backward.hpp | |
+2 −2 | test/suicide.cpp | |
+1 −1 | test_package/CMakeLists.txt |
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
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
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#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 { | ||
#ifdef USE_BANG | ||
setDevice(_card); | ||
#endif | ||
} | ||
|
||
}// namespace refactor::hardware |
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,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 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 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 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 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.