Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled Model.getOps() method #25470 #28572

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bindings/js/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ add_library(${PROJECT_NAME} SHARED
${CMAKE_CURRENT_SOURCE_DIR}/src/addon.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/element_type.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/partial_shape_wrap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/node_wrap.cpp

${CMAKE_JS_SRC}
)
Expand Down
12 changes: 12 additions & 0 deletions src/bindings/js/node/lib/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ interface Model {
* @param index The index of the output.
*/
getOutputElementType(index: number): string;

/**
* It gets the operations (nodes) of the model.
* @returns An array of Node objects representing the operations in the model.
*/
getOps(): Node[];
/**
* It gets the input of the model.
* If a model has more than one input, this method throws an exception.
Expand Down Expand Up @@ -309,6 +315,12 @@ interface Model {
outputs: Output[];
}

interface Node {
/**
* It gets the name of the node.
*/
getName(): string;
}
/**
* CompiledModel represents a model that is compiled for a specific device
* by applying multiple optimization transformations,
Expand Down
3 changes: 3 additions & 0 deletions src/bindings/js/node/src/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ void init_class(Napi::Env env,
exports.Set(class_name, prototype);
}

Prototype func = NodeWrap::get_class()
addon_data->node = Napi::Persistent(prototype);

Napi::Value save_model_sync(const Napi::CallbackInfo& info) {
std::vector<std::string> allowed_signatures;
try {
Expand Down
11 changes: 11 additions & 0 deletions src/bindings/js/node/src/model_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "node/include/helper.hpp"
#include "node/include/node_output.hpp"
#include "node/include/type_validation.hpp"
#include "model_wrap.h"
#include "node_wrap.h"

ModelWrap::ModelWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<ModelWrap>(info),
Expand Down Expand Up @@ -204,3 +206,12 @@ Napi::Value ModelWrap::clone(const Napi::CallbackInfo& info) {
return info.Env().Undefined();
}
}

Napi::Value ModelWrap::get_ops(const Napi::CallbackInfo& info) {
std::vector<ov::Node*> ops = this->model_->get_ops();
Napi::Array result = Napi::Array::New(info.Env(), ops.size());
for (size_t i = 0; i < ops.size(); i++) {
result[i] = NodeWrap::New(info.Env(), ops[i]);
}
return result;
}
32 changes: 32 additions & 0 deletions src/bindings/js/node/src/node_wrap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "node_wrap.h"

Napi::FunctionReference NodeWrap::constructor;

//NodeWrap
NodeWrap::NodeWrap(const Napi::CallbackInfo& info, ov::Node* node) : Napi::ObjectWrap<NodeWrap>(info) {
this->node_ = node;
}

Napi::Value NodeWrap::get_name(const Napi::CallbackInfo& info) {
return Napi::String::New(info.Env(), this->node_->get_name());
}

Napi::Object NodeWrap::New(Napi::Env env, ov::Node* node) {
Napi::Object obj = Napi::ObjectWrap<NodeWrap>::New(env, node);
return obj;
}

Napi::Object Init(Napi::Env env, Napi::Object exports) {
Napi::Function func = DefineClass(env, "Node", {
InstanceMethod("getName", &NodeWrap::get_name),
}, [](const Napi::CallbackInfo& info) {
ov::Node* node = info[0].As<Napi::External<ov::Node>>().Data();
return NodeWrap::New(env, node);
});

constructor = Napi::Persistent(func);
exports.Set("Node", func);
return exports;
}

NODE_API_MODULE(Node, Init)
24 changes: 24 additions & 0 deletions src/bindings/js/node/src/node_wrap.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include <napi.h>
#include <ov/node.hpp>

#include <openvino/openvino.hpp>

class NodeWrap : public Napi::ObjectWrap<NodeWrap> {
public:
/**
* constructor
* @brief Constructs NodeWrap from the Napi::CallbackInfo.
* @param info contains passed arguments. Can be empty.
* @param node pointer to ov::Node object.
*/
NodeWrap(const Napi::CallbackInfo& info, ov::Node* node);

// member functions
Napi::Value get_name(const Napi::CallbackInfo& info);

private:
ov::Node* node_;
};

#endif //NODE_WRAP_H
27 changes: 27 additions & 0 deletions src/bindings/js/node/tests/unit/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,31 @@ describe('ov.Model tests', () => {
);
});
});

