// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <openvino/runtime/core.hpp>
#include <openvino/runtime/intel_npu/level_zero/level_zero.hpp>
#include <openvino/runtime/intel_npu/properties.hpp>
#include <openvino/runtime/intel_npu/remote_properties.hpp>

int main() {
    ov::Core core;
    auto model = core.read_model("model.xml");
    auto input = model->get_parameters().at(0);

    auto compiled_model = core.compile_model(model, "NPU");
    auto npu_context = compiled_model.get_context().as<ov::intel_npu::level_zero::ZeroContext>();

    auto in_element_type = input->get_element_type();
    auto in_shape = input->get_shape();

    {
        //! [default_context_from_core]
        auto npu_context = core.get_default_context("NPU").as<ov::intel_npu::level_zero::ZeroContext>();
        // Extract raw level zero context handle from RemoteContext
        void* context_handle = npu_context.get();
        //! [default_context_from_core]
    }

    {
        //! [default_context_from_model]
        auto npu_context = compiled_model.get_context().as<ov::intel_npu::level_zero::ZeroContext>();
        // Extract raw level zero context handle from RemoteContext
        void* context_handle = npu_context.get();
        //! [default_context_from_model]
    }

    {
        //! [file_mapping]
        ov::intel_npu::FileDescriptor file_descriptor{"file_name"};
        auto remote_tensor = npu_context.create_tensor(in_element_type, in_shape, file_descriptor);
        //! [file_mapping]
    }

    {
        //! [wrap_nt_handle]
        void* shared_buffer = nullptr;
        ov::intel_npu::MemType memory_type = ov::intel_npu::MemType::SHARED_BUF;
        auto remote_tensor = npu_context.create_tensor(in_element_type, in_shape, shared_buffer, memory_type);
        //! [wrap_nt_handle]
    }

    {
        //! [import_cpu_va]
        void* standard_allocation = nullptr;
        ov::intel_npu::MemType memory_type = ov::intel_npu::MemType::CPU_VA;
        auto remote_tensor = npu_context.create_tensor(in_element_type, in_shape, standard_allocation, memory_type);
        //! [import_cpu_va]
    }

    {
        //! [wrap_dmabuf_fd]
        int32_t fd_heap = 0;  // create the DMA-BUF System Heap file descriptor
        ov::intel_npu::MemType memory_type = ov::intel_npu::MemType::SHARED_BUF;
        auto remote_tensor = npu_context.create_tensor(in_element_type, in_shape, fd_heap, memory_type);
        //! [wrap_dmabuf_fd]
    }

    {
        //! [wrap_dmabuf_fd]
        ov::intel_npu::FileDescriptor file_descriptor{"file_path.bin", 0};  // create the FileDescriptor
        auto remote_tensor = npu_context.create_tensor(in_element_type, in_shape, file_descriptor);
        //! [wrap_dmabuf_fd]
    }

    {
        //! [allocate_remote_level_zero_host]
        auto remote_tensor = npu_context.create_l0_host_tensor(in_element_type, in_shape);
        // Extract raw level zero pointer from remote tensor
        void* level_zero_ptr = remote_tensor.get();
        //! [allocate_remote_level_zero_host]
    }

    {
        //! [allocate_level_zero_host]
        auto tensor = npu_context.create_host_tensor(in_element_type, in_shape);
        // Extract raw level zero pointer from remote tensor
        void* level_zero_ptr = tensor.data();
        //! [allocate_level_zero_host]
    }

    return 0;
}
