VART-X  0.3.0
vart_plkernel.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2024-2026 Advanced Micro Devices Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
24 #include <any>
25 #include <memory>
26 #include <string>
27 #include <utility>
28 #include <vector>
30 #include "vart_device.hpp"
31 #include "vart_plkernel_types.hpp"
32 
35 namespace vart {
36 
40 class PLKernelImplBase;
41 
47 class PLKernel {
48  public:
62  const std::string& kernel_name,
63  std::string& json_data,
64  std::shared_ptr<Device> device);
65 
72  PLKernel(std::shared_ptr<PLKernelImplBase> ptr);
73 
80  const std::shared_ptr<PLKernelImplBase>& get_pimpl_handle() const;
81 
90  template <typename... Args>
91  void process(Args&&... args) {
92  try {
93  std::vector<std::any> any_args = {std::forward<Args>(args)...};
94  pimpl->process(any_args);
95  } catch (...) {
96  /* Rethrow the caught exception */
97  throw;
98  }
99  }
100 
110  int wait(unsigned int timeout);
111 
120  template <typename PLKernelAnyInfo>
121  void set_config(PLKernelAnyInfo& info) {
122  pimpl->set_config(info);
123  }
124 
136  template <typename PLKernelAnyInfo>
137  void get_config(PLKernelAnyInfo& info) {
138  std::any any_info = info;
139  pimpl->get_config_impl(any_info);
140  info = std::any_cast<PLKernelAnyInfo>(any_info);
141  }
142 
143  private:
144  std::shared_ptr<PLKernelImplBase> pimpl;
145 };
146 
147 } // namespace vart
PLKernel class for managing PL kernel execution.
Definition: vart_plkernel.hpp:47
void process(Args &&... args)
process() - Set and process the given arguments on Kernel.
Definition: vart_plkernel.hpp:91
void get_config(PLKernelAnyInfo &info)
get_config() - Gets the configuration of the kernel.
Definition: vart_plkernel.hpp:137
const std::shared_ptr< PLKernelImplBase > & get_pimpl_handle() const
get_pimpl_handle() - Gives pointer to implementation class.
void set_config(PLKernelAnyInfo &info)
set_config() - Sets the configuration for the kernel.
Definition: vart_plkernel.hpp:121
PLKernel(PLKernelImplType type, const std::string &kernel_name, std::string &json_data, std::shared_ptr< Device > device)
PLKernel() - Constructs a PLKernel object.
PLKernel(std::shared_ptr< PLKernelImplBase > ptr)
PLKernel() - Constructs a PLKernel object with a given implementation pointer.
int wait(unsigned int timeout)
wait() - Waits for the kernel to complete processing.
VART (Vitis AI Runtime) public API namespace.
PLKernelImplType
Definition: vart_plkernel_types.hpp:29
Device module managing hardware context and xclbin loading.