Skip to content

Commit

Permalink
Merge branch 'modelbox-ai:main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zxk114 authored Nov 6, 2024
2 parents edbd1b9 + faa1e93 commit 7dd1d6b
Show file tree
Hide file tree
Showing 34 changed files with 763 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test-daily-on-device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_CN_MIRROR=yes -DCLANG_TIDY=on -DCLANG_TIDY_AS_ERROR=on
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCLANG_TIDY=on -DCLANG_TIDY_AS_ERROR=on
- name: Build
working-directory: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test-pull-requests-on-device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_CN_MIRROR=yes -DWITH_WEBUI=${{github.event.inputs.WithWebUI}} -DCLANG_TIDY=${{github.event.inputs.WithClangTidy}} -DCLANG_TIDY_AS_ERROR=on
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWITH_WEBUI=${{github.event.inputs.WithWebUI}} -DCLANG_TIDY=${{github.event.inputs.WithClangTidy}} -DCLANG_TIDY_AS_ERROR=on
- name: Build
working-directory: build
Expand Down
47 changes: 44 additions & 3 deletions src/drivers/common/python/modelbox_api/modelbox_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ bool SetAttributes(DataType &context, const std::string &key,

if (py::isinstance<py::list>(obj)) {
py::list obj_list_all = obj.cast<py::list>();
if (obj_list_all.empty()) {
return setup_data(List1DObjectFunc, obj_list_all, obj_list_all);
}
if (py::isinstance<py::list>(obj_list_all[0])) {
py::list obj_list_1d = obj_list_all[0].cast<py::list>();
if (obj_list_1d.empty()) {
return setup_data(List2DObjectFunc, obj_list_1d, obj_list_all);
}
if (setup_data(List2DObjectFunc, obj_list_1d[0], obj_list_all)) {
return true;
}
Expand Down Expand Up @@ -192,6 +198,12 @@ bool GetAttributes(void *value, std::size_t value_type,
ret_data = *((py::object *)(value));
return true;
}

if (typeid(std::shared_ptr<py::object>).hash_code() == value_type) {
ret_data = *(*((std::shared_ptr<py::object> *)(value)));
return true;
}

return false;
}

Expand Down Expand Up @@ -233,6 +245,17 @@ void BufferSetAttributes(Buffer &buffer, const std::string &key,
return;
}

if (py::isinstance<py::object>(obj)) {
auto *obj_ptr = new py::object();
*obj_ptr = obj;
auto obj_shared = std::shared_ptr<py::object>(obj_ptr, [](void *ptr) {
py::gil_scoped_acquire interpreter_guard{};
delete static_cast<py::object *>(ptr);
});
buffer.Set(key, obj_shared);
return;
}

throw std::invalid_argument("invalid data type " +
py::str(obj).cast<std::string>() + " for key " +
key);
Expand Down Expand Up @@ -738,7 +761,25 @@ void ModelboxPyApiSetUpBuffer(pybind11::module &m) {
return buffer;
}),
py::keep_alive<1, 2>())
.def(py::init([](const std::shared_ptr<modelbox::Device> &device) {
auto buffer = std::make_shared<Buffer>(device);
return buffer;
}),
py::keep_alive<1, 2>())
.def(py::init<const Buffer &>())
.def("build", [](std::shared_ptr<Buffer> &buffer, const std::string &str) {
StrToBuffer(buffer, str);
})
.def("build", [](std::shared_ptr<Buffer> &buffer, const py::list &li) {
ListToBuffer(buffer, li);
})
.def("build", [](std::shared_ptr<Buffer> &buffer, const py::buffer &buf) {
PyBufferToBuffer(buffer, buf);
})
.def("as_bytes", [](Buffer &buffer) {
return py::bytes{(const char *)buffer.ConstData(),
buffer.GetBytes()};
})
.def("as_object",
[](Buffer &buffer) -> py::object {
return BufferToPyObject(buffer);
Expand All @@ -760,9 +801,8 @@ void ModelboxPyApiSetUpBuffer(pybind11::module &m) {
buffer.CopyMeta(other_ptr);
})
.def("set",
[](Buffer &buffer, const std::string &key, py::object &obj) {
BufferSetAttributes(buffer, key, obj);
})
[](Buffer &buffer, const std::string &key,
py::object &obj) { BufferSetAttributes(buffer, key, obj); })
.def("get", BufferGetAttributes);

ModelboxPyApiSetUpDataType(h);
Expand All @@ -784,6 +824,7 @@ void ModelboxPyApiSetUpBufferList(pybind11::module &m) {
})
.def("size", &modelbox::BufferList::Size)
.def("get_bytes", &modelbox::BufferList::GetBytes)
.def("get_device", &modelbox::BufferList::GetDevice)
.def(
"push_back",
[](BufferList &bl, Buffer &buffer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ void AscendVideoDecoder::Callback(acldvppStreamDesc *input,

auto *ctx = (DvppVideoDecodeContext *)userData;
auto queue = ctx->GetCacheQueue();
if (queue == nullptr) {
acldvppFree(vdecOutBufferDev);
MBLOG_ERROR << "get cache queue failed.";
return;
}
auto res = queue->Push(dvpp_frame);
if (!res) {
acldvppFree(vdecOutBufferDev);
Expand All @@ -214,6 +219,7 @@ void AscendVideoDecoder::Callback(acldvppStreamDesc *input,

modelbox::Status AscendVideoDecoder::Init(
const std::shared_ptr<modelbox::DataContext> &data_ctx) {
vdecChannelDesc_ = nullptr;
aclError ret = aclrtSetDevice(device_id_);
if (ret != ACL_ERROR_NONE) {
auto errMsg = "acl set device " + std::to_string(device_id_) +
Expand Down Expand Up @@ -304,22 +310,17 @@ modelbox::Status AscendVideoDecoder::Init(

auto device_id = device_id_;
vdecChannelDesc_.reset(
vdecChannelDescPtr, [device_id](aclvdecChannelDesc *p) {
auto ret = aclrtSetDevice(device_id);
if (ret != ACL_ERROR_NONE) {
MBLOG_ERROR << "Set device to " << device_id
<< " failed, err: " << ret;
}

ret = aclvdecDestroyChannel(p);
vdecChannelDescPtr, [this, device_id](aclvdecChannelDesc *p) {
auto ret = aclvdecDestroyChannel(p);
if (ret != ACL_ERROR_NONE) {
MBLOG_ERROR << "fail to destroy vdec channel, err: " << ret;
}

ret = aclvdecDestroyChannelDesc(p);
if (ret != ACL_ERROR_NONE) {
MBLOG_ERROR << "fail to destroy vdec channel desc, err: " << ret;
}

this->thread_handler_ = nullptr;
});

setup_result = true;
Expand Down
Loading

0 comments on commit 7dd1d6b

Please sign in to comment.