Skip to content

Commit

Permalink
Create factory API
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandropalla committed Jul 16, 2024
1 parent 1931246 commit f2ff0cd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
12 changes: 4 additions & 8 deletions examples/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ int main() {
std::cout << "Create a ModelFactory" << std::endl;
auto factory = std::make_shared<ModelFactory>("NPU");

auto context = factory->get_context();

// create parameter
auto input = factory->parameter({batch, inC}, ov::element::f16);
auto weights = factory->parameter({outC, inC}, ov::element::f16);
Expand All @@ -34,12 +32,10 @@ int main() {
// factory->saveModel("matmul.xml");

std::cout << "Creating a remote tensor" << std::endl;
auto input_buffer = context.create_l0_host_tensor(ov::element::f16, {batch, inC}, ov::intel_npu::TensorType::INPUT);
auto weights_buffer =
context.create_l0_host_tensor(ov::element::f16, {outC, inC}, ov::intel_npu::TensorType::INPUT);
auto bias_buffer = context.create_l0_host_tensor(ov::element::f16, {1, outC}, ov::intel_npu::TensorType::INPUT);
auto output_buffer =
context.create_l0_host_tensor(ov::element::f16, {batch, outC}, ov::intel_npu::TensorType::OUTPUT);
auto input_buffer = factory->createRemoteInputTensor(0);
auto weights_buffer = factory->createRemoteInputTensor(1);
auto bias_buffer = factory->createRemoteInputTensor(2);
auto output_buffer = factory->createRemoteOutputTensor(0);

std::memset(input_buffer.get(), 0, input_buffer.get_byte_size());
std::memset(weights_buffer.get(), 0, weights_buffer.get_byte_size());
Expand Down
36 changes: 36 additions & 0 deletions include/intel_npu_acceleration_library/inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,42 @@ class OVInferenceModel {
}
}

/**
* @brief Create a Remote Tensor object
*
* @param type element type
* @param shape element shape
* @param tensor_type element tensor type: INPUT, OUTPUT, BIND
* @return auto
*/
auto createRemoteTensor(const ov::element::Type type, const ov::Shape& shape,
const ov::intel_npu::TensorType tensor_type) {
ov::intel_npu::level_zero::ZeroContext context = get_context();
return context.create_l0_host_tensor(type, shape, tensor_type);
}

/**
* @brief Create a Remote Tensor object
*
* @param idx index of the input tensor
* @return auto
*/
auto createRemoteInputTensor(size_t idx) {
auto tensor = infer_request.get_input_tensor(idx);
return createRemoteTensor(tensor.get_element_type(), tensor.get_shape(), ov::intel_npu::TensorType::INPUT);
}

/**
* @brief Create a Remote Tensor object
*
* @param idx index of the output tensor
* @return auto
*/
auto createRemoteOutputTensor(size_t idx) {
auto tensor = infer_request.get_output_tensor(idx);
return createRemoteTensor(tensor.get_element_type(), tensor.get_shape(), ov::intel_npu::TensorType::OUTPUT);
}

/**
* @brief Get model input tensor
*
Expand Down

0 comments on commit f2ff0cd

Please sign in to comment.