Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chhwang committed Apr 5, 2024
1 parent 20840bb commit 473288c
Show file tree
Hide file tree
Showing 152 changed files with 4,053 additions and 1,659 deletions.
98 changes: 98 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,102 @@
"cmake.ctestArgs": [
"--verbose"
],
"files.associations": {
"ostream": "cpp",
"stdexcept": "cpp",
"string": "cpp",
"iosfwd": "cpp",
"memory": "cpp",
"stack": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"cfenv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ranges": "cpp",
"semaphore": "cpp",
"span": "cpp",
"sstream": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"__nullptr": "cpp",
"__hash_table": "cpp",
"__split_buffer": "cpp",
"__tree": "cpp",
"queue": "cpp",
"__locale": "cpp",
"*.ipp": "cpp",
"strstream": "cpp",
"typeindex": "cpp",
"locale": "cpp",
"__node_handle": "cpp",
"__threading_support": "cpp",
"__functional_03": "cpp",
"filesystem": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"version": "cpp",
"__functional_base": "cpp",
"__memory": "cpp"
},
}
6 changes: 3 additions & 3 deletions ark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.cc)
file(GLOB_RECURSE UT_SOURCES CONFIGURE_DEPENDS *_test.cc *_test.cu)
file(GLOB_RECURSE UT_COMMON_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/unittest/*.cc)
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.cpp)
file(GLOB_RECURSE UT_SOURCES CONFIGURE_DEPENDS *_test.cpp)
file(GLOB_RECURSE UT_COMMON_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/unittest/*.cpp)
list(REMOVE_ITEM SOURCES ${UT_SOURCES} ${UT_COMMON_SOURCES})

if(USE_ROCM)
Expand Down
File renamed without changes.
17 changes: 16 additions & 1 deletion ark/dims.cc → ark/dims.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "ark/dims.hpp"

#include <vector>

#include "include/ark.h"
#include "error.hpp"
#include "logging.h"

namespace ark {
Expand Down Expand Up @@ -101,6 +103,19 @@ Dims Dims::dims4() const {
return ret;
}

// Return true if all valid dimensions are zero.
bool Dims::is_zeros() const {
if (this->is_invalid()) {
return false;

Check warning on line 109 in ark/dims.cpp

View check run for this annotation

Codecov / codecov/patch

ark/dims.cpp#L107-L109

Added lines #L107 - L109 were not covered by tests
}
const DimType *v = this->data;
for (int i = 0; i < DIMS_LEN; ++i) {
if (v[i] == NO_DIM) break;
if (v[i] != 0) return false;

Check warning on line 114 in ark/dims.cpp

View check run for this annotation

Codecov / codecov/patch

ark/dims.cpp#L111-L114

Added lines #L111 - L114 were not covered by tests
}
return true;

Check warning on line 116 in ark/dims.cpp

View check run for this annotation

Codecov / codecov/patch

ark/dims.cpp#L116

Added line #L116 was not covered by tests
}

// Return true if the dimensions are empty.
bool Dims::is_no_dim() const {
const DimType *v = this->data;
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions ark/error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#ifndef ARK_ERROR_HPP_
#define ARK_ERROR_HPP_

#include <stdexcept>
#include <string>

namespace ark {

#define REGISTER_ERROR_TYPE(_name) \
class _name : public std::runtime_error { \
public: \
_name(const std::string &msg) : std::runtime_error(msg) {} \
};

REGISTER_ERROR_TYPE(InvalidUsageError)
REGISTER_ERROR_TYPE(ModelError)

Check warning on line 19 in ark/error.hpp

View check run for this annotation

Codecov / codecov/patch

ark/error.hpp#L19

Added line #L19 was not covered by tests
REGISTER_ERROR_TYPE(SchedulerError)
REGISTER_ERROR_TYPE(ExecutorError)

Check warning on line 21 in ark/error.hpp

View check run for this annotation

Codecov / codecov/patch

ark/error.hpp#L21

Added line #L21 was not covered by tests
REGISTER_ERROR_TYPE(SystemError)
REGISTER_ERROR_TYPE(GpuError)

Check warning on line 23 in ark/error.hpp

View check run for this annotation

Codecov / codecov/patch

ark/error.hpp#L23

Added line #L23 was not covered by tests
REGISTER_ERROR_TYPE(RuntimeError)
REGISTER_ERROR_TYPE(UnitTestError)

Check warning on line 25 in ark/error.hpp

View check run for this annotation

Codecov / codecov/patch

ark/error.hpp#L25

Added line #L25 was not covered by tests

} // namespace ark

#endif // ARK_ERROR_HPP_
87 changes: 87 additions & 0 deletions ark/executor/executor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "ark/executor.hpp"

#include <algorithm>
#include <memory>
#include <string>

#include "env.h"
#include "gpu/gpu_loop_kernel.h"
#include "logging.h"
#include "sched/sched.h"

namespace ark {

class Executor::Impl {
public:
Impl(int rank, int world_size, const Model &model, const Schedule &schedule, const std::string &name,
int num_warps_per_sm);
~Impl() = default;

void compile();
void launch();
void run(int iter);
void wait();
float stop();

private:
const int rank_;
const int world_size_;
int gpu_id_;

std::shared_ptr<GpuContext> ctx_;
std::unique_ptr<GpuLoopKernel> glk_;
std::shared_ptr<GpuStream> stream_;
};

Executor::Impl::Impl(int rank, int world_size, const Model &model, const Schedule &schedule,
const std::string &name, int num_warps_per_sm)
: rank_(rank), world_size_(world_size) {
gpu_id_ = rank_ % get_env().num_ranks_per_host;
sched_.reset(static_cast<BaseScheduler *>(new DefaultScheduler{
model, gpu_id_, rank_, world_size_, num_warps_per_sm}));

ctx_ = sched_->create_context();
const GpuManager::Info &ginfo = ctx_->get_gpu_manager()->info();
stream_ = ctx_->get_gpu_manager()->create_stream();
glk_ = std::make_unique<GpuLoopKernel>(
ctx_, name, sched_->gen_code(), ginfo.num_sm, num_warps_per_sm,
(unsigned int)ginfo.smem_block_total);
}

void Executor::Impl::compile() { glk_->compile(); }

void Executor::Impl::launch() {
glk_->load();
glk_->launch(stream_, false);
}

void Executor::Impl::run(int iter) { glk_->run(iter); }

void Executor::Impl::wait() { glk_->wait(); }

float Executor::Impl::stop() {
glk_->stop();
return glk_->get_elapsed_msec();
}

Executor::Executor(int rank, int world_size, const Model &model, const Schedule &schedule,
const std::string &name, int num_warps_per_sm)
: impl_{std::make_unique<Executor::Impl>(rank, world_size, model, schedule, name,
num_warps_per_sm)} {}

Executor::~Executor() = default;

void Executor::compile() { impl_->compile(); }

void Executor::launch() { impl_->launch(); }

void Executor::run(int iter) { impl_->run(iter); }

void Executor::wait() { impl_->wait(); }

float Executor::stop() { return impl_->stop(); }

} // namespace ark
1 change: 0 additions & 1 deletion ark/file_io.cc → ark/file_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <fstream>
#include <sstream>

#include "include/ark.h"
#include "logging.h"

namespace fs = std::filesystem;
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion ark/gpu/gpu_comm_sw.cc → ark/gpu/gpu_comm_sw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "env.h"
#include "gpu/gpu_logging.h"
#include "gpu/gpu_manager.h"
#include "include/ark.h"
#include "ipc/ipc_hosts.h"
#include "ipc/ipc_socket.h"

Expand Down
3 changes: 1 addition & 2 deletions ark/gpu/gpu_compile.cc → ark/gpu/gpu_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include "env.h"
#include "file_io.h"
#include "gpu/gpu_logging.h"
#include "include/ark.h"
#include "random.h"
#include "ark/random.hpp"

#define ARK_DEBUG_KERNEL 0

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions ark/gpu/gpu_context_test.cc → ark/gpu/gpu_context_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <numeric>

#include "include/ark.h"
#include "unittest/unittest_utils.h"

// Test initializing and destroying GpuContext
Expand Down Expand Up @@ -178,7 +177,6 @@ ark::unittest::State test_gpu_context_remote() {
}

int main() {
ark::init();
UNITTEST(test_gpu_context_basic);
UNITTEST(test_gpu_context_buffer_free);
UNITTEST(test_gpu_context_buffer_alloc);
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion ark/gpu/gpu_kernel_test.cc → ark/gpu/gpu_kernel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "gpu/gpu_kernel.h"

#include "gpu/gpu_loop_kernel.h"
#include "include/ark.h"
#include "unittest/unittest_utils.h"

const std::string void_kernel = "extern \"C\" __global__ void kernel() {}";
Expand Down
1 change: 0 additions & 1 deletion ark/gpu/gpu_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#define ARK_GPU_LOGGING_H_

#include "gpu/gpu.h"
#include "include/ark.h"
#include "logging.h"

#define GLOG(cmd) \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions ark/include/ark.h → ark/include/ark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#define ARK_PATCH 0
#define ARK_VERSION (ARK_MAJOR * 10000 + ARK_MINOR * 100 + ARK_PATCH)

#include "ark/dims.h"
#include "ark/error.h"
#include "ark/executor.h"
#include "ark/model.h"
#include "ark/dims.hpp"
#include "ark/error.hpp"
// #include "ark/executor.hpp"
#include "ark/model.hpp"

namespace ark {

Expand Down
13 changes: 8 additions & 5 deletions ark/include/ark/dims.h → ark/include/ark/dims.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#ifndef ARK_DIMS_H
#define ARK_DIMS_H
#ifndef ARK_DIMS_HPP
#define ARK_DIMS_HPP

#include <ostream>
#include <string>
Expand All @@ -11,11 +11,12 @@
namespace ark {

// Data type for dimension.
typedef long long int DimType;
typedef int64_t DimType;

// DIMS_LEN is the maximum number of dimensions of a tensor. If a tensor
// has less than DIMS_LEN dimensions, the remaining dimensions will be NO_DIM.
enum { DIMS_LEN = 4, NO_DIM = -1 };
constexpr DimType NO_DIM = -1;
constexpr DimType DIMS_LEN = 4;

// Up-to-`DIMS_LEN`-dimensional vector.
class Dims {
Expand All @@ -39,6 +40,8 @@ class Dims {
int ndims() const;
// Return a new Dims object with 4 valid dimensions by prepending 1s.
Dims dims4() const;
// Return true if all valid dimensions are zero.
bool is_zeros() const;
// Return true if the dimensions are empty.
bool is_no_dim() const;
// Return true if the dimensions are invalid.
Expand All @@ -64,4 +67,4 @@ class Dims {

} // namespace ark

#endif // ARK_DIMS_H
#endif // ARK_DIMS_HPP
Loading

0 comments on commit 473288c

Please sign in to comment.