describe('Node.js Model.getOps()', () => {
it('should return array of Node operations', () => {
const result = model.getOps();

assert(Array.isArray(result), 'getOps should return an array');
assert(result.length > 0, 'getOps should return a non-empty array');
result.forEach(op => {
assert.strictEqual(typeof op.getName, 'function', 'each item should have getName method');
});
});

it('should return the expected operation', () => {
const result = model.getOps();

const modelOperators = result.map(op => op.getName().split('_')[0]);
const expectedOpsCount = 14;
const expectedOps = [
"Subtract",
"Transpose",
];

assert.strictEqual(modelOperators.length, expectedOpsCount, `Expected ${expectedOpsCount} operations in the model`);
expectedOps.forEach(op => {
assert(modelOperators.includes(op), `Expected operation ${op} to be in the model`);
});
});
});
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/thirdparty/onednn
Submodule onednn updated 1677 files
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/thirdparty/onednn_gpu
Submodule onednn_gpu updated 1215 files
2 changes: 1 addition & 1 deletion thirdparty/level_zero/level-zero
Submodule level-zero updated 58 files
+0 −12 CHANGELOG.md
+2 −2 CMakeLists.txt
+9 −11 CONTRIBUTING.md
+1 −1 README.md
+0 −146 include/layers/zel_tracing_register_cb.h
+5 −197 include/ze.py
+3 −340 include/ze_api.h
+1 −77 include/ze_ddi.h
+5 −27 include/zes.py
+4 −47 include/zes_api.h
+1 −39 include/zes_ddi.h
+2 −7 include/zet.py
+10 −19 include/zet_api.h
+1 −25 include/zet_ddi.h
+1 −1 samples/zello_world/CMakeLists.txt
+4 −9 scripts/templates/helper.py
+2 −4 scripts/templates/libapi.cpp.mako
+0 −12 scripts/templates/libddi.cpp.mako
+21 −13 source/CMakeLists.txt
+0 −122 source/drivers/null/ze_nullddi.cpp
+0 −26 source/drivers/null/zes_nullddi.cpp
+2 −2 source/drivers/null/zet_nullddi.cpp
+1 −1 source/inc/ze_util.h
+0 −4 source/layers/tracing/ze_tracing_cb_structs.h
+0 −64 source/layers/tracing/ze_tracing_register_cb.cpp
+0 −188 source/layers/tracing/ze_trcddi.cpp
+4 −2 source/layers/validation/README.md
+1 −4 source/layers/validation/checkers/events_checker/zel_events_checker.cpp
+0 −107 source/layers/validation/checkers/parameter_validation/ze_parameter_validation.cpp
+0 −4 source/layers/validation/checkers/parameter_validation/ze_parameter_validation.h
+0 −16 source/layers/validation/checkers/parameter_validation/zes_parameter_validation.cpp
+0 −1 source/layers/validation/checkers/parameter_validation/zes_parameter_validation.h
+2 −2 source/layers/validation/checkers/parameter_validation/zet_parameter_validation.cpp
+0 −8 source/layers/validation/common/ze_entry_points.h
+0 −2 source/layers/validation/common/zes_entry_points.h
+0 −96 source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.cpp
+0 −4 source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.h
+0 −12 source/layers/validation/handle_lifetime_tracking/zes_handle_lifetime.cpp
+0 −1 source/layers/validation/handle_lifetime_tracking/zes_handle_lifetime.h
+2 −2 source/layers/validation/handle_lifetime_tracking/zet_handle_lifetime.cpp
+0 −188 source/layers/validation/ze_valddi.cpp
+0 −43 source/layers/validation/zes_valddi.cpp
+2 −2 source/layers/validation/zet_valddi.cpp
+3 −3 source/level-zero.pc.in
+2 −199 source/lib/ze_libapi.cpp
+0 −100 source/lib/ze_tracing_register_cb_libapi.cpp
+0 −40 source/lib/zes_libapi.cpp
+8 −10 source/lib/zet_libapi.cpp
+5 −3 source/libze_loader.pc.in
+0 −164 source/loader/ze_ldrddi.cpp
+0 −3 source/loader/ze_ldrddi.h
+0 −1 source/loader/ze_loader_internal.h
+0 −26 source/loader/zes_ldrddi.cpp
+2 −2 source/loader/zet_ldrddi.cpp
+4 −7 source/utils/CMakeLists.txt
+0 −2 test/CMakeLists.txt
+0 −17 test/loader_api.cpp
+2 −6 third_party/xla/ordered_set.h
1 change: 1 addition & 0 deletions thirdparty/open_model_zoo
Submodule open_model_zoo added at e7df86
Loading