Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chhwang committed Sep 6, 2024
1 parent 771a41d commit 006af24
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 2,317 deletions.
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/third_party/mscclpp/include",
"/usr/local/cuda/include",
"/opt/rocm/include"
],
Expand Down
16 changes: 10 additions & 6 deletions ark/api/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ class Executor::Impl {

private:
std::shared_ptr<BufferRegistry::Info> get_buffer_info(
const Tensor &tensor) const;
const Tensor &tensor, bool fail_on_null) const;

std::map<PlanResourceKey, std::shared_ptr<PlanResource>> plan_resources_;
std::shared_ptr<PlanResource> foreground_plan_resource_;
Expand Down Expand Up @@ -1039,11 +1039,11 @@ void Executor::Impl::barrier() {
}

std::shared_ptr<BufferRegistry::Info> Executor::Impl::get_buffer_info(
const Tensor &tensor) const {
const Tensor &tensor, bool fail_on_null) const {
size_t buffer_id = tensor.ref()->buffer()->id();
auto &buf_reg = BufferRegistry::get_instance();
auto info = buf_reg.get(buffer_id);
if (!info || !(info->data)) {
if (fail_on_null && (!info || !(info->data))) {
ERR(InvalidUsageError,
"Tensor has no allocated memory. "
"This is likely caused by accessing a tensor that is optimized "
Expand All @@ -1054,12 +1054,16 @@ std::shared_ptr<BufferRegistry::Info> Executor::Impl::get_buffer_info(
}

void *Executor::Impl::tensor_address(const Tensor &tensor) const {
return get_buffer_info(tensor)->data;
auto info = get_buffer_info(tensor, false);
if (!info || !(info->data)) {
return nullptr;
}
return info->data;
}

void Executor::Impl::tensor_read(const Tensor &tensor, void *data, size_t bytes,
Stream stream, bool is_d2d) const {
auto info = get_buffer_info(tensor);
auto info = get_buffer_info(tensor, true);
size_t device_id = info->device_id;
GLOG(gpuSetDevice(device_id));
std::shared_ptr<GpuStream> copy_stream;
Expand Down Expand Up @@ -1112,7 +1116,7 @@ void Executor::Impl::tensor_read(const Tensor &tensor, void *data, size_t bytes,
void Executor::Impl::tensor_write(const Tensor &tensor, const void *data,
size_t bytes, Stream stream,
bool is_d2d) const {
auto info = get_buffer_info(tensor);
auto info = get_buffer_info(tensor, true);
size_t device_id = info->device_id;
GLOG(gpuSetDevice(device_id));
std::shared_ptr<GpuStream> copy_stream;
Expand Down
29 changes: 29 additions & 0 deletions ark/api/executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "ark/executor.hpp"

#include "ark/planner.hpp"
#include "gpu/gpu.hpp"
#include "model/model_json.hpp"
#include "unittest/unittest_utils.h"
Expand Down Expand Up @@ -54,6 +55,34 @@ ark::unittest::State test_executor() {
// Stop & destroy automatically.
}

// Raw executor test
ark::Model m;
auto tensor = m.tensor({1024}, ark::FP32);
m.noop(tensor);

ark::Planner planner(m, 0);
auto plan = planner.plan();
{
std::vector<float> array(1024);

ark::Executor exe;
UNITTEST_EQ(exe.tensor_address(tensor), nullptr);
UNITTEST_THROW(
exe.tensor_read(tensor, array.data(), array.size() * sizeof(float)),
ark::InvalidUsageError);
UNITTEST_THROW(exe.tensor_write(tensor, array.data(),
array.size() * sizeof(float)),
ark::InvalidUsageError);
UNITTEST_THROW(exe.launch(), ark::InvalidUsageError);

exe.compile(plan, 0);
UNITTEST_NE(exe.tensor_address(tensor), nullptr);

exe.launch();
exe.run(1);
exe.wait();
}

UNITTEST_EQ(ark::gpuStreamDestroy(stream), ark::gpuSuccess);
return ark::unittest::SUCCESS;
}
Expand Down
271 changes: 0 additions & 271 deletions examples/tutorial/default_plan.json

This file was deleted.

Loading

0 comments on commit 006af24

Please sign in to comment.