Viet-Hoa Do | 500e10b | 2023-09-12 17:49:38 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2023 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #ifndef ACL_SRC_CORE_CL_CLCOMPATCOMMANDBUFFER_H |
| 26 | #define ACL_SRC_CORE_CL_CLCOMPATCOMMANDBUFFER_H |
| 27 | |
| 28 | #include "src/core/CL/CLCommandBuffer.h" |
| 29 | |
| 30 | #include <vector> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | |
| 35 | /** Command buffer implementation for platform without mutable dispatch command buffer extension. */ |
| 36 | class CLCompatCommandBuffer final : public CLCommandBuffer |
| 37 | { |
| 38 | public: |
| 39 | /** Create a new command buffer targeting the specified command queue. |
| 40 | * |
| 41 | * @param[in] queue The command queue to execute the command buffer. |
| 42 | */ |
| 43 | CLCompatCommandBuffer(cl_command_queue queue); |
| 44 | |
| 45 | /** Destructor. */ |
| 46 | virtual ~CLCompatCommandBuffer(); |
| 47 | |
| 48 | /** Disallow copy constructor. */ |
| 49 | CLCompatCommandBuffer(const CLCompatCommandBuffer &) = delete; |
| 50 | |
| 51 | /** Disallow copy assignment. */ |
| 52 | CLCompatCommandBuffer &operator=(const CLCompatCommandBuffer &) = delete; |
| 53 | |
| 54 | /** Disallow move constructor. */ |
| 55 | CLCompatCommandBuffer(CLCompatCommandBuffer &&) = delete; |
| 56 | |
| 57 | /** Disallow move assignment. */ |
| 58 | CLCompatCommandBuffer &operator=(CLCompatCommandBuffer &&) = delete; |
| 59 | |
| 60 | void add_kernel(cl_kernel kernel, const cl::NDRange &offset, const cl::NDRange &global, const cl::NDRange &local) override; |
| 61 | |
| 62 | void finalize() override; |
| 63 | |
| 64 | void update() override; |
| 65 | |
| 66 | void enqueue() override; |
| 67 | |
| 68 | bool is_finalized() const override; |
| 69 | |
| 70 | protected: |
| 71 | void add_mutable_argument_generic(cl_uint arg_idx, const void *value, size_t size) override; |
| 72 | |
| 73 | private: |
| 74 | struct KernelCommand |
| 75 | { |
| 76 | cl_kernel kernel; |
| 77 | cl::NDRange offset; |
| 78 | cl::NDRange global; |
| 79 | cl::NDRange local; |
| 80 | |
| 81 | std::vector<cl_mutable_dispatch_arg_khr> mutable_args; |
| 82 | }; |
| 83 | |
| 84 | private: |
| 85 | cl_command_queue _queue{}; |
| 86 | std::vector<KernelCommand> _kernel_cmds{}; |
| 87 | }; |
| 88 | |
| 89 | } // namespace arm_compute |
| 90 | |
| 91 | #endif // ACL_SRC_CORE_CL_CLCOMPATCOMMANDBUFFER_H |