Skip to content

Commit

Permalink
style: 整理代码
Browse files Browse the repository at this point in the history
Signed-off-by: YdrMaster <ydrml@hotmail.com>
  • Loading branch information
YdrMaster committed Nov 17, 2023
1 parent 7540ec0 commit 5c33586
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/03runtime/include/runtime/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace refactor::runtime {
auto prepare() -> std::vector<count_t>;
void run();
auto bench(void (*sync)()) -> std::vector<std::chrono::nanoseconds>;
void trace(std::function<void(count_t, void const **, void **)>);
void trace(std::function<void(count_t, void const *const *, void const *const *)>);
};

}// namespace refactor::runtime
Expand Down
5 changes: 1 addition & 4 deletions src/03runtime/src/stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ namespace refactor::runtime {
}

void Stream::run() {
auto map = [this](auto i) { return _internal.edges[i](*_stack); };
std::vector<void *> buffer(16);
for (auto const [nodeIdx, i, o] : _internal.topology) {
auto [inputs, outputs] = collectAddress(*_stack, _internal.edges, buffer, i, o);
Expand All @@ -105,7 +104,6 @@ namespace refactor::runtime {
}

auto Stream::bench(void (*sync)()) -> std::vector<std::chrono::nanoseconds> {
auto map = [this](auto i) { return _internal.edges[i](*_stack); };
std::vector<void *> buffer(16);
std::vector<std::chrono::nanoseconds> ans(_internal.nodes.size());
for (auto const [nodeIdx, i, o] : _internal.topology) {
Expand All @@ -119,8 +117,7 @@ namespace refactor::runtime {
return ans;
}

void Stream::trace(std::function<void(count_t, void const **, void **)> record) {
auto map = [this](auto i) { return _internal.edges[i](*_stack); };
void Stream::trace(std::function<void(count_t, void const *const *, void const *const *)> record) {
std::vector<void *> buffer(16);
for (auto const [nodeIdx, i, o] : _internal.topology) {
auto [inputs, outputs] = collectAddress(*_stack, _internal.edges, buffer, i, o);
Expand Down
2 changes: 1 addition & 1 deletion src/07onnx/src/operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
namespace refactor::onnx {

void register_() {
// clang-format off
// clang-format off
#define REGISTER(NAME, CLASS) Operator::register_<CLASS>("onnx::" #NAME)
REGISTER(BatchNormalization, BatchNormalization);
REGISTER(Cast , Cast );
Expand Down
2 changes: 1 addition & 1 deletion src/08communication/src/operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace refactor::communication {
using namespace frontend;

void register_() {
// clang-format off
// clang-format off
#define REGISTER(NAME, CLASS) Operator::register_<CLASS>("onnx::" #NAME)
REGISTER(AllReduceAvg , AllReduce);
REGISTER(AllReduceSum , AllReduce);
Expand Down
16 changes: 9 additions & 7 deletions src/09python_ffi/src/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,23 @@ namespace refactor::python_ffi {

void Executor::trace(std::string path_) {
namespace fs = std::filesystem;

auto path = fs::path(std::move(path_));
fs::create_directories(path);
ASSERT(fs::is_directory(path), "Failed to create \"{}\"", path.c_str());

auto it = _graph.internal().contiguous().topology.begin();
_stream.trace([&](count_t nodeIdx, void const **inputs, void **outputs) {
_stream.trace([&](count_t nodeIdx, void const *const *inputs, void const *const *outputs) {
auto [nodeIdx_, i_, o_] = *it++;
ASSERT(nodeIdx_ == nodeIdx, "node index mismatch");
auto nodeName = _graph.internal().contiguous().nodes[nodeIdx].name;
std::replace(nodeName.begin(), nodeName.end(), '/', '_');
std::replace(nodeName.begin(), nodeName.end(), '.', '-');

std::vector<char> buffer;
auto fn = [&](char dir, count_t idx, computation::Edge const &edge, void const *ptr) {
if (!ptr) { return; }
auto fn = [&](char dir, count_t idx, count_t edgeIdx, void const *const *addresses) {
if (!addresses[idx]) { return; }
auto edge = _graph.internal().contiguous().edges[edgeIdx];
auto size = edge.tensor->bytesSize();
buffer.resize(size);

Expand All @@ -75,14 +78,13 @@ namespace refactor::python_ffi {
fs::remove(file);
std::ofstream os(file, std::ios::binary);
#ifdef USE_CUDA
kernel::cuda::copyOut(buffer.data(), ptr, size);
kernel::cuda::copyOut(buffer.data(), addresses[idx], size);
#endif
os.write(buffer.data(), size);
};

auto const &edges = _graph.internal().contiguous().edges;
for (auto i : range0_(i_.size())) { fn('i', i, edges[i_[i]], inputs[i]); }
for (auto i : range0_(o_.size())) { fn('o', i, edges[o_[i]], outputs[i]); }
for (auto i : range0_(i_.size())) { fn('i', i, i_[i], inputs); }
for (auto i : range0_(o_.size())) { fn('o', i, o_[i], outputs); }
});
}

Expand Down

0 comments on commit 5c33586

Please sign in to comment.