diff --git a/.gitignore b/.gitignore index 4b852f97..b7386bef 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .vscode *.DS_Store *.blend1 -lab/assets/models/*.onnx -lab/assets/models/*.json -lab/assets/models/*.txt -lab/assets/models/*.zip +paint/assets/models/*.onnx +paint/assets/models/*.json +paint/assets/models/*.txt +paint/assets/models/*.zip diff --git a/base/tools/extract_locales.js b/base/tools/extract_locales.js index fdd826c5..1ff8baff 100644 --- a/base/tools/extract_locales.js +++ b/base/tools/extract_locales.js @@ -21,9 +21,7 @@ if (fs_exists(locale_path)) { let source_paths = [ "base/sources", "base/sources/nodes", - "paint/sources", "paint/sources/nodes", - "lab/sources", "lab/sources/nodes", - "forge/sources", "forge/sources/nodes" + "paint/sources", "paint/sources/nodes" ]; for (let path of source_paths) { diff --git a/lab/assets/badge.png b/lab/assets/badge.png deleted file mode 100644 index c06afa3d..00000000 Binary files a/lab/assets/badge.png and /dev/null differ diff --git a/lab/assets/default_brush.arm b/lab/assets/default_brush.arm deleted file mode 100644 index 28cc64e9..00000000 Binary files a/lab/assets/default_brush.arm and /dev/null differ diff --git a/lab/assets/keymap_presets/touch.json b/lab/assets/keymap_presets/touch.json deleted file mode 100644 index 5407c7d0..00000000 --- a/lab/assets/keymap_presets/touch.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "action_paint": "left", - "action_rotate": "left", - "action_pan": "right", - "action_zoom": "" -} diff --git a/lab/assets/licenses/license_esrgan.md b/lab/assets/licenses/license_esrgan.md deleted file mode 100644 index fb73735a..00000000 --- a/lab/assets/licenses/license_esrgan.md +++ /dev/null @@ -1,32 +0,0 @@ -real-esrgan-license: -https://github.com/xinntao/Real-ESRGAN - -BSD 3-Clause License - -Copyright (c) 2021, Xintao Wang -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lab/assets/licenses/license_onnx.md b/lab/assets/licenses/license_onnx.md deleted file mode 100644 index cbc27402..00000000 --- a/lab/assets/licenses/license_onnx.md +++ /dev/null @@ -1,23 +0,0 @@ -MIT License - -Copyright (c) Microsoft Corporation - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -https://github.com/microsoft/onnxruntime diff --git a/lab/assets/licenses/license_photo_to_pbr.md b/lab/assets/licenses/license_photo_to_pbr.md deleted file mode 100644 index e438c55c..00000000 --- a/lab/assets/licenses/license_photo_to_pbr.md +++ /dev/null @@ -1,44 +0,0 @@ -'Photo to PBR' node is based on work by: - -https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix - -Copyright (c) 2017, Jun-Yan Zhu and Taesung Park -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ---------------------------- LICENSE FOR pix2pix -------------------------------- -BSD License - -For pix2pix software -Copyright (c) 2016, Phillip Isola and Jun-Yan Zhu -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. diff --git a/lab/assets/licenses/license_sd.md b/lab/assets/licenses/license_sd.md deleted file mode 100644 index 38de58a4..00000000 --- a/lab/assets/licenses/license_sd.md +++ /dev/null @@ -1,83 +0,0 @@ - -stable-diffusion-license: -https://huggingface.co/CompVis/stable-diffusion-v1-4 - -Copyright (c) 2022 Robin Rombach and Patrick Esser and contributors - -CreativeML Open RAIL-M -dated August 22, 2022 - -Section I: PREAMBLE - -Multimodal generative models are being widely adopted and used, and have the potential to transform the way artists, among other individuals, conceive and benefit from AI or ML technologies as a tool for content creation. - -Notwithstanding the current and potential benefits that these artifacts can bring to society at large, there are also concerns about potential misuses of them, either due to their technical limitations or ethical considerations. - -In short, this license strives for both the open and responsible downstream use of the accompanying model. When it comes to the open character, we took inspiration from open source permissive licenses regarding the grant of IP rights. Referring to the downstream responsible use, we added use-based restrictions not permitting the use of the Model in very specific scenarios, in order for the licensor to be able to enforce the license in case potential misuses of the Model may occur. At the same time, we strive to promote open and responsible research on generative models for art and content generation. - -Even though downstream derivative versions of the model could be released under different licensing terms, the latter will always have to include - at minimum - the same use-based restrictions as the ones in the original license (this license). We believe in the intersection between open and responsible AI development; thus, this License aims to strike a balance between both in order to enable responsible open-science in the field of AI. - -This License governs the use of the model (and its derivatives) and is informed by the model card associated with the model. - -NOW THEREFORE, You and Licensor agree as follows: - -1. Definitions - -- "License" means the terms and conditions for use, reproduction, and Distribution as defined in this document. -- "Data" means a collection of information and/or content extracted from the dataset used with the Model, including to train, pretrain, or otherwise evaluate the Model. The Data is not licensed under this License. -- "Output" means the results of operating a Model as embodied in informational content resulting therefrom. -- "Model" means any accompanying machine-learning based assemblies (including checkpoints), consisting of learnt weights, parameters (including optimizer states), corresponding to the model architecture as embodied in the Complementary Material, that have been trained or tuned, in whole or in part on the Data, using the Complementary Material. -- "Derivatives of the Model" means all modifications to the Model, works based on the Model, or any other model which is created or initialized by transfer of patterns of the weights, parameters, activations or output of the Model, to the other model, in order to cause the other model to perform similarly to the Model, including - but not limited to - distillation methods entailing the use of intermediate data representations or methods based on the generation of synthetic data by the Model for training the other model. -- "Complementary Material" means the accompanying source code and scripts used to define, run, load, benchmark or evaluate the Model, and used to prepare data for training or evaluation, if any. This includes any accompanying documentation, tutorials, examples, etc, if any. -- "Distribution" means any transmission, reproduction, publication or other sharing of the Model or Derivatives of the Model to a third party, including providing the Model as a hosted service made available by electronic or other remote means - e.g. API-based or web access. -- "Licensor" means the copyright owner or entity authorized by the copyright owner that is granting the License, including the persons or entities that may have rights in the Model and/or distributing the Model. -- "You" (or "Your") means an individual or Legal Entity exercising permissions granted by this License and/or making use of the Model for whichever purpose and in any field of use, including usage of the Model in an end-use application - e.g. chatbot, translator, image generator. -- "Third Parties" means individuals or legal entities that are not under common control with Licensor or You. -- "Contribution" means any work of authorship, including the original version of the Model and any modifications or additions to that Model or Derivatives of the Model thereof, that is intentionally submitted to Licensor for inclusion in the Model by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Model, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." -- "Contributor" means Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Model. - -Section II: INTELLECTUAL PROPERTY RIGHTS - -Both copyright and patent grants apply to the Model, Derivatives of the Model and Complementary Material. The Model and Derivatives of the Model are subject to additional terms as described in Section III. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare, publicly display, publicly perform, sublicense, and distribute the Complementary Material, the Model, and Derivatives of the Model. -3. Grant of Patent License. Subject to the terms and conditions of this License and where and as applicable, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this paragraph) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Model and the Complementary Material, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Model to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Model and/or Complementary Material or a Contribution incorporated within the Model and/or Complementary Material constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for the Model and/or Work shall terminate as of the date such litigation is asserted or filed. - -Section III: CONDITIONS OF USAGE, DISTRIBUTION AND REDISTRIBUTION - -4. Distribution and Redistribution. You may host for Third Party remote access purposes (e.g. software-as-a-service), reproduce and distribute copies of the Model or Derivatives of the Model thereof in any medium, with or without modifications, provided that You meet the following conditions: -Use-based restrictions as referenced in paragraph 5 MUST be included as an enforceable provision by You in any type of legal agreement (e.g. a license) governing the use and/or distribution of the Model or Derivatives of the Model, and You shall give notice to subsequent users You Distribute to, that the Model or Derivatives of the Model are subject to paragraph 5. This provision does not apply to the use of Complementary Material. -You must give any Third Party recipients of the Model or Derivatives of the Model a copy of this License; -You must cause any modified files to carry prominent notices stating that You changed the files; -You must retain all copyright, patent, trademark, and attribution notices excluding those notices that do not pertain to any part of the Model, Derivatives of the Model. -You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions - respecting paragraph 4.a. - for use, reproduction, or Distribution of Your modifications, or for any such Derivatives of the Model as a whole, provided Your use, reproduction, and Distribution of the Model otherwise complies with the conditions stated in this License. -5. Use-based restrictions. The restrictions set forth in Attachment A are considered Use-based restrictions. Therefore You cannot use the Model and the Derivatives of the Model for the specified restricted uses. You may use the Model subject to this License, including only for lawful purposes and in accordance with the License. Use may include creating any content with, finetuning, updating, running, training, evaluating and/or reparametrizing the Model. You shall require all of Your users who use the Model or a Derivative of the Model to comply with the terms of this paragraph (paragraph 5). -6. The Output You Generate. Except as set forth herein, Licensor claims no rights in the Output You generate using the Model. You are accountable for the Output you generate and its subsequent uses. No use of the output can contravene any provision as stated in the License. - -Section IV: OTHER PROVISIONS - -7. Updates and Runtime Restrictions. To the maximum extent permitted by law, Licensor reserves the right to restrict (remotely or otherwise) usage of the Model in violation of this License, update the Model through electronic means, or modify the Output of the Model based on updates. You shall undertake reasonable efforts to use the latest version of the Model. -8. Trademarks and related. Nothing in this License permits You to make use of Licensors’ trademarks, trade names, logos or to otherwise suggest endorsement or misrepresent the relationship between the parties; and any rights not expressly granted herein are reserved by the Licensors. -9. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Model and the Complementary Material (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Model, Derivatives of the Model, and the Complementary Material and assume any risks associated with Your exercise of permissions under this License. -10. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Model and the Complementary Material (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. -11. Accepting Warranty or Additional Liability. While redistributing the Model, Derivatives of the Model and the Complementary Material thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. -12. If any provision of this License is held to be invalid, illegal or unenforceable, the remaining provisions shall be unaffected thereby and remain valid as if such provision had not been set forth herein. - -END OF TERMS AND CONDITIONS - -Attachment A - -Use Restrictions - -You agree not to use the Model or Derivatives of the Model: -- In any way that violates any applicable national, federal, state, local or international law or regulation; -- For the purpose of exploiting, harming or attempting to exploit or harm minors in any way; -- To generate or disseminate verifiably false information and/or content with the purpose of harming others; -- To generate or disseminate personal identifiable information that can be used to harm an individual; -- To defame, disparage or otherwise harass others; -- For fully automated decision making that adversely impacts an individual’s legal rights or otherwise creates or modifies a binding, enforceable obligation; -- For any use intended to or which has the effect of discriminating against or harming individuals or groups based on online or offline social behavior or known or predicted personal or personality characteristics; -- To exploit any of the vulnerabilities of a specific group of persons based on their age, social, physical or mental characteristics, in order to materially distort the behavior of a person pertaining to that group in a manner that causes or is likely to cause that person or another person physical or psychological harm; -- For any use intended to or which has the effect of discriminating against individuals or groups based on legally protected characteristics or categories; -- To provide medical advice and medical results interpretation; -- To generate or disseminate information for the purpose to be used for administration of justice, law enforcement, immigration or asylum processes, such as predicting an individual will commit fraud/crime commitment (e.g. by text profiling, drawing causal relationships between assertions made in documents, indiscriminate and arbitrarily-targeted use). diff --git a/lab/assets/licenses/license_texsynth.md b/lab/assets/licenses/license_texsynth.md deleted file mode 100644 index 85ba8f32..00000000 --- a/lab/assets/licenses/license_texsynth.md +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2019 Embark Studios - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. - -https://github.com/EmbarkStudios/texture-synthesis diff --git a/lab/assets/meshes/keepme.txt b/lab/assets/meshes/keepme.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/lab/assets/models/README.md b/lab/assets/models/README.md deleted file mode 100644 index 6ed44dff..00000000 --- a/lab/assets/models/README.md +++ /dev/null @@ -1,2 +0,0 @@ - -Unpack `models.zip` from https://github.com/armory3d/armorai/releases using 7-Zip - Extract Here. diff --git a/lab/assets/placeholder.png b/lab/assets/placeholder.png deleted file mode 100644 index a5f2a1a5..00000000 Binary files a/lab/assets/placeholder.png and /dev/null differ diff --git a/lab/assets/plugins/keepme.txt b/lab/assets/plugins/keepme.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/lab/assets/readme/readme.txt b/lab/assets/readme/readme.txt deleted file mode 100644 index 33962edc..00000000 --- a/lab/assets/readme/readme.txt +++ /dev/null @@ -1,14 +0,0 @@ -Thank you for supporting ArmorLab! - -Quick start: -https://armory3d.org/lab/manual - - ( - ( )\ ) ) - )\ ( ) ( (()/( ) ( /( -((((_)( )( ( ( )( /(_)) ( /( )\()) - )\ _ )\(()\ )\ ' )\ (()\ (_)) )(_))((_)\ - (_)_\(_)((_) _((_)) ((_) ((_)| | ((_)_ | |(_) - / _ \ | '_|| ' \()/ _ \| '_|| |__ / _` || '_ \ - /_/ \_\|_| |_|_|_| \___/|_| |____|\__,_||_.__/ - diff --git a/lab/icon.png b/lab/icon.png deleted file mode 100644 index b8ac22fc..00000000 Binary files a/lab/icon.png and /dev/null differ diff --git a/lab/onnx/include/LICENSE b/lab/onnx/include/LICENSE deleted file mode 100644 index 48bc6bb4..00000000 --- a/lab/onnx/include/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) Microsoft Corporation - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/lab/onnx/include/coreml_provider_factory.h b/lab/onnx/include/coreml_provider_factory.h deleted file mode 100644 index f7857a3c..00000000 --- a/lab/onnx/include/coreml_provider_factory.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -#pragma once - -#include "onnxruntime_c_api.h" - -// COREMLFlags are bool options we want to set for CoreML EP -// This enum is defined as bit flags, and cannot have negative value -// To generate an uint32_t coreml_flags for using with OrtSessionOptionsAppendExecutionProvider_CoreML below, -// uint32_t coreml_flags = 0; -// coreml_flags |= COREML_FLAG_USE_CPU_ONLY; -enum COREMLFlags { - COREML_FLAG_USE_NONE = 0x000, - - // Using CPU only in CoreML EP, this may decrease the perf but will provide - // reference output value without precision loss, which is useful for validation - COREML_FLAG_USE_CPU_ONLY = 0x001, - - // Enable CoreML EP on subgraph - COREML_FLAG_ENABLE_ON_SUBGRAPH = 0x002, - - // By default CoreML Execution provider will be enabled for all compatible Apple devices - // Enable this option will only enable CoreML EP for Apple devices with ANE (Apple Neural Engine) - // Please note, enable this option does not guarantee the entire model to be executed using ANE only - COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE = 0x004, - - // Keep COREML_FLAG_MAX at the end of the enum definition - // And assign the last COREMLFlag to it - COREML_FLAG_LAST = COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE, -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ORT_EXPORT ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CoreML, - _In_ OrtSessionOptions* options, uint32_t coreml_flags); - -#ifdef __cplusplus -} -#endif diff --git a/lab/onnx/include/cpu_provider_factory.h b/lab/onnx/include/cpu_provider_factory.h deleted file mode 100644 index 29267869..00000000 --- a/lab/onnx/include/cpu_provider_factory.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "onnxruntime_c_api.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \param use_arena zero: false. non-zero: true. - */ -ORT_EXPORT -ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CPU, _In_ OrtSessionOptions* options, int use_arena) -ORT_ALL_ARGS_NONNULL; - -#ifdef __cplusplus -} -#endif diff --git a/lab/onnx/include/dml_provider_factory.h b/lab/onnx/include/dml_provider_factory.h deleted file mode 100644 index 6af7dac9..00000000 --- a/lab/onnx/include/dml_provider_factory.h +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -#pragma warning(push) -#pragma warning(disable : 4201) // nonstandard extension used: nameless struct/union -#ifdef _GAMING_XBOX_SCARLETT -#include -#elif defined(_GAMING_XBOX_XBOXONE) -#include -#else -#include -#endif -#pragma warning(pop) - -#ifdef __cplusplus - #include -#else - struct IDMLDevice; - typedef struct IDMLDevice IDMLDevice; -#endif - -// Windows pollutes the macro space, causing a build break in constants.h. -#undef OPTIONAL - -#include "onnxruntime_c_api.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * [[deprecated]] - * This export is deprecated. - * The OrtSessionOptionsAppendExecutionProvider_DML export on the OrtDmlApi should be used instead. - * - * Creates a DirectML Execution Provider which executes on the hardware adapter with the given device_id, also known as - * the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by - * IDXGIFactory::EnumAdapters. A device_id of 0 always corresponds to the default adapter, which is typically the - * primary display GPU installed on the system. A negative device_id is invalid. - */ -ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id); - -/** - * [[deprecated]] - * This export is deprecated. - * The OrtSessionOptionsAppendExecutionProvider_DML1 export on the OrtDmlApi should be used instead. - * - * Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12 - * command queue. The DirectML device and D3D12 command queue must have the same parent ID3D12Device, or an error will - * be returned. The D3D12 command queue must be of type DIRECT or COMPUTE (see D3D12_COMMAND_LIST_TYPE). If this - * function succeeds, the inference session maintains a strong reference on both the dml_device and the command_queue - * objects. - * See also: DMLCreateDevice - * See also: ID3D12Device::CreateCommandQueue - */ -ORT_API_STATUS(OrtSessionOptionsAppendExecutionProviderEx_DML, _In_ OrtSessionOptions* options, - _In_ IDMLDevice* dml_device, _In_ ID3D12CommandQueue* cmd_queue); - - -struct OrtDmlApi; -typedef struct OrtDmlApi OrtDmlApi; - -struct OrtDmlApi { - /** - * Creates a DirectML Execution Provider which executes on the hardware adapter with the given device_id, also known as - * the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by - * IDXGIFactory::EnumAdapters. A device_id of 0 always corresponds to the default adapter, which is typically the - * primary display GPU installed on the system. A negative device_id is invalid. - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id); - - /** - * Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12 - * command queue. The DirectML device and D3D12 command queue must have the same parent ID3D12Device, or an error will - * be returned. The D3D12 command queue must be of type DIRECT or COMPUTE (see D3D12_COMMAND_LIST_TYPE). If this - * function succeeds, the inference session maintains a strong reference on both the dml_device and the command_queue - * objects. - * See also: DMLCreateDevice - * See also: ID3D12Device::CreateCommandQueue - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML1, _In_ OrtSessionOptions* options, - _In_ IDMLDevice* dml_device, _In_ ID3D12CommandQueue* cmd_queue); - - /** - * CreateGPUAllocationFromD3DResource - * This API creates a DML EP resource based on a user-specified D3D12 resource. - */ - ORT_API2_STATUS(CreateGPUAllocationFromD3DResource, _In_ ID3D12Resource* d3d_resource, _Out_ void** dml_resource); - - /** - * FreeGPUAllocation - * This API frees the DML EP resource created by CreateGPUAllocationFromD3DResource. - */ - ORT_API2_STATUS(FreeGPUAllocation, _In_ void* dml_resource); - - /** - * GetD3D12ResourceFromAllocation - * This API gets the D3D12 resource when an OrtValue has been allocated by the DML EP. - */ - ORT_API2_STATUS(GetD3D12ResourceFromAllocation, _In_ OrtAllocator* provider, _In_ void* dml_resource, _Out_ ID3D12Resource** d3d_resource); -}; - -#ifdef __cplusplus -} -#endif diff --git a/lab/onnx/include/onnxruntime_c_api.h b/lab/onnx/include/onnxruntime_c_api.h deleted file mode 100644 index 44875b0f..00000000 --- a/lab/onnx/include/onnxruntime_c_api.h +++ /dev/null @@ -1,3987 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// See docs\c_cxx\README.md on generating the Doxygen documentation from this file - -/** \mainpage C & C++ APIs - * - *

C

- * - * ::OrtApi - Click here to go to the structure with all C API functions. - * - *

C++

- * - * ::Ort - Click here to go to the namespace holding all of the C++ wrapper classes - * - * It is a set of header only wrapper classes around the C API. The goal is to turn the C style return value error codes into C++ exceptions, and to - * automate memory management through standard C++ RAII principles. - * - * \addtogroup Global - * ONNX Runtime C API - * @{ - */ - -#pragma once -#include -#include -#include - -/** \brief The API version defined in this header - * - * This value is used by some API functions to behave as this version of the header expects. - */ -#define ORT_API_VERSION 14 - -#ifdef __cplusplus -extern "C" { -#endif - -//! @} -// SAL2 Definitions -#ifndef _WIN32 -#define _In_ -#define _In_z_ -#define _In_opt_ -#define _In_opt_z_ -#define _Out_ -#define _Outptr_ -#define _Out_opt_ -#define _Inout_ -#define _Inout_opt_ -#define _Frees_ptr_opt_ -#define _Ret_maybenull_ -#define _Ret_notnull_ -#define _Check_return_ -#define _Outptr_result_maybenull_ -#define _In_reads_(X) -#define _Inout_updates_all_(X) -#define _Out_writes_bytes_all_(X) -#define _Out_writes_all_(X) -#define _Success_(X) -#define _Outptr_result_buffer_maybenull_(X) -#define ORT_ALL_ARGS_NONNULL __attribute__((nonnull)) -#else -#include -#define ORT_ALL_ARGS_NONNULL -#endif - -#ifdef _WIN32 -// Define ORT_DLL_IMPORT if your program is dynamically linked to Ort. -// dllexport is not used, we use a .def file. -#ifdef ORT_DLL_IMPORT -#define ORT_EXPORT __declspec(dllimport) -#else -#define ORT_EXPORT -#endif -#define ORT_API_CALL _stdcall -#define ORT_MUST_USE_RESULT -#define ORTCHAR_T wchar_t -#else -// To make symbols visible on macOS/iOS -#ifdef __APPLE__ -#define ORT_EXPORT __attribute__((visibility("default"))) -#else -#define ORT_EXPORT -#endif -#define ORT_API_CALL -#define ORT_MUST_USE_RESULT __attribute__((warn_unused_result)) -#define ORTCHAR_T char -#endif - -#ifndef ORT_TSTR -#ifdef _WIN32 -#define ORT_TSTR(X) L##X -#else -#define ORT_TSTR(X) X -#endif -#endif - -// Any pointer marked with _In_ or _Out_, cannot be NULL. - -// Windows users should use unicode paths when possible to bypass the MAX_PATH limitation -// Every pointer marked with _In_ or _Out_, cannot be NULL. Caller should ensure that. -// for ReleaseXXX(...) functions, they can accept NULL pointer. - -#ifdef __cplusplus -// For any compiler with C++11 support, MSVC 2015 and greater, or Clang version supporting noexcept. -// Such complex condition is needed because compilers set __cplusplus value differently. -#ifndef __has_feature -#define __has_feature(x) 0 -#endif -#if ((__cplusplus >= 201103L) || (_MSC_VER >= 1900) || (defined(__has_feature) && __has_feature(cxx_noexcept))) -#define NO_EXCEPTION noexcept -#else -#define NO_EXCEPTION throw() -#endif -#else -#define NO_EXCEPTION -#endif - -// __VA_ARGS__ on Windows and Linux are different -#define ORT_API(RETURN_TYPE, NAME, ...) RETURN_TYPE ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION - -#define ORT_API_STATUS(NAME, ...) \ - _Success_(return == 0) _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) \ - NO_EXCEPTION ORT_MUST_USE_RESULT - -// XXX: Unfortunately, SAL annotations are known to not work with function pointers -#define ORT_API2_STATUS(NAME, ...) \ - _Check_return_ _Ret_maybenull_ OrtStatusPtr(ORT_API_CALL* NAME)(__VA_ARGS__) NO_EXCEPTION ORT_MUST_USE_RESULT - -// Used in *.cc files. Almost as same as ORT_API_STATUS, except without ORT_MUST_USE_RESULT and ORT_EXPORT -#define ORT_API_STATUS_IMPL(NAME, ...) \ - _Success_(return == 0) _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION - -#define ORT_CLASS_RELEASE(X) void(ORT_API_CALL * Release##X)(_Frees_ptr_opt_ Ort##X * input) - -#ifdef __DOXYGEN__ -#undef ORT_API_STATUS -#define ORT_API_STATUS(NAME, ...) OrtStatus* NAME(__VA_ARGS__) -#undef ORT_API2_STATUS -#define ORT_API2_STATUS(NAME, ...) OrtStatus* NAME(__VA_ARGS__) -#undef ORT_CLASS_RELEASE -#define ORT_CLASS_RELEASE(X) void Release##X(Ort##X* input) -#undef NO_EXCEPTION -#define NO_EXCEPTION -#endif -/** \addtogroup Global - * ONNX Runtime C API - * @{ - */ - -/** Copied from TensorProto::DataType - * Currently, Ort doesn't support complex64, complex128 - */ -typedef enum ONNXTensorElementDataType { - ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED, - ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, // maps to c type float - ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8, // maps to c type uint8_t - ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8, // maps to c type int8_t - ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16, // maps to c type uint16_t - ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16, // maps to c type int16_t - ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32, // maps to c type int32_t - ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64, // maps to c type int64_t - ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING, // maps to c++ type std::string - ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL, - ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16, - ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE, // maps to c type double - ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32, // maps to c type uint32_t - ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64, // maps to c type uint64_t - ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64, // complex with float32 real and imaginary components - ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128, // complex with float64 real and imaginary components - ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16 // Non-IEEE floating-point format based on IEEE754 single-precision -} ONNXTensorElementDataType; - -// Synced with onnx TypeProto oneof -typedef enum ONNXType { - ONNX_TYPE_UNKNOWN, - ONNX_TYPE_TENSOR, - ONNX_TYPE_SEQUENCE, - ONNX_TYPE_MAP, - ONNX_TYPE_OPAQUE, - ONNX_TYPE_SPARSETENSOR, - ONNX_TYPE_OPTIONAL -} ONNXType; - -// These types are synced with internal -// SparseFormatFlags -typedef enum OrtSparseFormat { - ORT_SPARSE_UNDEFINED = 0, - ORT_SPARSE_COO = 0x1, - ORT_SPARSE_CSRC = 0x2, - ORT_SPARSE_BLOCK_SPARSE = 0x4 -} OrtSparseFormat; - -// Enum allows to query sparse tensor indices -enum OrtSparseIndicesFormat { - ORT_SPARSE_COO_INDICES, - ORT_SPARSE_CSR_INNER_INDICES, - ORT_SPARSE_CSR_OUTER_INDICES, - ORT_SPARSE_BLOCK_SPARSE_INDICES -}; - -/** \brief Logging severity levels - * - * In typical API usage, specifying a logging severity level specifies the minimum severity of log messages to show. - */ -typedef enum OrtLoggingLevel { - ORT_LOGGING_LEVEL_VERBOSE, ///< Verbose informational messages (least severe). - ORT_LOGGING_LEVEL_INFO, ///< Informational messages. - ORT_LOGGING_LEVEL_WARNING, ///< Warning messages. - ORT_LOGGING_LEVEL_ERROR, ///< Error messages. - ORT_LOGGING_LEVEL_FATAL, ///< Fatal error messages (most severe). -} OrtLoggingLevel; - -typedef enum OrtErrorCode { - ORT_OK, - ORT_FAIL, - ORT_INVALID_ARGUMENT, - ORT_NO_SUCHFILE, - ORT_NO_MODEL, - ORT_ENGINE_ERROR, - ORT_RUNTIME_EXCEPTION, - ORT_INVALID_PROTOBUF, - ORT_MODEL_LOADED, - ORT_NOT_IMPLEMENTED, - ORT_INVALID_GRAPH, - ORT_EP_FAIL, -} OrtErrorCode; - -typedef enum OrtOpAttrType { - ORT_OP_ATTR_UNDEFINED = 0, - ORT_OP_ATTR_INT, - ORT_OP_ATTR_INTS, - ORT_OP_ATTR_FLOAT, - ORT_OP_ATTR_FLOATS, - ORT_OP_ATTR_STRING, - ORT_OP_ATTR_STRINGS, -} OrtOpAttrType; - -//! @} -#define ORT_RUNTIME_CLASS(X) \ - struct Ort##X; \ - typedef struct Ort##X Ort##X; - -/** \addtogroup Global - * ONNX Runtime C API - * @{ - */ -// The actual types defined have an Ort prefix -ORT_RUNTIME_CLASS(Env); -ORT_RUNTIME_CLASS(Status); // nullptr for Status* indicates success -ORT_RUNTIME_CLASS(MemoryInfo); -ORT_RUNTIME_CLASS(IoBinding); -ORT_RUNTIME_CLASS(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool) -ORT_RUNTIME_CLASS(Value); -ORT_RUNTIME_CLASS(RunOptions); -ORT_RUNTIME_CLASS(TypeInfo); -ORT_RUNTIME_CLASS(TensorTypeAndShapeInfo); -ORT_RUNTIME_CLASS(SessionOptions); -ORT_RUNTIME_CLASS(CustomOpDomain); -ORT_RUNTIME_CLASS(MapTypeInfo); -ORT_RUNTIME_CLASS(SequenceTypeInfo); -ORT_RUNTIME_CLASS(ModelMetadata); -ORT_RUNTIME_CLASS(ThreadPoolParams); -ORT_RUNTIME_CLASS(ThreadingOptions); -ORT_RUNTIME_CLASS(ArenaCfg); -ORT_RUNTIME_CLASS(PrepackedWeightsContainer); -ORT_RUNTIME_CLASS(TensorRTProviderOptionsV2); -ORT_RUNTIME_CLASS(CUDAProviderOptionsV2); -ORT_RUNTIME_CLASS(CANNProviderOptions); -ORT_RUNTIME_CLASS(Op); -ORT_RUNTIME_CLASS(OpAttr); - -#ifdef _WIN32 -typedef _Return_type_success_(return == 0) OrtStatus* OrtStatusPtr; -#else -typedef OrtStatus* OrtStatusPtr; -#endif - -/** \brief Memory allocation interface - * - * Structure of function pointers that defines a memory allocator. This can be created and filled in by the user for custom allocators. - * - * When an allocator is passed to any function, be sure that the allocator object is not destroyed until the last allocated object using it is freed. - */ -typedef struct OrtAllocator { - uint32_t version; ///< Must be initialized to ORT_API_VERSION - void*(ORT_API_CALL* Alloc)(struct OrtAllocator* this_, size_t size); ///< Returns a pointer to an allocated block of `size` bytes - void(ORT_API_CALL* Free)(struct OrtAllocator* this_, void* p); ///< Free a block of memory previously allocated with OrtAllocator::Alloc - const struct OrtMemoryInfo*(ORT_API_CALL* Info)(const struct OrtAllocator* this_); ///< Return a pointer to an ::OrtMemoryInfo that describes this allocator -} OrtAllocator; - -typedef void(ORT_API_CALL* OrtLoggingFunction)( - void* param, OrtLoggingLevel severity, const char* category, const char* logid, const char* code_location, - const char* message); - -/** \brief Graph optimization level - * - * Refer to https://www.onnxruntime.ai/docs/resources/graph-optimizations.html - * for an in-depth understanding of Graph Optimizations - */ -typedef enum GraphOptimizationLevel { - ORT_DISABLE_ALL = 0, - ORT_ENABLE_BASIC = 1, - ORT_ENABLE_EXTENDED = 2, - ORT_ENABLE_ALL = 99 -} GraphOptimizationLevel; - -typedef enum ExecutionMode { - ORT_SEQUENTIAL = 0, - ORT_PARALLEL = 1, -} ExecutionMode; - -/** \brief Language projection identifiers - * /see OrtApi::SetLanguageProjection - */ -typedef enum OrtLanguageProjection { - ORT_PROJECTION_C = 0, - ORT_PROJECTION_CPLUSPLUS = 1, - ORT_PROJECTION_CSHARP = 2, - ORT_PROJECTION_PYTHON = 3, - ORT_PROJECTION_JAVA = 4, - ORT_PROJECTION_WINML = 5, - ORT_PROJECTION_NODEJS = 6, -} OrtLanguageProjection; - -struct OrtKernelInfo; -typedef struct OrtKernelInfo OrtKernelInfo; -struct OrtKernelContext; -typedef struct OrtKernelContext OrtKernelContext; -struct OrtCustomOp; -typedef struct OrtCustomOp OrtCustomOp; - -typedef enum OrtAllocatorType { - OrtInvalidAllocator = -1, - OrtDeviceAllocator = 0, - OrtArenaAllocator = 1 -} OrtAllocatorType; - -/** \brief Memory types for allocated memory, execution provider specific types should be extended in each provider. - */ -// Whenever this struct is updated, please also update the MakeKey function in onnxruntime / core / framework / execution_provider.cc -typedef enum OrtMemType { - OrtMemTypeCPUInput = -2, ///< Any CPU memory used by non-CPU execution provider - OrtMemTypeCPUOutput = -1, ///< CPU accessible memory outputted by non-CPU execution provider, i.e. CUDA_PINNED - OrtMemTypeCPU = OrtMemTypeCPUOutput, ///< Temporary CPU accessible memory allocated by non-CPU execution provider, i.e. CUDA_PINNED - OrtMemTypeDefault = 0, ///< The default allocator for execution provider -} OrtMemType; - -/** \brief This mimics OrtDevice type constants so they can be returned in the API - */ -typedef enum OrtMemoryInfoDeviceType { - OrtMemoryInfoDeviceType_CPU = 0, - OrtMemoryInfoDeviceType_GPU = 1, - OrtMemoryInfoDeviceType_FPGA = 2 -} OrtMemoryInfoDeviceType; - -/** \brief Algorithm to use for cuDNN Convolution Op - */ -typedef enum OrtCudnnConvAlgoSearch { - OrtCudnnConvAlgoSearchExhaustive, // expensive exhaustive benchmarking using cudnnFindConvolutionForwardAlgorithmEx - OrtCudnnConvAlgoSearchHeuristic, // lightweight heuristic based search using cudnnGetConvolutionForwardAlgorithm_v7 - OrtCudnnConvAlgoSearchDefault, // default algorithm using CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM -} OrtCudnnConvAlgoSearch; - -/** \brief CUDA Provider Options - * - * \see OrtApi::SessionOptionsAppendExecutionProvider_CUDA - */ -typedef struct OrtCUDAProviderOptions { -#ifdef __cplusplus - OrtCUDAProviderOptions() - : device_id{}, - cudnn_conv_algo_search{OrtCudnnConvAlgoSearchExhaustive}, - gpu_mem_limit{SIZE_MAX}, - arena_extend_strategy{}, - do_copy_in_default_stream{1}, - has_user_compute_stream{}, - user_compute_stream{}, - default_memory_arena_cfg{}, - tunable_op_enabled{false} {} -#endif - - /** \brief CUDA device Id - * Defaults to 0. - */ - int device_id; - - /** \brief CUDA Convolution algorithm search configuration. - * See enum OrtCudnnConvAlgoSearch for more details. - * Defaults to OrtCudnnConvAlgoSearchExhaustive. - */ - OrtCudnnConvAlgoSearch cudnn_conv_algo_search; - - /** \brief CUDA memory limit (To use all possible memory pass in maximum size_t) - * Defaults to SIZE_MAX. - * \note If a ::OrtArenaCfg has been applied, it will override this field - */ - size_t gpu_mem_limit; - - /** \brief Strategy used to grow the memory arena - * 0 = kNextPowerOfTwo
- * 1 = kSameAsRequested
- * Defaults to 0. - * \note If a ::OrtArenaCfg has been applied, it will override this field - */ - int arena_extend_strategy; - - /** \brief Flag indicating if copying needs to take place on the same stream as the compute stream in the CUDA EP - * 0 = Use separate streams for copying and compute. - * 1 = Use the same stream for copying and compute. - * Defaults to 1. - * WARNING: Setting this to 0 may result in data races for some models. - * Please see issue #4829 for more details. - */ - int do_copy_in_default_stream; - - /** \brief Flag indicating if there is a user provided compute stream - * Defaults to 0. - */ - int has_user_compute_stream; - - /** \brief User provided compute stream. - * If provided, please set `has_user_compute_stream` to 1. - */ - void* user_compute_stream; - - /** \brief CUDA memory arena configuration parameters - */ - OrtArenaCfg* default_memory_arena_cfg; - - /** \brief Enable TunableOp. - * Set it to 1 to enable TunableOp. Otherwise, it is disabled by default. - * This option can be superseded by environment variable ORT_CUDA_TUNABLE_OP_ENABLED. - */ - int tunable_op_enabled; - -} OrtCUDAProviderOptions; - -/** \brief ROCM Provider Options - * - * \see OrtApi::SessionOptionsAppendExecutionProvider_ROCM - */ -typedef struct OrtROCMProviderOptions { -#ifdef __cplusplus - OrtROCMProviderOptions() - : device_id{}, - miopen_conv_exhaustive_search{0}, - gpu_mem_limit{SIZE_MAX}, - arena_extend_strategy{}, - do_copy_in_default_stream{1}, - has_user_compute_stream{}, - user_compute_stream{}, - default_memory_arena_cfg{}, - tunable_op_enabled{false} {} -#endif - - /** \brief ROCM device Id - * Defaults to 0. - */ - int device_id; - - /** \brief ROCM MIOpen Convolution algorithm exaustive search option. - * Defaults to 0 (false). - */ - int miopen_conv_exhaustive_search; - - /** \brief ROCM memory limit (To use all possible memory pass in maximum size_t) - * Defaults to SIZE_MAX. - * \note If a ::OrtArenaCfg has been applied, it will override this field - */ - size_t gpu_mem_limit; - - /** \brief Strategy used to grow the memory arena - * 0 = kNextPowerOfTwo
- * 1 = kSameAsRequested
- * Defaults to 0. - * \note If a ::OrtArenaCfg has been applied, it will override this field - */ - int arena_extend_strategy; - - /** \brief Flag indicating if copying needs to take place on the same stream as the compute stream in the ROCM EP - * 0 = Use separate streams for copying and compute. - * 1 = Use the same stream for copying and compute. - * Defaults to 1. - * WARNING: Setting this to 0 may result in data races for some models. - * Please see issue #4829 for more details. - */ - int do_copy_in_default_stream; - - /** \brief Flag indicating if there is a user provided compute stream - * Defaults to 0. - */ - int has_user_compute_stream; - - /** \brief User provided compute stream. - * If provided, please set `has_user_compute_stream` to 1. - */ - void* user_compute_stream; - - /** \brief ROCM memory arena configuration parameters - */ - OrtArenaCfg* default_memory_arena_cfg; - - /** \brief Enable TunableOp. - * Set it to 1 to enable TunableOp. Otherwise, it is disabled by default. - * This option can be superseded by environment variable ORT_ROCM_TUNABLE_OP_ENABLED. - */ - int tunable_op_enabled; - -} OrtROCMProviderOptions; - -/** \brief TensorRT Provider Options - * - * \see OrtApi::SessionOptionsAppendExecutionProvider_TensorRT - */ -typedef struct OrtTensorRTProviderOptions { - int device_id; ///< CUDA device id (0 = default device) - int has_user_compute_stream; // indicator of user specified CUDA compute stream. - void* user_compute_stream; // user specified CUDA compute stream. - int trt_max_partition_iterations; // maximum iterations for TensorRT parser to get capability - int trt_min_subgraph_size; // minimum size of TensorRT subgraphs - size_t trt_max_workspace_size; // maximum workspace size for TensorRT. - int trt_fp16_enable; // enable TensorRT FP16 precision. Default 0 = false, nonzero = true - int trt_int8_enable; // enable TensorRT INT8 precision. Default 0 = false, nonzero = true - const char* trt_int8_calibration_table_name; // TensorRT INT8 calibration table name. - int trt_int8_use_native_calibration_table; // use native TensorRT generated calibration table. Default 0 = false, nonzero = true - int trt_dla_enable; // enable DLA. Default 0 = false, nonzero = true - int trt_dla_core; // DLA core number. Default 0 - int trt_dump_subgraphs; // dump TRT subgraph. Default 0 = false, nonzero = true - int trt_engine_cache_enable; // enable engine caching. Default 0 = false, nonzero = true - const char* trt_engine_cache_path; // specify engine cache path - int trt_engine_decryption_enable; // enable engine decryption. Default 0 = false, nonzero = true - const char* trt_engine_decryption_lib_path; // specify engine decryption library path - int trt_force_sequential_engine_build; // force building TensorRT engine sequentially. Default 0 = false, nonzero = true - // This is the legacy struct and don't add new fields here. - // For new field that can be represented by string, please add it in include/onnxruntime/core/providers/tensorrt/tensorrt_provider_options.h - // For non-string field, need to create a new separate api to handle it. -} OrtTensorRTProviderOptions; - -/** \brief MIGraphX Provider Options - * - * \see OrtApi::SessionOptionsAppendExecutionProvider_MIGraphX - */ -typedef struct OrtMIGraphXProviderOptions { - int device_id; // hip device id. - int migraphx_fp16_enable; // enable MIGraphX FP16 precision. Default 0 = false, nonzero = true - int migraphx_int8_enable; // enable MIGraphX INT8 precision. Default 0 = false, nonzero = true -} OrtMIGraphXProviderOptions; - -/** \brief OpenVINO Provider Options - * - * \see OrtApi::SessionOptionsAppendExecutionProvider_OpenVINO - */ -typedef struct OrtOpenVINOProviderOptions { -#ifdef __cplusplus - OrtOpenVINOProviderOptions() : device_type{}, enable_vpu_fast_compile{}, device_id{}, - num_of_threads{}, cache_dir{}, - context{}, enable_opencl_throttling{}, enable_dynamic_shapes{} {} -#endif - /** \brief Device type string - * - * Valid settings are one of: "CPU_FP32", "CPU_FP16", "GPU_FP32", "GPU_FP16", "MYRIAD_FP16", "VAD-M_FP16" or "VAD-F_FP32" - */ - const char* device_type; - unsigned char enable_vpu_fast_compile; ///< 0 = disabled, nonzero = enabled - const char* device_id; - size_t num_of_threads; ///< 0 = Use default number of threads - const char* cache_dir; // path is set to empty by default - void* context; - unsigned char enable_opencl_throttling; ///< 0 = disabled, nonzero = enabled - unsigned char enable_dynamic_shapes; ///< 0 = disabled, nonzero = enabled -} OrtOpenVINOProviderOptions; - -struct OrtApi; -typedef struct OrtApi OrtApi; - -struct OrtTrainingApi; -typedef struct OrtTrainingApi OrtTrainingApi; - -/** \brief The helper interface to get the right version of OrtApi - * - * Get a pointer to this structure through ::OrtGetApiBase - */ -struct OrtApiBase { - /** \brief Get a pointer to the requested version of the ::OrtApi - * - * \param[in] version Must be ::ORT_API_VERSION - * \return The ::OrtApi for the version requested, nullptr will be returned if this version is unsupported, for example when using a runtime - * older than the version created with this header file. - */ - const OrtApi*(ORT_API_CALL* GetApi)(uint32_t version)NO_EXCEPTION; - const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION; ///< Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1") -}; -typedef struct OrtApiBase OrtApiBase; - -/** \brief The Onnxruntime library's entry point to access the C API - * - * Call this to get the a pointer to an ::OrtApiBase - */ -ORT_EXPORT const OrtApiBase* ORT_API_CALL OrtGetApiBase(void) NO_EXCEPTION; - -/** \brief Thread work loop function - * - * Onnxruntime will provide the working loop on custom thread creation - * Argument is an onnxruntime built-in type which will be provided when thread pool calls OrtCustomCreateThreadFn - */ -typedef void (*OrtThreadWorkerFn)(void* ort_worker_fn_param); - -typedef const struct OrtCustomHandleType { - char __place_holder; -}* OrtCustomThreadHandle; - -/** \brief Ort custom thread creation function - * - * The function should return a thread handle to be used in onnxruntime thread pools - * Onnxruntime will throw exception on return value of nullptr or 0, indicating that the function failed to create a thread - */ -typedef OrtCustomThreadHandle (*OrtCustomCreateThreadFn)(void* ort_custom_thread_creation_options, OrtThreadWorkerFn ort_thread_worker_fn, void* ort_worker_fn_param); - -/** \brief Custom thread join function - * - * Onnxruntime thread pool destructor will call the function to join a custom thread. - * Argument ort_custom_thread_handle is the value returned by OrtCustomCreateThreadFn - */ -typedef void (*OrtCustomJoinThreadFn)(OrtCustomThreadHandle ort_custom_thread_handle); - -typedef OrtStatus*(ORT_API_CALL* RegisterCustomOpsFn)(OrtSessionOptions* options, const OrtApiBase* api); - -/** \brief The C API - * - * All C API functions are defined inside this structure as pointers to functions. - * Call OrtApiBase::GetApi to get a pointer to it - * - * \nosubgrouping - */ -struct OrtApi { - /// \name OrtStatus - /// @{ - - /** - * \brief Create an OrtStatus from a null terminated string - * - * \param[in] code - * \param[in] msg A null-terminated string. Its contents will be copied. - * \return A new OrtStatus object, must be destroyed with OrtApi::ReleaseStatus - */ - OrtStatus*(ORT_API_CALL* CreateStatus)(OrtErrorCode code, _In_ const char* msg)NO_EXCEPTION ORT_ALL_ARGS_NONNULL; - - /** \brief Get OrtErrorCode from OrtStatus - * - * \param[in] status - * \return OrtErrorCode that \p status was created with - */ - OrtErrorCode(ORT_API_CALL* GetErrorCode)(_In_ const OrtStatus* status) NO_EXCEPTION ORT_ALL_ARGS_NONNULL; - - /** \brief Get error string from OrtStatus - * - * \param[in] status - * \return The error message inside the `status`. Do not free the returned value. - */ - const char*(ORT_API_CALL* GetErrorMessage)(_In_ const OrtStatus* status)NO_EXCEPTION ORT_ALL_ARGS_NONNULL; - - /// @} - /// \name OrtEnv - /// @{ - - /** \brief Create an OrtEnv - * - * \param[in] log_severity_level The log severity level. - * \param[in] logid The log identifier. - * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateEnv, OrtLoggingLevel log_severity_level, _In_ const char* logid, _Outptr_ OrtEnv** out); - - /** \brief Create an OrtEnv - * - * \param[in] logging_function A pointer to a logging function. - * \param[in] logger_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to - * `logging_function`. - * \param[in] log_severity_level The log severity level. - * \param[in] logid The log identifier. - * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateEnvWithCustomLogger, OrtLoggingFunction logging_function, _In_opt_ void* logger_param, - OrtLoggingLevel log_severity_level, _In_ const char* logid, _Outptr_ OrtEnv** out); - - /** \brief Enable Telemetry - * - * \note Telemetry events are on by default since they are lightweight - * \param[in] env - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(EnableTelemetryEvents, _In_ const OrtEnv* env); - /** \brief Disable Telemetry - * - * \see OrtApi::EnableTelemetryEvents - * \param[in] env - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(DisableTelemetryEvents, _In_ const OrtEnv* env); - - /// @} - /// \name OrtSession - /// @{ - - /** \brief Create an OrtSession from a model file - * - * \param[in] env - * \param[in] model_path - * \param[in] options - * \param[out] out Returned newly created OrtSession. Must be freed with OrtApi::ReleaseSession - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - // TODO: document the path separator convention? '/' vs '\' - // TODO: should specify the access characteristics of model_path. Is this read only during the - // execution of CreateSession, or does the OrtSession retain a handle to the file/directory - // and continue to access throughout the OrtSession lifetime? - // What sort of access is needed to model_path : read or read/write? - ORT_API2_STATUS(CreateSession, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path, - _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out); - - /** \brief Create an OrtSession from memory - * - * \param[in] env - * \param[in] model_data - * \param[in] model_data_length - * \param[in] options - * \param[out] out Returned newly created OrtSession. Must be freed with OrtApi::ReleaseSession - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateSessionFromArray, _In_ const OrtEnv* env, _In_ const void* model_data, size_t model_data_length, - _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out); - - /** \brief Run the model in an ::OrtSession - * - * Will not return until the model run has completed. Multiple threads might be used to run the model based on - * the options in the ::OrtSession and settings used when creating the ::OrtEnv - * - * \param[in] session - * \param[in] run_options If nullptr, will use a default ::OrtRunOptions - * \param[in] input_names Array of null terminated UTF8 encoded strings of the input names - * \param[in] inputs Array of ::OrtValue%s of the input values - * \param[in] input_len Number of elements in the input_names and inputs arrays - * \param[in] output_names Array of null terminated UTF8 encoded strings of the output names - * \param[in] output_names_len Number of elements in the output_names and outputs array - * \param[out] outputs Array of ::OrtValue%s that the outputs are stored in. This can also be - * an array of nullptr values, in this case ::OrtValue objects will be allocated and pointers - * to them will be set into the `outputs` array. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(Run, _Inout_ OrtSession* session, _In_opt_ const OrtRunOptions* run_options, - _In_reads_(input_len) const char* const* input_names, - _In_reads_(input_len) const OrtValue* const* inputs, size_t input_len, - _In_reads_(output_names_len) const char* const* output_names, size_t output_names_len, - _Inout_updates_all_(output_names_len) OrtValue** outputs); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Create an ::OrtSessionOptions object - * - * To use additional providers, you must build ORT with the extra providers enabled. Then call one of these - * functions to enable them in the session:
- * OrtSessionOptionsAppendExecutionProvider_CPU
- * OrtSessionOptionsAppendExecutionProvider_CUDA
- * OrtSessionOptionsAppendExecutionProvider_(remaining providers...)
- * The order they are called indicates the preference order as well. In other words call this method - * on your most preferred execution provider first followed by the less preferred ones. - * If none are called Ort will use its internal CPU execution provider. - * - * \param[out] options The newly created OrtSessionOptions. Must be freed with OrtApi::ReleaseSessionOptions - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateSessionOptions, _Outptr_ OrtSessionOptions** options); - - /** \brief Set filepath to save optimized model after graph level transformations - * - * \param[in] options - * \param[in] optimized_model_filepath - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetOptimizedModelFilePath, _Inout_ OrtSessionOptions* options, - _In_ const ORTCHAR_T* optimized_model_filepath); - - /** \brief Create a copy of an existing ::OrtSessionOptions - * - * \param[in] in_options OrtSessionOptions to copy - * \param[out] out_options Returned newly created ::OrtSessionOptions. Must be freed with OrtApi::ReleaseSessionOptions - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CloneSessionOptions, _In_ const OrtSessionOptions* in_options, - _Outptr_ OrtSessionOptions** out_options); - - /** \brief Set execution mode - * - * Controls whether you want to execute operators in your graph sequentially or in parallel. Usually when the model - * has many branches, setting this option to ExecutionMode.ORT_PARALLEL will give you better performance. - * See [docs/ONNX_Runtime_Perf_Tuning.md] for more details. - * - * \param[in] options - * \param[in] execution_mode - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetSessionExecutionMode, _Inout_ OrtSessionOptions* options, ExecutionMode execution_mode); - - /** \brief Enable profiling for a session - * - * \param[in] options - * \param[in] profile_file_prefix - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(EnableProfiling, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* profile_file_prefix); - - /** \brief Disable profiling for a session - * - * \param[in] options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(DisableProfiling, _Inout_ OrtSessionOptions* options); - - /** \brief Enable the memory pattern optimization - * - * The idea is if the input shapes are the same, we could trace the internal memory allocation - * and generate a memory pattern for future request. So next time we could just do one allocation - * with a big chunk for all the internal memory allocation. - * \note Memory pattern optimization is only available when Sequential Execution mode is enabled (see OrtApi::SetSessionExecutionMode) - * - * \see OrtApi::DisableMemPattern - * - * \param[in] options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(EnableMemPattern, _Inout_ OrtSessionOptions* options); - - /** \brief Disable the memory pattern optimization - * - * \see OrtApi::EnableMemPattern - * - * \param[in] options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(DisableMemPattern, _Inout_ OrtSessionOptions* options); - - /** \brief Enable the memory arena on CPU - * - * Arena may pre-allocate memory for future usage. - * - * \param[in] options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(EnableCpuMemArena, _Inout_ OrtSessionOptions* options); - - /** \brief Disable the memory arena on CPU - * - * \param[in] options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(DisableCpuMemArena, _Inout_ OrtSessionOptions* options); - - /** \brief Set session log id - * - * \param[in] options - * \param[in] logid The log identifier. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetSessionLogId, _Inout_ OrtSessionOptions* options, const char* logid); - - /** \brief Set session log verbosity level - * - * Applies to session load, initialization, etc - * - * \param[in] options - * \param[in] session_log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetSessionLogVerbosityLevel, _Inout_ OrtSessionOptions* options, int session_log_verbosity_level); - - /** \brief Set session log severity level - * - * \param[in] options - * \param[in] session_log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values). - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetSessionLogSeverityLevel, _Inout_ OrtSessionOptions* options, int session_log_severity_level); - - /** \brief Set the optimization level to apply when loading a graph - * - * Please see https://www.onnxruntime.ai/docs/resources/graph-optimizations.html for an in-depth explanation - * \param[in,out] options The session options object - * \param[in] graph_optimization_level The optimization level - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetSessionGraphOptimizationLevel, _Inout_ OrtSessionOptions* options, - GraphOptimizationLevel graph_optimization_level); - - /** \brief Sets the number of threads used to parallelize the execution within nodes - * - * When running a single node operation, ex. add, this sets the maximum number of threads to use. - * - * \note If built with OpenMP, this has no effect on the number of threads used. In this case - * use the OpenMP env variables to configure the number of intra op num threads. - * - * \param[in] options - * \param[in] intra_op_num_threads Number of threads to use
- * A value of 0 will use the default number of threads
- * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetIntraOpNumThreads, _Inout_ OrtSessionOptions* options, int intra_op_num_threads); - - /** \brief Sets the number of threads used to parallelize the execution of the graph - * - * If nodes can be run in parallel, this sets the maximum number of threads to use to run them in parallel. - * - * \note If sequential execution is enabled this value is ignored, it acts as if it was set to 1. - * - * \param[in] options - * \param[in] inter_op_num_threads Number of threads to use
- * A value of 0 will use the default number of threads
- * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetInterOpNumThreads, _Inout_ OrtSessionOptions* options, int inter_op_num_threads); - - /// @} - /// \name OrtCustomOpDomain - /// @{ - - /** \brief Create a custom op domain - * - * \param[in] domain - * \param[out] out Newly created domain. Must be freed with OrtApi::ReleaseCustomOpDomain - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateCustomOpDomain, _In_ const char* domain, _Outptr_ OrtCustomOpDomain** out); - - /** \brief Add a custom op to a custom op domain - * - * \note The OrtCustomOp* pointer must remain valid until the ::OrtCustomOpDomain using it is released - * - * \param[in] custom_op_domain - * \param[in] op - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CustomOpDomain_Add, _Inout_ OrtCustomOpDomain* custom_op_domain, _In_ const OrtCustomOp* op); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Add custom op domain to a session options - * - * \note The OrtCustomOpDomain* must not be deleted until all sessions using it are released - * - * \param[in] options - * \param[in] custom_op_domain - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(AddCustomOpDomain, _Inout_ OrtSessionOptions* options, _In_ OrtCustomOpDomain* custom_op_domain); - - /** \deprecated Use OrtApi::RegisterCustomOpsLibrary_V2. - * - * Registers custom ops from a shared library. - * - * Loads a shared library (dll on windows, so on linux, etc) named 'library_path' and looks for this entry point: - * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api); - * It then passes in the provided session options to this function along with the api base. - * The handle to the loaded library is returned in library_handle. It can be freed by the caller after all sessions using the passed in - * session options are destroyed, or if an error occurs and it is non null. - * - * \param[in] options - * \param[in] library_path - * \param[out] library_handle OS specific handle to the loaded library (Use FreeLibrary on Windows, dlclose on Linux, etc.. to unload) - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(RegisterCustomOpsLibrary, _Inout_ OrtSessionOptions* options, _In_ const char* library_path, _Outptr_ void** library_handle); - - /// @} - /// \name OrtSession - /// @{ - - /** \brief Get input count for a session - * - * This number must also match the number of inputs passed to OrtApi::Run - * - * \see OrtApi::SessionGetInputTypeInfo, OrtApi::SessionGetInputName, OrtApi::Session - * - * \param[in] session - * \param[out] out Number of inputs - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetInputCount, _In_ const OrtSession* session, _Out_ size_t* out); - - /** \brief Get output count for a session - * - * This number must also match the number of outputs returned by OrtApi::Run - * - * \see OrtApi::SessionGetOutputTypeInfo, OrtApi::SessionGetOutputName, OrtApi::Session - * - * \param[in] session - * \param[out] out Number of outputs - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetOutputCount, _In_ const OrtSession* session, _Out_ size_t* out); - - /** \brief Get overridable initializer count - * - * \see OrtApi::SessionGetOverridableInitializerTypeInfo, OrtApi::SessionGetOverridableInitializerName - * - * \param[in] session - * \param[in] out - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetOverridableInitializerCount, _In_ const OrtSession* session, _Out_ size_t* out); - - /** \brief Get input type information - * - * \param[in] session - * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetInputCount returns (exclusive) - * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetInputTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info); - - /** \brief Get output type information - * - * \param[in] session - * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOutputCount returns (exclusive) - * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetOutputTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info); - - /** \brief Get overridable initializer type information - * - * \param[in] session - * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOverridableInitializerCount returns (exclusive) - * \param[out] type_info Must be freed with OrtApi::ReleaseTypeInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetOverridableInitializerTypeInfo, _In_ const OrtSession* session, size_t index, _Outptr_ OrtTypeInfo** type_info); - - /** \brief Get input name - * - * \param[in] session - * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetInputCount returns (exclusive) - * \param[in] allocator - * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetInputName, _In_ const OrtSession* session, size_t index, _Inout_ OrtAllocator* allocator, _Outptr_ char** value); - - /** \brief Get output name - * - * \param[in] session - * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOutputCount returns (exclusive) - * \param[in] allocator - * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetOutputName, _In_ const OrtSession* session, size_t index, _Inout_ OrtAllocator* allocator, _Outptr_ char** value); - - /** \brief Get overridable initializer name - * - * \param[in] session - * \param[in] index Must be between 0 (inclusive) and what OrtApi::SessionGetOverridableInitializerCount returns (exclusive) - * \param[in] allocator - * \param[out] value Set to a null terminated UTF-8 encoded string allocated using `allocator`. Must be freed using `allocator`. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetOverridableInitializerName, _In_ const OrtSession* session, size_t index, - _Inout_ OrtAllocator* allocator, _Outptr_ char** value); - - /// @} - /// \name OrtRunOptions - /// @{ - - /** \brief Create an OrtRunOptions - * - * \param[out] out Returned newly created ::OrtRunOptions. Must be freed with OrtApi::ReleaseRunOptions - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateRunOptions, _Outptr_ OrtRunOptions** out); - - /** \brief Set per-run log verbosity level - * - * \see OrtApi::RunOptionsGetRunLogVerbosityLevel - * - * \param[in] options - * \param[in] log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(RunOptionsSetRunLogVerbosityLevel, _Inout_ OrtRunOptions* options, int log_verbosity_level); - - /** \brief Set per-run log severity level - * - * \see OrtApi::RunOptionsGetRunLogSeverityLevel - * - * \param[in] options - * \param[in] log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values). - */ - ORT_API2_STATUS(RunOptionsSetRunLogSeverityLevel, _Inout_ OrtRunOptions* options, int log_severity_level); - - /** \brief Set per-run tag - * - * This is used in a per-run log identifier. - * - * \see OrtApi::RunOptionsGetRunTag - * - * \param[in] options - * \param[in] run_tag The run tag. - */ - ORT_API2_STATUS(RunOptionsSetRunTag, _Inout_ OrtRunOptions* options, _In_ const char* run_tag); - - /** \brief Get per-run log verbosity level - * - * \see OrtApi::RunOptionsSetRunLogVerbosityLevel - * - * \param[in] options - * \param[out] log_verbosity_level \snippet{doc} snippets.dox Log Verbosity Level - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(RunOptionsGetRunLogVerbosityLevel, _In_ const OrtRunOptions* options, - _Out_ int* log_verbosity_level); - - /** \brief Get per-run log severity level - * - * \see OrtApi::RunOptionsSetRunLogSeverityLevel - * - * \param[in] options - * \param[out] log_severity_level The log severity level (refer to ::OrtLoggingLevel for possible values). - */ - ORT_API2_STATUS(RunOptionsGetRunLogSeverityLevel, _In_ const OrtRunOptions* options, _Out_ int* log_severity_level); - - /** \brief Get per-run tag - * - * This is used in a per-run log identifier. - * - * \see OrtApi::RunOptionsSetRunTag - * - * \param[in] options - * \param[out] run_tag The run tag. - * Do not free this value, it is owned by `options`. It will be invalidated if the run tag - * changes (i.e., with OrtApi::RunOptionsSetRunTag) or `options` is freed. - */ - ORT_API2_STATUS(RunOptionsGetRunTag, _In_ const OrtRunOptions* options, _Out_ const char** run_tag); - - /** \brief Set terminate flag - * - * If a currently executing session needs to be force terminated, this can be called from another thread to force it to fail with an error. - * - * \param[in] options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(RunOptionsSetTerminate, _Inout_ OrtRunOptions* options); - - /** \brief Clears the terminate flag - * - * Used so the OrtRunOptions instance can be used in a new OrtApi::Run call without it instantly terminating - * - * \param[in] options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(RunOptionsUnsetTerminate, _Inout_ OrtRunOptions* options); - - /// @} - /// \name OrtValue - /// @{ - - /** \brief Create a tensor - * - * Create a tensor using a supplied ::OrtAllocator - * - * \param[in] allocator - * \param[in] shape Pointer to the tensor shape dimensions. - * \param[in] shape_len The number of tensor shape dimensions. - * \param[in] type - * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* shape, size_t shape_len, - ONNXTensorElementDataType type, _Outptr_ OrtValue** out); - - /** \brief Create a tensor backed by a user supplied buffer - * - * Create a tensor with user's buffer. You can fill the buffer either before calling this function or after. - * p_data is owned by caller. ReleaseValue won't release p_data. - * - * \param[in] info Memory description of where the p_data buffer resides (CPU vs GPU etc). - * \param[in] p_data Pointer to the data buffer. - * \param[in] p_data_len The number of bytes in the data buffer. - * \param[in] shape Pointer to the tensor shape dimensions. - * \param[in] shape_len The number of tensor shape dimensions. - * \param[in] type The data type. - * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateTensorWithDataAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data, - size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type, - _Outptr_ OrtValue** out); - - /** \brief Return if an ::OrtValue is a tensor type - * - * \param[in] value A tensor type (string tensors are not supported) - * \param[out] out Set to 1 iff ::OrtValue is a tensor, 0 otherwise - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(IsTensor, _In_ const OrtValue* value, _Out_ int* out); - - /** \brief Get a pointer to the raw data inside a tensor - * - * Used to read/write/modify the internal tensor data directly. - * \note The returned pointer is valid until the \p value is destroyed. - * - * \param[in] value A tensor type (string tensors are not supported) - * \param[out] out Filled in with a pointer to the internal storage - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetTensorMutableData, _In_ OrtValue* value, _Outptr_ void** out); - - /** \brief Set all strings at once in a string tensor - * - * \param[in,out] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING - * \param[in] s An array of strings. Each string in this array must be null terminated. - * \param[in] s_len Count of strings in s (Must match the size of \p value's tensor shape) - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(FillStringTensor, _Inout_ OrtValue* value, _In_ const char* const* s, size_t s_len); - - /** \brief Get total byte length for all strings in a string tensor - * - * Typically used with OrtApi::GetStringTensorContent - * - * \param[in] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING - * \param[out] len Total byte length of all strings (does not include trailing nulls) - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetStringTensorDataLength, _In_ const OrtValue* value, _Out_ size_t* len); - - /** \brief Get all strings from a string tensor - * - * An example of the results:
- * Given \p value is a string tensor with the strings { "This" "is" "a" "test" }
- * \p s must have a size of 11 bytes
- * \p offsets must have 4 elements
- * After the call, these values will be filled in:
- * \p s will contain "Thisisatest"
- * \p offsets will contain { 0, 4, 6, 7 }
- * The length of the last string is just s_len - offsets[last] - * - * \param[in] value A tensor of type ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING - * \param[in] s Buffer to sequentially write all tensor strings to. Each string is NOT null-terminated. - * \param[in] s_len Number of bytes of buffer pointed to by \p s (Get it from OrtApi::GetStringTensorDataLength) - * \param[out] offsets Array of start offsets into the strings written to \p s - * \param[in] offsets_len Number of elements in offsets - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetStringTensorContent, _In_ const OrtValue* value, _Out_writes_bytes_all_(s_len) void* s, - size_t s_len, _Out_writes_all_(offsets_len) size_t* offsets, size_t offsets_len); - - /// @} - /// \name OrtTypeInfo - /// @{ - - /** \brief Get ::OrtTensorTypeAndShapeInfo from an ::OrtTypeInfo - * - * \param[in] type_info - * \param[out] out Do not free this value, it will be valid until type_info is freed. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CastTypeInfoToTensorInfo, _In_ const OrtTypeInfo* type_info, - _Outptr_result_maybenull_ const OrtTensorTypeAndShapeInfo** out); - - /** \brief Get ::ONNXType from ::OrtTypeInfo - * - * \param[in] type_info - * \param[out] out - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetOnnxTypeFromTypeInfo, _In_ const OrtTypeInfo* type_info, _Out_ enum ONNXType* out); - - /// @} - /// \name OrtTensorTypeAndShapeInfo - /// @{ - - /** \brief Create an ::OrtTensorTypeAndShapeInfo object - * - * \param[out] out Returns newly created ::OrtTensorTypeAndShapeInfo. Must be freed with OrtApi::ReleaseTensorTypeAndShapeInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateTensorTypeAndShapeInfo, _Outptr_ OrtTensorTypeAndShapeInfo** out); - - /** \brief Set element type in ::OrtTensorTypeAndShapeInfo - * - * \param[in] info - * \param[in] type - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetTensorElementType, _Inout_ OrtTensorTypeAndShapeInfo* info, enum ONNXTensorElementDataType type); - - /** \brief Set shape information in ::OrtTensorTypeAndShapeInfo - * - * \param[in] info - * \param[in] dim_values Array with `dim_count` elements. Can contain negative values. - * \param[in] dim_count Number of elements in `dim_values` - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetDimensions, OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count); - - /** \brief Get element type in ::OrtTensorTypeAndShapeInfo - * - * \see OrtApi::SetTensorElementType - * - * \param[in] info - * \param[out] out - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetTensorElementType, _In_ const OrtTensorTypeAndShapeInfo* info, - _Out_ enum ONNXTensorElementDataType* out); - - /** \brief Get dimension count in ::OrtTensorTypeAndShapeInfo - * - * \see OrtApi::GetDimensions - * - * \param[in] info - * \param[out] out - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetDimensionsCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out); - - /** \brief Get dimensions in ::OrtTensorTypeAndShapeInfo - * - * \param[in] info - * \param[out] dim_values Array with `dim_values_length` elements. On return, filled with the dimensions stored in the ::OrtTensorTypeAndShapeInfo - * \param[in] dim_values_length Number of elements in `dim_values`. Use OrtApi::GetDimensionsCount to get this value - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetDimensions, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, - size_t dim_values_length); - - /** \brief Get symbolic dimension names in ::OrtTensorTypeAndShapeInfo - * - * \param[in] info - * \param[in] dim_params Array with `dim_params_length` elements. On return filled with pointers to null terminated strings of the dimension names - * \param[in] dim_params_length Number of elements in `dim_params`. Use OrtApi::GetDimensionsCount to get this value - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetSymbolicDimensions, _In_ const OrtTensorTypeAndShapeInfo* info, - _Out_writes_all_(dim_params_length) const char* dim_params[], size_t dim_params_length); - - /** \brief Get total number of elements in a tensor shape from an ::OrtTensorTypeAndShapeInfo - * - * Return the number of elements specified by the tensor shape (all dimensions multiplied by each other). - * For 0 dimensions, 1 is returned. If any dimension is less than 0, the result is always -1. - * - * Examples:
- * [] = 1
- * [1,3,4] = 12
- * [2,0,4] = 0
- * [-1,3,4] = -1
- * - * \param[in] info - * \param[out] out Number of elements - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetTensorShapeElementCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out); - - /// @} - /// \name OrtValue - /// @{ - - /** \brief Get type and shape information from a tensor ::OrtValue - * - * \param[in] value Must be a tensor (not a map/sequence/etc) or will return failure - * \param[out] out Newly created ::OrtTensorTypeAndShapeInfo. Must be freed with OrtApi::ReleaseTensorTypeAndShapeInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetTensorTypeAndShape, _In_ const OrtValue* value, _Outptr_ OrtTensorTypeAndShapeInfo** out); - - /** \brief Get type information of an OrtValue - * - * \param[in] value - * \param[out] out Newly created ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetTypeInfo, _In_ const OrtValue* value, _Outptr_result_maybenull_ OrtTypeInfo** out); - - /** \brief Get ONNXType of an ::OrtValue - * - * \param[in] value - * \param[out] out - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetValueType, _In_ const OrtValue* value, _Out_ enum ONNXType* out); - - /// @} - /// \name OrtMemoryInfo - /// @{ - - /** \brief Create an ::OrtMemoryInfo - * - * \param[in] name - * \param[in] type - * \param[in] id - * \param[in] mem_type - * \param[out] out Newly created ::OrtMemoryInfo. Must be freed with OrtAPi::ReleaseMemoryInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateMemoryInfo, _In_ const char* name, enum OrtAllocatorType type, int id, - enum OrtMemType mem_type, _Outptr_ OrtMemoryInfo** out); - - /** \brief Create an ::OrtMemoryInfo for CPU memory - * - * Special case version of OrtApi::CreateMemoryInfo for CPU based memory. Same as using OrtApi::CreateMemoryInfo with name = "Cpu" and id = 0. - * - * \param[in] type - * \param[in] mem_type - * \param[out] out - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateCpuMemoryInfo, enum OrtAllocatorType type, enum OrtMemType mem_type, - _Outptr_ OrtMemoryInfo** out); - - /** \brief Compare ::OrtMemoryInfo objects for equality - * - * Compares all settings of each ::OrtMemoryInfo for equality - * - * \param[in] info1 - * \param[in] info2 - * \param[out] out Set to 0 if equal, -1 if not equal - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CompareMemoryInfo, _In_ const OrtMemoryInfo* info1, _In_ const OrtMemoryInfo* info2, _Out_ int* out); - - /** \brief Get name from ::OrtMemoryInfo - * - * \param[in] ptr - * \param[out] out Writes null terminated string to this pointer. Do NOT free the returned pointer. It is valid for the lifetime of the ::OrtMemoryInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(MemoryInfoGetName, _In_ const OrtMemoryInfo* ptr, _Out_ const char** out); - - /** \brief Get the id from ::OrtMemoryInfo - */ - ORT_API2_STATUS(MemoryInfoGetId, _In_ const OrtMemoryInfo* ptr, _Out_ int* out); - - /** \brief Get the ::OrtMemType from ::OrtMemoryInfo - */ - ORT_API2_STATUS(MemoryInfoGetMemType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtMemType* out); - - /** \brief Get the ::OrtAllocatorType from ::OrtMemoryInfo - */ - ORT_API2_STATUS(MemoryInfoGetType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtAllocatorType* out); - - /// @} - /// \name OrtAllocator - /// @{ - - /// \brief Calls OrtAllocator::Alloc function - ORT_API2_STATUS(AllocatorAlloc, _Inout_ OrtAllocator* ort_allocator, size_t size, _Outptr_ void** out); - /// \brief Calls OrtAllocator::Free function - ORT_API2_STATUS(AllocatorFree, _Inout_ OrtAllocator* ort_allocator, void* p); - /// \brief Calls OrtAllocator::Info function - ORT_API2_STATUS(AllocatorGetInfo, _In_ const OrtAllocator* ort_allocator, _Outptr_ const struct OrtMemoryInfo** out); - - /** \brief Get the default allocator - * - * The default allocator is a CPU based, non-arena. Always returns the same pointer to the same default allocator. - * - * \param[out] out Returned value should NOT be freed - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetAllocatorWithDefaultOptions, _Outptr_ OrtAllocator** out); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Override session symbolic dimensions - * - * Override symbolic dimensions (by specific denotation strings) with actual values if known at session initialization time to enable - * optimizations that can take advantage of fixed values (such as memory planning, etc) - * - * \param[in] options - * \param[in] dim_denotation - * \param[in] dim_value - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(AddFreeDimensionOverride, _Inout_ OrtSessionOptions* options, _In_ const char* dim_denotation, - _In_ int64_t dim_value); - - /// @} - /// \name OrtValue - /// @{ - - /* Internal information (not seen in Doxygen) - * - * APIs to support non-tensor types - map and sequence. - * Currently only the following types are supported - * Note: the following types should be kept in sync with data_types.h - * Map types - * ========= - * std::map - * std::map - * std::map - * std::map - * std::map - * std::map - * std::map - * std::map - * - * Sequence types - * ============== - * std::vector - * std::vector - * std::vector - * std::vector - * std::vector> - * std::vector - */ - - /** \brief Get non tensor data from an ::OrtValue - * - * If `value` is of type ONNX_TYPE_MAP, you need to retrieve the keys and values - * separately. Use index=0 to retrieve keys and index=1 to retrieve values. - * If `value` is of type ONNX_TYPE_SEQUENCE, use index to retrieve the index'th element - * of the sequence. - * - * \param[in] value - * \param[in] index See above for usage based on `value` type - * \param[in] allocator Allocator used to allocate ::OrtValue - * \param[out] out Created ::OrtValue that holds the element requested. Must be freed with OrtApi::ReleaseValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetValue, _In_ const OrtValue* value, int index, _Inout_ OrtAllocator* allocator, - _Outptr_ OrtValue** out); - - /** \brief Get non tensor value count from an ::OrtValue - * - * If `value` is of type ONNX_TYPE_MAP 2 will always be returned. For ONNX_TYPE_SEQUENCE - * the number of elements in the sequence will be returned - * - * \param[in] value - * \param[out] out - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetValueCount, _In_ const OrtValue* value, _Out_ size_t* out); - - /** \brief Create a map or sequence ::OrtValue - * - * To construct a map (ONNX_TYPE_MAP), use num_values = 2 and `in` should be an array of 2 ::OrtValue%s - * representing keys and values.
- * - * To construct a sequence (ONNX_TYPE_SEQUENCE), use num_values = N where N is the number of the elements in the - * sequence. 'in' should be an array of N ::OrtValue%s. - * - * \param[in] in See above for details - * \param[in] num_values - * \param[in] value_type Must be either ONNX_TYPE_MAP or ONNX_TYPE_SEQUENCE - * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateValue, _In_reads_(num_values) const OrtValue* const* in, size_t num_values, - enum ONNXType value_type, _Outptr_ OrtValue** out); - - /** \brief Create an opaque (custom user defined type) ::OrtValue - * - * Constructs an ::OrtValue that contains a value of non-standard type created for - * experiments or while awaiting standardization. ::OrtValue in this case would contain - * an internal representation of the Opaque type. Opaque types are distinguished from - * each other by two strings 1) domain and 2) type name. The combination of the two - * must be unique, so the type representation is properly identified internally. The combination - * must be properly registered from within ORT at both compile/run time or by another API. - * - * To construct the ::OrtValue pass domain and type names, also a pointer to a data container - * the type of which must be known to both ORT and the client program. That data container may or may - * not match the internal representation of the Opaque type. The sizeof(data_container) is passed for - * verification purposes. - * - * \param[in] domain_name Null terminated string of the domain name - * \param[in] type_name Null terminated string of the type name - * \param[in] data_container User pointer Data to populate ::OrtValue - * \param[in] data_container_size Size in bytes of what `data_container` points to - * \param[out] out Newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateOpaqueValue, _In_z_ const char* domain_name, _In_z_ const char* type_name, - _In_ const void* data_container, size_t data_container_size, _Outptr_ OrtValue** out); - - /** \brief Get internal data from an opaque (custom user defined type) ::OrtValue - * - * Copies internal data from an opaque value into a user provided buffer - * - * \see OrtApi::CreateOpaqueValue - * - * \param[in] domain_name Null terminated string of the domain name - * \param[in] type_name Null terminated string of the type name - * \param[in] in The opaque ::OrtValue - * \param[out] data_container Buffer to copy data into - * \param[out] data_container_size Size in bytes of the buffer pointed to by data_container. Must match the size of the internal buffer. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetOpaqueValue, _In_ const char* domain_name, _In_ const char* type_name, _In_ const OrtValue* in, - _Out_ void* data_container, size_t data_container_size); - - /// @} - /// \name OrtKernelInfo - /// Custom operator APIs. - /// @{ - - /** \brief Get a float stored as an attribute in the graph node - * - * \param[in] info ::OrtKernelInfo instance - * \param[in] name Null terminated string of the name of the attribute - * \param[out] out Pointer to memory where the attribute will be stored - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(KernelInfoGetAttribute_float, _In_ const OrtKernelInfo* info, _In_ const char* name, - _Out_ float* out); - - /** \brief Fetch a 64-bit int stored as an attribute in the graph node - * - * \param[in] info ::OrtKernelInfo instance - * \param[in] name Null terminated string of the name of the attribute - * \param[out] out Pointer to memory where the attribute will be stored - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(KernelInfoGetAttribute_int64, _In_ const OrtKernelInfo* info, _In_ const char* name, - _Out_ int64_t* out); - - /** \brief Fetch a string stored as an attribute in the graph node - * - * If `out` is nullptr, the value of `size` is set to the true size of the string - * attribute, and a success status is returned. - * - * If the `size` parameter is greater than or equal to the actual string attribute's size, - * the value of `size` is set to the true size of the string attribute, the provided memory - * is filled with the attribute's contents, and a success status is returned. - * - * If the `size` parameter is less than the actual string attribute's size and `out` - * is not nullptr, the value of `size` is set to the true size of the string attribute - * and a failure status is returned.) - * - * \param[in] info ::OrtKernelInfo instance - * \param[in] name Null terminated string of the name of the attribute - * \param[out] out Pointer to memory where the attribute will be stored - * \param[in,out] size See above comments for details - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(KernelInfoGetAttribute_string, _In_ const OrtKernelInfo* info, _In_ const char* name, _Out_ char* out, - _Inout_ size_t* size); - - /// @} - /// \name OrtKernelContext - /// Custom operator APIs. - /// @{ - - /** \brief Used for custom operators, get the input count of a kernel - * - * \see ::OrtCustomOp - */ - ORT_API2_STATUS(KernelContext_GetInputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out); - - /** \brief Used for custom operators, get the output count of a kernel - * - * \see ::OrtCustomOp - */ - ORT_API2_STATUS(KernelContext_GetOutputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out); - - /** \brief Used for custom operators, get an input of a kernel - * - * \see ::OrtCustomOp - */ - ORT_API2_STATUS(KernelContext_GetInput, _In_ const OrtKernelContext* context, _In_ size_t index, - _Out_ const OrtValue** out); - - /** \brief Used for custom operators, get an output of a kernel - * - * \see ::OrtCustomOp - */ - ORT_API2_STATUS(KernelContext_GetOutput, _Inout_ OrtKernelContext* context, _In_ size_t index, - _In_ const int64_t* dim_values, size_t dim_count, _Outptr_ OrtValue** out); - - /// @} - /// \name OrtEnv - /// @{ - ORT_CLASS_RELEASE(Env); - /// @} - /// \name OrtStatus - /// @{ - ORT_CLASS_RELEASE(Status); - /// @} - /// \name OrtMemoryInfo - /// @{ - ORT_CLASS_RELEASE(MemoryInfo); - /// @} - /// \name OrtSession - /// @{ - ORT_CLASS_RELEASE(Session); // Don't call ReleaseSession from Dllmain (because session owns a thread pool) - /// @} - /// \name OrtValue - /// @{ - ORT_CLASS_RELEASE(Value); - /// @} - /// \name OrtRunOptions - /// @{ - ORT_CLASS_RELEASE(RunOptions); - /// @} - /// \name OrtTypeInfo - /// @{ - ORT_CLASS_RELEASE(TypeInfo); - /// @} - /// \name OrtTensorTypeAndShapeInfo - /// @{ - ORT_CLASS_RELEASE(TensorTypeAndShapeInfo); - /// @} - /// \name OrtSessionOptions - /// @{ - ORT_CLASS_RELEASE(SessionOptions); - /// @} - /// \name OrtCustomOpDomain - /// @{ - ORT_CLASS_RELEASE(CustomOpDomain); - - /// @} - /// \name OrtTypeInfo - /// @{ - - /** \brief Get denotation from type information - * - * Augments ::OrtTypeInfo to return denotations on the type. - * - * This is used by WinML to determine if an input/output is intended to be an Image or a Tensor. - * - * \param[in] type_info - * \param[out] denotation Pointer to the null terminated denotation string is written to this pointer. This pointer is valid until the object is destroyed or the name is changed, do not free. - * \param[out] len Length in bytes of the string returned in `denotation` - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetDenotationFromTypeInfo, _In_ const OrtTypeInfo* type_info, _Out_ const char** const denotation, - _Out_ size_t* len); - - /** \brief Get detailed map information from an ::OrtTypeInfo - * - * This augments ::OrtTypeInfo to return an ::OrtMapTypeInfo when the type is a map. - * The OrtMapTypeInfo has additional information about the map's key type and value type. - * - * This is used by WinML to support model reflection APIs. - * - * \param[out] type_info - * \param[out] out A pointer to the ::OrtMapTypeInfo. Do not free this value - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CastTypeInfoToMapTypeInfo, _In_ const OrtTypeInfo* type_info, - _Outptr_result_maybenull_ const OrtMapTypeInfo** out); - - /** \brief Cast ::OrtTypeInfo to an ::OrtSequenceTypeInfo - * - * This api augments ::OrtTypeInfo to return an ::OrtSequenceTypeInfo when the type is a sequence. - * The ::OrtSequenceTypeInfo has additional information about the sequence's element type. - * - * This is used by WinML to support model reflection APIs. - * - * \param[in] type_info - * \param[out] out A pointer to the OrtSequenceTypeInfo. Do not free this value - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CastTypeInfoToSequenceTypeInfo, _In_ const OrtTypeInfo* type_info, - _Outptr_result_maybenull_ const OrtSequenceTypeInfo** out); - - /// @} - /// \name OrtMapTypeInfo - /// @{ - - /** \brief Get key type from an ::OrtMapTypeInfo - * - * Key types are restricted to being scalar types. - * - * This is used by WinML to support model reflection APIs. - * - * \param[in] map_type_info - * \param[out] out - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetMapKeyType, _In_ const OrtMapTypeInfo* map_type_info, _Out_ enum ONNXTensorElementDataType* out); - - /** \brief Get the value type from an ::OrtMapTypeInfo - * - * \param[in] map_type_info - * \param[out] type_info - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetMapValueType, _In_ const OrtMapTypeInfo* map_type_info, _Outptr_ OrtTypeInfo** type_info); - - /// @} - /// \name OrtSequenceTypeInfo - /// @{ - - /** \brief Get element type from an ::OrtSequenceTypeInfo - * - * This is used by WinML to support model reflection APIs. - * - * \param[in] sequence_type_info - * \param[out] type_info - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetSequenceElementType, _In_ const OrtSequenceTypeInfo* sequence_type_info, - _Outptr_ OrtTypeInfo** type_info); - - /// @} - /// \name OrtMapTypeInfo - /// @{ - ORT_CLASS_RELEASE(MapTypeInfo); - /// @} - /// \name OrtSequenceTypeInfo - /// @{ - ORT_CLASS_RELEASE(SequenceTypeInfo); - - /// @} - /// \name OrtSession - /// @{ - - /** \brief End profiling and return filename of the profile data - * - * Profiling is turned on through OrtApi::EnableProfiling - * - * \param[in] session - * \param[in] allocator - * \param[out] out Null terminated string of the filename, allocated using `allocator`. Must be freed using `allocator` - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionEndProfiling, _In_ OrtSession* session, _Inout_ OrtAllocator* allocator, _Outptr_ char** out); - - /** \brief Get ::OrtModelMetadata from an ::OrtSession - * - * \param[in] session - * \param[out] out Newly created ::OrtModelMetadata. Must be freed using OrtApi::ReleaseModelMetadata - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetModelMetadata, _In_ const OrtSession* session, _Outptr_ OrtModelMetadata** out); - - /// @} - /// \name OrtModelMetadata - /// @{ - - /** \brief Get `producer name` from an ::OrtModelMetadata - * - * \param[in] model_metadata - * \param[in] allocator - * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator` - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ModelMetadataGetProducerName, _In_ const OrtModelMetadata* model_metadata, - _Inout_ OrtAllocator* allocator, _Outptr_ char** value); - - /** \brief Get `graph name` from an ::OrtModelMetadata - * - * \param[in] model_metadata - * \param[in] allocator - * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator` - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ModelMetadataGetGraphName, _In_ const OrtModelMetadata* model_metadata, - _Inout_ OrtAllocator* allocator, _Outptr_ char** value); - - /** \brief Get `domain` from an ::OrtModelMetadata - * - * \param[in] model_metadata - * \param[in] allocator - * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator` - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ModelMetadataGetDomain, _In_ const OrtModelMetadata* model_metadata, _Inout_ OrtAllocator* allocator, - _Outptr_ char** value); - - /** \brief Get `description` from an ::OrtModelMetadata - * - * \param[in] model_metadata - * \param[in] allocator - * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator` - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ModelMetadataGetDescription, _In_ const OrtModelMetadata* model_metadata, - _Inout_ OrtAllocator* allocator, _Outptr_ char** value); - - /** \brief Return data for a key in the custom metadata map in an ::OrtModelMetadata - * - * \param[in] model_metadata - * \param[in] allocator - * \param[in] key Null terminated string - * \param[out] value Set to a null terminated string allocated using `allocator`. Must be freed using `allocator` - * `value` will be set to nullptr if the given key is not found in the custom metadata map. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ModelMetadataLookupCustomMetadataMap, _In_ const OrtModelMetadata* model_metadata, - _Inout_ OrtAllocator* allocator, _In_ const char* key, _Outptr_result_maybenull_ char** value); - - /** \brief Get version number from an ::OrtModelMetadata - * - * \param[in] model_metadata - * \param[out] value Set to the version number - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ModelMetadataGetVersion, _In_ const OrtModelMetadata* model_metadata, _Out_ int64_t* value); - - ORT_CLASS_RELEASE(ModelMetadata); - - /// @} - /// \name OrtEnv - /// @{ - - /** \brief Create an OrtEnv - * - * Create an environment with global threadpools that will be shared across sessions. - * Use this in conjunction with OrtApi::DisablePerSessionThreads or else the session will use - * its own thread pools. - * - * \param[in] log_severity_level The log severity level. - * \param[in] logid The log identifier. - * \param[in] tp_options - * \param[out] out Returned newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateEnvWithGlobalThreadPools, OrtLoggingLevel log_severity_level, _In_ const char* logid, - _In_ const OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Use global thread pool on a session - * - * Disable using per session thread pool and use the shared global threadpool. - * This should be used in conjunction with OrtApi::CreateEnvWithGlobalThreadPools. - * - * \param[in] options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(DisablePerSessionThreads, _Inout_ OrtSessionOptions* options); - - /// @} - /// \name OrtThreadingOptions - /// @{ - - /** \brief Create an ::OrtThreadingOptions - * - * \param[out] out Newly created ::OrtThreadingOptions. Must be freed with OrtApi::ReleaseThreadingOptions - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateThreadingOptions, _Outptr_ OrtThreadingOptions** out); - - ORT_CLASS_RELEASE(ThreadingOptions); - - /// @} - /// \name OrtModelMetadata - /// @{ - - /** - * - * \param[in] model_metadata - * \param[in] allocator - * \param[out] keys Array of null terminated strings (array count = num_keys) allocated using `allocator`. - * The strings and the pointer array must be freed using `allocator` - * `keys` will be set to nullptr if the custom metadata map is empty. - * \param[out] num_keys Set to the number of elements in the `keys` array - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ModelMetadataGetCustomMetadataMapKeys, _In_ const OrtModelMetadata* model_metadata, - _Inout_ OrtAllocator* allocator, _Outptr_result_buffer_maybenull_(*num_keys) char*** keys, _Out_ int64_t* num_keys); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** - * - * Override symbolic dimensions (by specific name strings) with actual values - * if known at session initialization time to enable optimizations that can - * take advantage of fixed values (such as memory planning, etc) - * - */ - ORT_API2_STATUS(AddFreeDimensionOverrideByName, - _Inout_ OrtSessionOptions* options, _In_ const char* dim_name, - _In_ int64_t dim_value); - - /// @} - /// \name Misc - /// @{ - - /** \brief Get the names of all available providers - * - * \note The providers in the list are not guaranteed to be usable. They may fail to load due to missing system dependencies. - * For example, if the CUDA/cuDNN libraries are not installed, the CUDA provider will report an error when it is added to the session options. - * - * \param[out] out_ptr Set to a pointer to an array of null terminated strings of the available providers. The entries and the - * array itself must be freed using OrtApi::ReleaseAvailableProviders - * \param[out] provider_length Set to the number of entries in the `out_ptr` array - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetAvailableProviders, _Outptr_ char*** out_ptr, _Out_ int* provider_length); - - /** \brief Release data from OrtApi::GetAvailableProviders - * - * \param[in] ptr The `out_ptr` result from OrtApi::GetAvailableProviders. - * \param[in] providers_length The `provider_length` result from OrtApi::GetAvailableProviders - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ReleaseAvailableProviders, _In_ char** ptr, - _In_ int providers_length); - - /// @} - /// \name OrtValue - /// @{ - - /** \brief Get the length of a single string in a string tensor - * - * \param[in] value A string tensor - * \param[in] index Index of the string in the tensor - * \param[out] out Set to number of bytes of the string element - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetStringTensorElementLength, _In_ const OrtValue* value, size_t index, _Out_ size_t* out); - - /** \brief Get a single string from a string tensor - * - * \param[in] value A string tensor - * \param[in] s_len Number of bytes in the `s` buffer. Must match the value returned by OrtApi::GetStringTensorElementLength. - * \param[in] index Index of the string in the tensor - * \param[out] s The string element contents in UTF-8 encoding. The string is NOT null-terminated. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetStringTensorElement, _In_ const OrtValue* value, size_t s_len, size_t index, _Out_writes_bytes_all_(s_len) void* s); - - /** \brief Set a single string in a string tensor - * - * \param[in] value A string tensor - * \param[in] s A null terminated UTF-8 encoded string - * \param[in] index Index of the string in the tensor to set - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(FillStringTensorElement, _Inout_ OrtValue* value, _In_ const char* s, size_t index); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Set a session configuration entry as a pair of strings - * - * If a configuration with same key exists, this will overwrite the configuration with the given config_value. - * - * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h - * - * \param[in] options - * \param[in] config_key A null terminated string representation of the config key - * \param[in] config_value A null terminated string representation of the config value - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(AddSessionConfigEntry, _Inout_ OrtSessionOptions* options, - _In_z_ const char* config_key, _In_z_ const char* config_value); - - /// @} - /// \name OrtAllocator - /// @{ - - /** \brief Create an allocator for an ::OrtSession following an ::OrtMemoryInfo - * - * \param[in] session - * \param[in] mem_info valid ::OrtMemoryInfo instance - * \param[out] out Newly created ::OrtAllocator. Must be freed with OrtApi::ReleaseAllocator - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateAllocator, _In_ const OrtSession* session, _In_ const OrtMemoryInfo* mem_info, - _Outptr_ OrtAllocator** out); - - /** \brief Release an ::OrtAllocator obtained from OrtApi::CreateAllocator - */ - ORT_CLASS_RELEASE(Allocator); - - /// @} - /// \name OrtSession - /// @{ - - /** \brief Run a model using Io Bindings for the inputs & outputs - * - * \see OrtApi::Run - * - * \param[in] session - * \param[in] run_options - * \param[in] binding_ptr - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(RunWithBinding, _Inout_ OrtSession* session, _In_ const OrtRunOptions* run_options, _In_ const OrtIoBinding* binding_ptr); - - /** \brief Create an ::OrtIoBinding instance - * - * An IoBinding object allows one to bind pre-allocated ::OrtValue%s to input names. - * Thus if you want to use a raw on device buffer as input or output you can avoid - * extra copy during runtime. - * - * \param[in] session - * \param[out] out Newly created ::OrtIoBinding. Must be freed with OrtApi::ReleaseIoBinding - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateIoBinding, _Inout_ OrtSession* session, _Outptr_ OrtIoBinding** out); - - /// @} - /// \name OrtIoBinding - /// @{ - - /** \brief Release an ::OrtIoBinding obtained from OrtApi::CreateIoBinding - */ - ORT_CLASS_RELEASE(IoBinding); - - /** \brief Bind an ::OrtValue to an ::OrtIoBinding input - * - * When using OrtApi::RunWithBinding this value is used for the named input - * - * \param[in] binding_ptr - * \param[in] name Name for the model input - * \param[in] val_ptr ::OrtValue of Tensor type. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(BindInput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr); - - /** \brief Bind an ::OrtValue to an ::OrtIoBinding output - * - * When using OrtApi::RunWithBinding this value is used for the named output - * - * \param[in] binding_ptr - * \param[in] name Null terminated string of the model output name - * \param[in] val_ptr ::OrtValue of Tensor type. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(BindOutput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr); - - /** \brief Bind an ::OrtIoBinding output to a device - * - * Binds the ::OrtValue to a device which is specified by ::OrtMemoryInfo. - * You can either create an instance of ::OrtMemoryInfo with a device id or obtain one from the allocator that you have created/are using - * This is useful when one or more outputs have dynamic shapes and, it is hard to pre-allocate and bind a chunk of - * memory within ::OrtValue ahead of time. - * - * \see OrtApi::RunWithBinding - * - * \param[in] binding_ptr - * \param[in] name Null terminated string of the device name - * \param[in] mem_info_ptr - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(BindOutputToDevice, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtMemoryInfo* mem_info_ptr); - - /** \brief Get the names of an ::OrtIoBinding's outputs - * - * Returns the names of the outputs in the order they were bound. This is useful after running the model - * with bound outputs because the returned names are in order in which output ::OrtValue are returned. This is useful if - * the order of outputs and their names is not known. - * - * \param[in] binding_ptr - * \param[in] allocator Allocator used to allocate continuous buffers for output strings and lengths. - * \param[out] buffer Returns an array of non-null terminated UTF-8 strings. The number of strings stored is returned in the count parameter. - * This buffer is allocated using `allocator` and must be freed using it. - * \param[out] lengths Returns an array of `count` lengths of the strings returned in `buffer` - * This buffer is allocated using `allocator` and must be freed using it. - * \param[out] count Number of strings returned. If `binding_ptr` has no bound outputs, zero is returned, - * no memory allocation is performed and buffer and lengths are set to nullptr. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetBoundOutputNames, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator, - _Out_ char** buffer, _Out_writes_all_(count) size_t** lengths, _Out_ size_t* count); - - /** \brief Get the output ::OrtValue objects from an ::OrtIoBinding - * - * Returns an array of pointers to individually allocated ::OrtValue%s that contain results of a model execution with OrtApi::RunWithBinding - * The array contains the same number of ::OrtValue%s and they are in the same order as they were bound with OrtApi::BindOutput - * or OrtApi::BindOutputToDevice. - * - * The returned ::OrtValue%s must be released using OrtApi::ReleaseValue after they are no longer needed. - * The array is allocated using the specified instance of the allocator and must be freed using the same allocator after - * all the ::OrtValue%s contained therein are individually released. - * - * \param[in] binding_ptr - * \param[in] allocator Allocator used to allocate output array - * \param[out] output Set to the allocated array of allocated ::OrtValue outputs. Set to nullptr if there are 0 outputs. - * \param[out] output_count Set to number of ::OrtValue%s returned - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetBoundOutputValues, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator, - _Out_writes_all_(output_count) OrtValue*** output, _Out_ size_t* output_count); - - /** \brief Clears any previously set Inputs for an ::OrtIoBinding - */ - void(ORT_API_CALL* ClearBoundInputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL; - - /** \brief Clears any previously set Outputs for an ::OrtIoBinding - */ - void(ORT_API_CALL* ClearBoundOutputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL; - - /// @} - /// \name OrtValue - /// @{ - - /** \brief Direct memory access to a specified tensor element - * - * For example, given a tensor with shape of [3,224,224], a pointer to the element at location [2,150,128] can be retrieved - * - * This function only works for numeric type tensors (No strings, etc). - * This is a no-copy method whose returned pointer is valid until the passed in ::OrtValue is free'd. - * - * \param[in] value - * \param[in] location_values Pointer to an array of index values that specify an element's location relative to its shape - * \param[in] location_values_count Number of elements in location_values. Must match the number of elements in the tensor's shape. - * \param[out] out Set to a pointer to the element specified - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(TensorAt, _Inout_ OrtValue* value, const int64_t* location_values, size_t location_values_count, _Outptr_ void** out); - - /// @} - /// \name OrtEnv - /// @{ - - /** \brief Create an allocator and register it with the ::OrtEnv - * - * Enables sharing the allocator between multiple sessions that use the same env instance. - * Lifetime of the created allocator will be valid for the duration of the environment. - * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered. - * - * See https://onnxruntime.ai/docs/reference/api/c-api.html for details. - * - * \param[in] env ::OrtEnv instance - * \param[in] mem_info - * \param[in] arena_cfg Pass nullptr for defaults - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateAndRegisterAllocator, _Inout_ OrtEnv* env, _In_ const OrtMemoryInfo* mem_info, - _In_ const OrtArenaCfg* arena_cfg); - - /** \brief Set language projection - * - * Set the language projection for collecting telemetry data when Env is created. - * - * The default is ORT_PROJECTION_C, which means it will classify the language not in the list to C also. - * - * \param[in] ort_env - * \param[in] projection - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetLanguageProjection, _In_ const OrtEnv* ort_env, _In_ OrtLanguageProjection projection); - - /// @} - /// \name OrtSession - /// @{ - - /** \brief Return the time that profiling was started - * - * \note The timer precision varies per platform. On Windows and MacOS, the precision will be ~100ns - * - * \param[in] session - * \param[out] out nanoseconds of profiling's start time - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionGetProfilingStartTimeNs, _In_ const OrtSession* session, _Outptr_ uint64_t* out); - - /// @} - /// \name OrtThreadingOptions - /// @{ - - /** \brief Set global intra-op thread count - * - * This configures the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools - * - * \param[in] tp_options - * \param[in] intra_op_num_threads Number of threads, special values:
- * 0 = Use default thread count
- * 1 = The invoking thread will be used; no threads will be created in the thread pool. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetGlobalIntraOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int intra_op_num_threads); - - /** \brief Set global inter-op thread count - * - * This configures the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools - * - * \param[in] tp_options - * \param[in] inter_op_num_threads Number of threads, special values:
- * 0 = Use default thread count
- * 1 = The invoking thread will be used; no threads will be created in the thread pool. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetGlobalInterOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int inter_op_num_threads); - - /** \brief Set global spin control options - * - * This will configure the global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools. - * Allow spinning of thread pools when their queues are empty. This will set the value for both - * inter_op and intra_op threadpools. - * - * \param[in] tp_options - * \param[in] allow_spinning Valid values are 0 or 1.
- * 0 = It won't spin (recommended if CPU usage is high)
- * 1 = Threadpool will spin to wait for queue to become non-empty - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetGlobalSpinControl, _Inout_ OrtThreadingOptions* tp_options, int allow_spinning); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Add a pre-allocated initializer to a session - * - * If a model contains an initializer with a name that is same as the name passed to this call, - * ORT will use this initializer instance instead of deserializing one from the model file. This - * is useful when you want to share the same initializer across sessions. - * - * \param[in] options - * \param[in] name Null terminated string of the initializer name - * \param[in] val ::OrtValue containing the initializer. Its lifetime and the underlying initializer buffer must be - * managed by the user (created using the OrtApi::CreateTensorWithDataAsOrtValue) and it must outlive the session object - * to which it is added. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(AddInitializer, _Inout_ OrtSessionOptions* options, _In_z_ const char* name, - _In_ const OrtValue* val); - - /// @} - /// \name OrtEnv - /// @{ - - /** - * Create a custom environment with global threadpools and logger that will be shared across sessions. - * Use this in conjunction with OrtApi::DisablePerSessionThreads or else the session will use - * its own thread pools. - * - * \param[in] logging_function A pointer to a logging function. - * \param[in] logger_param A pointer to arbitrary data passed as the ::OrtLoggingFunction `param` parameter to - * `logging_function`. - * \param[in] log_severity_level The log severity level. - * \param[in] logid The log identifier. - * \param[in] tp_options - * \param[out] out Newly created OrtEnv. Must be freed with OrtApi::ReleaseEnv - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateEnvWithCustomLoggerAndGlobalThreadPools, OrtLoggingFunction logging_function, _In_opt_ void* logger_param, OrtLoggingLevel log_severity_level, - _In_ const char* logid, _In_ const struct OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Append CUDA provider to session options - * - * If CUDA is not available (due to a non CUDA enabled build, or if CUDA is not installed on the system), this function will return failure. - * - * \param[in] options - * \param[in] cuda_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA, - _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptions* cuda_options); - - /** \brief Append ROCM execution provider to the session options - * - * If ROCM is not available (due to a non ROCM enabled build, or if ROCM is not installed on the system), this function will return failure. - * - * \param[in] options - * \param[in] rocm_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_ROCM, - _In_ OrtSessionOptions* options, _In_ const OrtROCMProviderOptions* rocm_options); - - /** \brief Append OpenVINO execution provider to the session options - * - * If OpenVINO is not available (due to a non OpenVINO enabled build, or if OpenVINO is not installed on the system), this function will fail. - * - * \param[in] options - * \param[in] provider_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_OpenVINO, - _In_ OrtSessionOptions* options, _In_ const OrtOpenVINOProviderOptions* provider_options); - - /// @} - /// \name OrtThreadingOptions - /// @{ - - /** \brief Set threading flush-to-zero and denormal-as-zero - * - * Sets global thread pool options to be used in the call to OrtApi::CreateEnvWithGlobalThreadPools. - * Flush-to-zero and denormal-as-zero are applied to threads in both intra and inter global thread pool. - * \note This option is not needed if the models used have no denormals. Having no denormals is recommended as this option may hurt model accuracy. - * - * \param[in] tp_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetGlobalDenormalAsZero, _Inout_ OrtThreadingOptions* tp_options); - - /// @} - /// \name OrtArenaCfg - /// @{ - - /** \deprecated Use OrtApi::CreateArenaCfgV2 - * - * This will create the configuration of an arena that can eventually be used to define an arena based allocator's behavior - * - * \param[in] max_mem Use 0 to allow ORT to choose the default - * \param[in] arena_extend_strategy Use -1 to allow ORT to choose the default, 0 = kNextPowerOfTwo, 1 = kSameAsRequested - * \param[in] initial_chunk_size_bytes Use -1 to allow ORT to choose the default - * \param[in] max_dead_bytes_per_chunk Use -1 to allow ORT to choose the default - * \param[in] out A pointer to an OrtArenaCfg instance - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateArenaCfg, _In_ size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, - int max_dead_bytes_per_chunk, _Outptr_ OrtArenaCfg** out); - - ORT_CLASS_RELEASE(ArenaCfg); - - /// @} - /// \name OrtModelMetadata - /// @{ - - /** - * Use this to obtain the description of the graph present in the model - * (doc_string field of the GraphProto message within the ModelProto message). - * If it doesn't exist, an empty string will be returned. - * - * \param[in] model_metadata An instance of ::OrtModelMetadata - * \param[in] allocator Allocator used to allocate the string that will be returned back - * \param[out] value Set to a null terminated string allocated using `allocator`. The caller is responsible for freeing it using `allocator` - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(ModelMetadataGetGraphDescription, _In_ const OrtModelMetadata* model_metadata, - _Inout_ OrtAllocator* allocator, _Outptr_ char** value); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Append TensorRT provider to session options - * - * If TensorRT is not available (due to a non TensorRT enabled build, or if TensorRT is not installed on the system), this function will return failure. - * - * \param[in] options - * \param[in] tensorrt_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_TensorRT, - _In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptions* tensorrt_options); - - /// @} - /// \name Misc - /// @{ - - /** \brief Set current GPU device ID - * - * Set the current device id of the GPU execution provider (CUDA/tensorrt/rocm). The device id should be less - * than the total number of devices available. This is only useful when multiple-GPUs are installed and it is - * required to restrict execution to a single GPU. - * - * \param[in] device_id - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetCurrentGpuDeviceId, _In_ int device_id); - - /** \brief Get current GPU device ID - * - * Get the current device id of the GPU execution provider (CUDA/tensorrt/rocm). - * - * \see OrtApi::SetCurrentGpuDeviceId - * - * \param[out] device_id - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetCurrentGpuDeviceId, _In_ int* device_id); - - /// @} - /// \name OrtKernelInfo - /// Custom operator APIs. - /// @{ - - /** \brief Fetch an array of int64_t values stored as an attribute in the graph node - * - * - * If `out` is nullptr, the value of `size` is set to the true size of the attribute - * array's size, and a success status is returned. - * - * If the `size` parameter is greater than or equal to the actual attribute array's size, - * the value of `size` is set to the true size of the attribute array's size, - * the provided memory is filled with the attribute's contents, - * and a success status is returned. - * - * If the `size` parameter is less than the actual attribute array's size and `out` - * is not nullptr, the value of `size` is set to the true size of the attribute array's size - * and a failure status is returned.) - * - * \param[in] info instance - * \param[in] name name of the attribute to be parsed - * \param[out] out pointer to memory where the attribute's contents are to be stored - * \param[in, out] size actual size of attribute array - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(KernelInfoGetAttributeArray_float, _In_ const OrtKernelInfo* info, _In_ const char* name, - _Out_ float* out, _Inout_ size_t* size); - - /** \brief Fetch an array of int64_t values stored as an attribute in the graph node - * - * If `out` is nullptr, the value of `size` is set to the true size of the attribute - * array's size, and a success status is returned. - * - * If the `size` parameter is greater than or equal to the actual attribute array's size, - * the value of `size` is set to the true size of the attribute array's size, - * the provided memory is filled with the attribute's contents, - * and a success status is returned. - * - * If the `size` parameter is less than the actual attribute array's size and `out` - * is not nullptr, the value of `size` is set to the true size of the attribute array's size - * and a failure status is returned.) - * - * \param[in] info instance - * \param[in] name name of the attribute to be parsed - * \param[out] out pointer to memory where the attribute's contents are to be stored - * \param[in, out] size actual size of attribute array - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(KernelInfoGetAttributeArray_int64, _In_ const OrtKernelInfo* info, _In_ const char* name, - _Out_ int64_t* out, _Inout_ size_t* size); - - /// @} - /// \name OrtArenaCfg - /// @{ - - /** \brief Create an ::OrtArenaCfg - * - * Create the configuration of an arena that can eventually be used to define an arena based allocator's behavior. - * - * Supported keys are (See https://onnxruntime.ai/docs/reference/api/c-api.html for details on what the - * following parameters mean and how to choose these values.): - * "max_mem": Maximum memory that can be allocated by the arena based allocator. - * Use 0 for ORT to pick the best value. Default is 0. - * "arena_extend_strategy": 0 = kNextPowerOfTwo, 1 = kSameAsRequested. - * Use -1 to allow ORT to choose the default. - * "initial_chunk_size_bytes": (Possible) Size of the first allocation in the arena. - * Only relevant if arena strategy is `kNextPowerOfTwo`. Use -1 to allow ORT to choose the default. - * Ultimately, the first allocation size is determined by the allocation memory request. - * "max_dead_bytes_per_chunk": Threshold of unused memory in an allocated chunk of arena memory after - * crossing which the current chunk is chunked into 2. - * "initial_growth_chunk_size_bytes": (Possible) Size of the second allocation in the arena. - * Only relevant if arena strategy is `kNextPowerOfTwo`. Use -1 to allow ORT to choose the default. - * Ultimately, the allocation size is determined by the allocation memory request. - * Further allocation sizes are governed by the arena extend strategy. - * - * \param[in] arena_config_keys Keys to configure the arena - * \param[in] arena_config_values Values to configure the arena - * \param[in] num_keys Number of keys in `arena_config_keys` and `arena_config_values` - * \param[out] out Newly created ::OrtArenaCfg. Must be freed with OrtApi::ReleaseArenaCfg - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateArenaCfgV2, _In_reads_(num_keys) const char* const* arena_config_keys, - _In_reads_(num_keys) const size_t* arena_config_values, _In_ size_t num_keys, - _Outptr_ OrtArenaCfg** out); - - /// @} - /// \name OrtRunOptions - /// @{ - - /** \brief Set a single run configuration entry as a pair of strings - * - * If a configuration with same key exists, this will overwrite the configuration with the given config_value - * - * The config_key and the format of config_value are defined in onnxruntime_run_options_config_keys.h - * - * \param[in] options - * \param[in] config_key A null terminated string representation of the config key - * \param[in] config_value A null terminated string representation of the config value - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(AddRunConfigEntry, _Inout_ OrtRunOptions* options, - _In_z_ const char* config_key, _In_z_ const char* config_value); - - /// @} - /// \name OrtPrepackedWeightsContainer - /// @{ - - /** \brief Create an ::OrtPrepackedWeightsContainer - * - * This container will hold pre-packed buffers of shared initializers for sharing between sessions - * (i.e.) if there are shared initializers that can be shared between sessions, the pre-packed buffers - * of these (if any) may possibly be shared to provide memory footprint savings. Pass this container - * to sessions that you would like to share pre-packed buffers of shared initializers at session - * creation time. - * - * \param[out] out Newly created ::OrtPrepackedWeightsContainer. Must be freed with OrtApi::ReleasePrepackedWeightsContainer - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreatePrepackedWeightsContainer, _Outptr_ OrtPrepackedWeightsContainer** out); - - /** \brief Release OrtPrepackedWeightsContainer instance - * - * \note instance must not be released until the sessions using it are released - */ - ORT_CLASS_RELEASE(PrepackedWeightsContainer); - - /// @} - /// \name OrtSession - /// @{ - - /** \brief Create session with prepacked weights container - * - * Same functionality offered by OrtApi::CreateSession except that a container that contains - * pre-packed weights' buffers is written into/read from by the created session. - * This is useful when used in conjunction with OrtApi::AddInitializer which injects - * shared initializer info into sessions. Wherever possible, the pre-packed versions of these - * shared initializers are cached in this container so that multiple sessions can just re-use - * these instead of duplicating these in memory. - * - * \param[in] env OrtEnv instance instance - * \param[in] model_path Null terminated string of the path (wchar on Windows, char otherwise) - * \param[in] options - * \param[in] prepacked_weights_container - * \param[out] out Newly created ::OrtSession. Must be freed with OrtApi::ReleaseSession - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateSessionWithPrepackedWeightsContainer, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path, - _In_ const OrtSessionOptions* options, _Inout_ OrtPrepackedWeightsContainer* prepacked_weights_container, - _Outptr_ OrtSession** out); - - /** \brief Create session from memory with prepacked weights container - * - * Same functionality offered by OrtApi::CreateSessionFromArray except that a container that contains - * pre-packed weights' buffers is written into/read from by the created session. - * This is useful when used in conjunction with OrtApi::AddInitializer which injects - * shared initializer info into sessions. Wherever possible, the pre-packed versions of these - * shared initializers are cached in this container so that multiple sessions can just re-use - * these instead of duplicating these in memory. - * - * \param[in] env - * \param[in] model_data Array of bytes holding the model - * \param[in] model_data_length Number of bytes in `model_data_model` - * \param[in] options - * \param[in] prepacked_weights_container - * \param[out] out Newly created ::OrtSession. Must be freed with OrtApi::ReleaseSession - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateSessionFromArrayWithPrepackedWeightsContainer, _In_ const OrtEnv* env, - _In_ const void* model_data, size_t model_data_length, - _In_ const OrtSessionOptions* options, _Inout_ OrtPrepackedWeightsContainer* prepacked_weights_container, - _Outptr_ OrtSession** out); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Append TensorRT execution provider to the session options - * - * If TensorRT is not available (due to a non TensorRT enabled build), this function will return failure. - * - * This is slightly different from OrtApi::SessionOptionsAppendExecutionProvider_TensorRT, it takes an - * ::OrtTensorRTProviderOptions which is publicly defined. This takes an opaque ::OrtTensorRTProviderOptionsV2 - * which must be created with OrtApi::CreateTensorRTProviderOptions. - * - * For OrtApi::SessionOptionsAppendExecutionProvider_TensorRT, the user needs to instantiate ::OrtTensorRTProviderOptions - * as well as allocate/release buffers for some members of ::OrtTensorRTProviderOptions. - * Here, OrtApi::CreateTensorRTProviderOptions and Ortapi::ReleaseTensorRTProviderOptions will do the memory management for you. - * - * \param[in] options - * \param[in] tensorrt_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_TensorRT_V2, - _In_ OrtSessionOptions* options, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options); - - /// @} - /// \name OrtTensorRTProviderOptionsV2 - /// @{ - - /** \brief Create an OrtTensorRTProviderOptionsV2 - * - * \param[out] out Newly created ::OrtTensorRTProviderOptionsV2. Must be released with OrtApi::ReleaseTensorRTProviderOptions - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateTensorRTProviderOptions, _Outptr_ OrtTensorRTProviderOptionsV2** out); - - /** \brief Set options in a TensorRT Execution Provider. - * - * Please refer to https://www.onnxruntime.ai/docs/reference/execution-providers/TensorRT-ExecutionProvider.html#c-api-example - * to know the available keys and values. Key should be in null terminated string format of the member of ::OrtTensorRTProviderOptionsV2 - * and value should be its related range. - * - * For example, key="trt_max_workspace_size" and value="2147483648" - * - * \param[in] tensorrt_options - * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys - * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values - * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(UpdateTensorRTProviderOptions, _Inout_ OrtTensorRTProviderOptionsV2* tensorrt_options, - _In_reads_(num_keys) const char* const* provider_options_keys, - _In_reads_(num_keys) const char* const* provider_options_values, - _In_ size_t num_keys); - - /** \brief Get serialized TensorRT provider options string. - * - * For example, "trt_max_workspace_size=2147483648;trt_max_partition_iterations=10;trt_int8_enable=1;......" - * - * \param tensorrt_options - OrTensorRTProviderOptionsV2 instance - * \param allocator - a ptr to an instance of OrtAllocator obtained with OrtApi::CreateAllocator or OrtApi::GetAllocatorWithDefaultOptions - * the specified allocator will be used to allocate continuous buffers for output strings and lengths. - * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetTensorRTProviderOptionsAsString, _In_ const OrtTensorRTProviderOptionsV2* tensorrt_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr); - - /** \brief Release an ::OrtTensorRTProviderOptionsV2 - * - * \note This is an exception in the naming convention of other Release* functions, as the name of the method does not have the V2 suffix, but the type does - */ - void(ORT_API_CALL* ReleaseTensorRTProviderOptions)(_Frees_ptr_opt_ OrtTensorRTProviderOptionsV2* input); - - /// @} - /// \name OrtSessionOptions - /// @{ - - /** \brief Enable custom operators - * - * See onnxruntime-extensions: https://github.com/microsoft/onnxruntime-extensions.git - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(EnableOrtCustomOps, _Inout_ OrtSessionOptions* options); - - /// @} - /// \name OrtAllocator - /// @{ - - /** \brief Register a custom allocator - * - * Enables sharing between multiple sessions that use the same env instance. - * Returns an error if an allocator with the same ::OrtMemoryInfo is already registered. - * - * The behavior of this is exactly the same as OrtApi::CreateAndRegisterAllocator except - * instead of ORT creating an allocator based on provided info, in this case - * ORT uses the user-provided custom allocator. - * See https://onnxruntime.ai/docs/reference/api/c-api.html for details. - * - * \param[in] env - * \param[in] allocator User provided allocator - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(RegisterAllocator, _Inout_ OrtEnv* env, _In_ OrtAllocator* allocator); - - /** \brief Unregister a custom allocator - * - * It is an error if you provide an ::OrtMemoryInfo not corresponding to any - * registered allocators for sharing. - * - * \param[in] env - * \param[in] mem_info - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(UnregisterAllocator, _Inout_ OrtEnv* env, - _In_ const OrtMemoryInfo* mem_info); - - /// @} - /// \name OrtValue - /// @{ - - /** \brief Sets *out to 1 iff an ::OrtValue is a SparseTensor, and 0 otherwise - * - * \param[in] value existing ::OrtValue - * \param[out] out unless an error occurs, contains 1 iff the value contains an instance - * of sparse tensor or 0 otherwise. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(IsSparseTensor, _In_ const OrtValue* value, _Out_ int* out); - - /** \brief Create an ::OrtValue with a sparse tensor that is empty. - * - * Use FillSparseTensor() functions to populate sparse tensor with non-zero values and - * format specific indices data. - * Use ReleaseValue to destroy the sparse tensor, this will also release the buffer inside the output value - * if any was allocated. - * \param[in,out] allocator allocator to use when performing an allocation. Allocation will be performed - * by FillSparseTensor() APIs. The lifespan of the allocator instance must eclipse the lifespan - * this sparse tensor instance as the same allocator will be used to free memory. - * \param[in] dense_shape shape of the original dense tensor - * \param[in] dense_shape_len number of shape dimensions being passed - * \param[in] type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx - * \param[out] out Should be freed by calling ReleaseValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateSparseTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* dense_shape, - size_t dense_shape_len, ONNXTensorElementDataType type, _Outptr_ OrtValue** out); - - /** - * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue. - * This will allocate required memory and copy the supplied NNZ values and COO indices into that memory allocation. - * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue. - * - * \param[in,out] ort_value ::OrtValue to populate with data - * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified - * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed. - * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer. - * \param[in] values_shape pointer to values shape array - * \param[in] values_shape_len length of the values_shape - * \param[in] values pointer to an array of values. For strings, pass const char**. - * \param[in] indices_data pointer to a location of COO indices - * \param[in] indices_num number of COO indices - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(FillSparseTensorCoo, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info, - _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values, - _In_ const int64_t* indices_data, size_t indices_num); - - /** - * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue. - * This will allocate required memory and copy the supplied NNZ values and CSR indices into that memory allocation. - * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue. - * - * \param[in,out] ort_value ::OrtValue to populate with data - * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified - * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed. - * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer. - * \param[in] values_shape pointer to values shape array - * \param[in] values_shape_len length of the values_shape - * \param[in] values - pointer to an array of values. For strings, pass const char**. - * \param[in] inner_indices_data pointer to a location of CSR inner indices - * \param[in] inner_indices_num number of CSR inner indices - * \param[in] outer_indices_data pointer to a location of CSR outer indices - * \param[in] outer_indices_num number of CSR outer indices - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(FillSparseTensorCsr, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info, - _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values, - _In_ const int64_t* inner_indices_data, size_t inner_indices_num, - _In_ const int64_t* outer_indices_data, size_t outer_indices_num); - - /** - * This fills populates an empty tensor that was created using OrtApi::CreateSparseTensorAsOrtValue. - * This will allocate required memory and copy the supplied NNZ values and BlockSparse indices into that memory allocation. - * Memory allocation is performed using the allocator that was specified with OrtApi::CreateSparseTensorAsOrtValue. - * - * \param[in,out] ort_value ::OrtValue to populate with data - * \param[in] data_mem_info serves to identify the location of the data to be copied. If the allocator specified - * at the creation time has memory info that is not the same as mem_info argument to this function a X-device copy will be performed. - * String data is assumed to be on CPU and will only be copied into a CPU allocated buffer. - * \param[in] values_shape - * \param[in] values_shape_len - * \param[in] values structure with values information - * \param[in] indices_shape_data pointer to a location of indices shape - * \param[in] indices_shape_len length of the block sparse indices shape - * \param[in] indices_data pointer to a location of indices data. Shape will determine the length of the indices data. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(FillSparseTensorBlockSparse, _Inout_ OrtValue* ort_value, _In_ const OrtMemoryInfo* data_mem_info, - _In_ const int64_t* values_shape, size_t values_shape_len, _In_ const void* values, - _In_ const int64_t* indices_shape_data, size_t indices_shape_len, - _In_ const int32_t* indices_data); - - /** - * Create an ::OrtValue with a sparse tensor. This is the first step. - * Next, use UseIndices() functions to supply sparse tensor with - * format specific indices data and set its sparse format to a specific enum value. - * This will not perform memory allocations. It will - * use supplied user buffer which should outlive the created sparse tensor. - * Use OrtApi::ReleaseValue to destroy the sparse tensor. It would not release the supplied values buffer. - * This function can not be used to map strings from the user allocated memory. Strings must always be copied - * and have UTF-8 encoding. Therefore, use OrtApi::CreateSparseTensorAsOrtValue above and then fill it with data - * using appropriate Make*() function. - * - * \param[in] info memory info where sparse values reside. - * \param[in,out] p_data pointer to a user allocated buffer with values. To create a full sparse tensor with no non-zero - * values, pass nullptr - * \param[in] dense_shape shape of the original dense tensor - * \param[in] dense_shape_len number of shape dimensions being passed - * \param[in] values_shape shape of the values data. To create a fully sparse tensor with no non-zero values, - * pass {0} shape. - * \param[in] values_shape_len number of values shape dimensions - * \param[in] type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx - * \param[out] out Should be freed by calling ReleaseValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(CreateSparseTensorWithValuesAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data, - _In_ const int64_t* dense_shape, size_t dense_shape_len, - _In_ const int64_t* values_shape, size_t values_shape_len, - ONNXTensorElementDataType type, _Outptr_ OrtValue** out); - - /** - * This assigns Coo format indices to the SparseTensor that was created by - * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to - * ORT_SPARSE_COO. This will not allocate any additional memory for data. The life span of - * indices_data buffer should eclipse the life span of this ::OrtValue. - * - * \param[in,out] ort_value ::OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue - * \param[in,out] indices_data pointer to a user pre-allocated buffer or nullptr for fully sparse tensors. - * \param[in] indices_num number of COO indices. Should either be 0 for fully sparse tensors, be equal - * to the number of nnz values specified to OrtApi::CreateSparseTensorWithValuesAsOrtValue for 1-D {nnz} indices or - * be twice as number of nnz values for a 2-D indices {nnz, 2} - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(UseCooIndices, _Inout_ OrtValue* ort_value, _Inout_ int64_t* indices_data, size_t indices_num); - - /** - * The assigns CSR format indices to the SparseTensor that was created by - * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to - * ORT_SPARSE_CSRC. This will not allocate any additional memory for data. The life spans of - * inner_data and outer_data buffers should eclipse the life span of this ::OrtValue. - * - * \param[in,out] ort_value ::OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue - * \param[in,out] inner_data pointer to a user pre-allocated buffer or nullptr for fully sparse tensors. - * \param[in] inner_num number of inner CSR indices. Should either be 0 for fully sparse tensors or be equal - * to the number of nnz values specified to OrtApi::CreateSparseTensorWithValuesAsOrtValue. - * \param[in,out] outer_data pointer to user pre-allocated buffer or nullptr for fully sparse tensors. - * \param[in] outer_num number of CSR outer indices. Should either be 0 for fully sparse tensors or - * equal to rows + 1 of the dense shape. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(UseCsrIndices, _Inout_ OrtValue* ort_value, _Inout_ int64_t* inner_data, size_t inner_num, - _Inout_ int64_t* outer_data, size_t outer_num); - - /** - * The assigns BlockSparse format indices to the SparseTensor that was created by - * OrtApi::CreateSparseTensorWithValuesAsOrtValue above. It also sets OrtSparseFormat to - * ORT_SPARSE_BLOCK_SPARSE. This will not allocate any additional memory for data. The life span of - * indices_data buffer must eclipse the lifespan of this ::OrtValue. - * - * \param[in,out] ort_value OrtValue instance constructed with OrtApi::CreateSparseTensorWithValuesAsOrtValue - * \param[in] indices_shape pointer to indices shape. Use {0} for fully sparse tensors - * \param[in] indices_shape_len length of the indices shape - * \param[in,out] indices_data pointer to user pre-allocated buffer or nullptr for fully sparse tensors. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(UseBlockSparseIndices, _Inout_ OrtValue* ort_value, const int64_t* indices_shape, size_t indices_shape_len, _Inout_ int32_t* indices_data); - - /** \brief Returns sparse tensor format enum iff a given ort value contains an instance of sparse tensor. - * - * \param[in] ort_value ::OrtValue that contains an instance of sparse tensor - * \param[out] out pointer to out parameter - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetSparseTensorFormat, _In_ const OrtValue* ort_value, _Out_ enum OrtSparseFormat* out); - - /** \brief Returns data type and shape of sparse tensor values (nnz) iff ::OrtValue contains a SparseTensor. - * - * \param[in] ort_value An ::OrtValue that contains a fully constructed sparse tensor - * \param[out] out Must be freed by OrtApi::ReleaseTensorTypeAndShapeInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetSparseTensorValuesTypeAndShape, _In_ const OrtValue* ort_value, _Outptr_ OrtTensorTypeAndShapeInfo** out); - - /** \brief Returns numeric data for sparse tensor values (nnz). For string values use GetStringTensor*(). - * - * \param[in] ort_value an instance of ::OrtValue containing sparse tensor - * \param[out] out returns a pointer to values data. Do not attempt to free this ptr. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetSparseTensorValues, _In_ const OrtValue* ort_value, _Outptr_ const void** out); - - /** \brief Returns data type, shape for the type of indices specified by indices_format. - * - * \param[in] ort_value ::OrtValue containing sparse tensor. - * \param[in] indices_format One of the indices formats. It is an error to request a format that the sparse - * tensor does not contain. - * \param[out] out an instance of ::OrtTensorTypeAndShapeInfo. Must be freed by OrtApi::ReleaseTensorTypeAndShapeInfo - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetSparseTensorIndicesTypeShape, _In_ const OrtValue* ort_value, enum OrtSparseIndicesFormat indices_format, _Outptr_ OrtTensorTypeAndShapeInfo** out); - - /** \brief Returns indices data for the type of the indices specified by indices_format - * - * \param[in] ort_value ::OrtValue containing sparse tensor. - * \param[in] indices_format One of the indices formats. It is an error to request a format that the sparse tensor does not contain. - * \param[out] num_indices Pointer to where the number of indices entries is returned - * \param[out] indices Returned pointer to the indices data. Do not free the returned pointer as it refers to internal data owned by the ::OrtValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetSparseTensorIndices, _In_ const OrtValue* ort_value, enum OrtSparseIndicesFormat indices_format, _Out_ size_t* num_indices, _Outptr_ const void** indices); - /// @} - /// \name OrtSessionOptions - /// @{ - - /** - * \brief Sets out to 1 iff an optional type OrtValue has an element, 0 otherwise (OrtValue is None) - * Use this API to find if the optional type OrtValue is None or not. - * If the optional type OrtValue is not None, use the OrtValue just like any other OrtValue. - * For example, if you get an OrtValue that corresponds to Optional(tensor) and - * if HasValue() returns true, use it as tensor and so on. - - * \param[in] value Input OrtValue. - * \param[out] out indicating if the input OrtValue contains data (1) or if it is a None (0) - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(HasValue, _In_ const OrtValue* value, _Out_ int* out); - - /// @} - /// \name OrtKernelContext - /// Custom operator APIs. - /// @{ - - /** \brief Used for custom operators, gets the GPU compute stream to use to launch the custom a GPU kernel - * \see ::OrtCustomOp - * \param[in] context OrtKernelContext instance - * \param[out] out Returns pointer to a GPU compute stream that can be used to launch the custom GPU kernel. - * If retrieving the GPU compute stream is not relevant (GPU not enabled in the build, kernel partitioned to - * some other EP), then a nullptr is returned as the output param. - * Do not free or mutate the returned pointer as it refers to internal data owned by the underlying session. - * Only use it for custom kernel launching. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(KernelContext_GetGPUComputeStream, _In_ const OrtKernelContext* context, _Outptr_ void** out); - - /// @} - /// \name GetTensorMemoryInfo - /// @{ - /** \brief Returns a pointer to the ::OrtMemoryInfo of a Tensor - * \param[in] value ::OrtValue containing tensor. - * \param[out] mem_info ::OrtMemoryInfo of the tensor. Do NOT free the returned pointer. It is valid for the lifetime of the ::OrtValue - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetTensorMemoryInfo, _In_ const OrtValue* value, _Out_ const OrtMemoryInfo** mem_info); - - /// @} - /// \name GetExecutionProviderApi - /// @{ - /** \brief Get a pointer to the requested version of the Execution Provider specific - * API extensions to the OrtApi - * \param[in] provider_name The name of the execution provider name. Currently only the following - * values are supported: "DML". - * \param[in] version Must be ::ORT_API_VERSION. - * \param[out] provider_api A void pointer containing a reference to the execution provider versioned api structure. - * For example, the provider_api pointer can be cast to the OrtDmlApi* when the provider_name is "DML". - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(GetExecutionProviderApi, _In_ const char* provider_name, _In_ uint32_t version, _Outptr_ const void** provider_api); - - /// @} - - /// \name SessionOptions - /// @{ - /** \brief Set custom thread creation function - * - * \param[in] options Session options - * \param[in] ort_custom_create_thread_fn Custom thread creation function - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionOptionsSetCustomCreateThreadFn, _Inout_ OrtSessionOptions* options, _In_ OrtCustomCreateThreadFn ort_custom_create_thread_fn); - - /** \brief Set creation options for custom thread - * - * \param[in] options Session options - * \param[in] ort_custom_thread_creation_options Custom thread creation options (can be nullptr) - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionOptionsSetCustomThreadCreationOptions, _Inout_ OrtSessionOptions* options, _In_ void* ort_custom_thread_creation_options); - - /** \brief Set custom thread join function - * - * \param[in] options Session options - * \param[in] ort_custom_join_thread_fn Custom join thread function, must not be nullptr when ort_custom_create_thread_fn is set - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SessionOptionsSetCustomJoinThreadFn, _Inout_ OrtSessionOptions* options, _In_ OrtCustomJoinThreadFn ort_custom_join_thread_fn); - /// @} - - /// \name OrtThreadingOptions - /// @{ - /** \brief Set custom thread creation function for global thread pools - * - * \param[inout] tp_options - * \param[in] ort_custom_create_thread_fn Custom thread creation function - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetGlobalCustomCreateThreadFn, _Inout_ OrtThreadingOptions* tp_options, _In_ OrtCustomCreateThreadFn ort_custom_create_thread_fn); - - /** \brief Set custom thread creation options for global thread pools - * - * \param[inout] tp_options - * \param[in] ort_custom_thread_creation_options Custom thread creation options (can be nullptr) - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetGlobalCustomThreadCreationOptions, _Inout_ OrtThreadingOptions* tp_options, _In_ void* ort_custom_thread_creation_options); - - /** \brief Set custom thread join function for global thread pools - * - * \param[inout] tp_options - * \param[in] ort_custom_join_thread_fn Custom thread join function, must not be nullptr when global ort_custom_create_thread_fn is set - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SetGlobalCustomJoinThreadFn, _Inout_ OrtThreadingOptions* tp_options, _In_ OrtCustomJoinThreadFn ort_custom_join_thread_fn); - /// @} - - /** \brief Synchronize bound inputs. The call may be necessary for some providers, such as cuda, - * in case the system that allocated bound memory operated on a different stream. However, the - * operation is provider specific and could be a no-op. - * - * \param[inout] binding_ptr - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SynchronizeBoundInputs, _Inout_ OrtIoBinding* binding_ptr); - - /** \brief Synchronize bound outputs. The call may be necessary for some providers, such as cuda, - * in case the system that allocated bound memory operated on a different stream. However, the - * operation is provider specific and could be a no-op. - * - * \param[inout] binding_ptr - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(SynchronizeBoundOutputs, _Inout_ OrtIoBinding* binding_ptr); - - /// \name OrtSessionOptions - /// @{ - - /** \brief Append CUDA execution provider to the session options - * - * If CUDA is not available (due to a non CUDA enabled build), this function will return failure. - * - * This is slightly different from OrtApi::SessionOptionsAppendExecutionProvider_CUDA, it takes an - * ::OrtCUDAProviderOptions which is publicly defined. This takes an opaque ::OrtCUDAProviderOptionsV2 - * which must be created with OrtApi::CreateCUDAProviderOptions. - * - * For OrtApi::SessionOptionsAppendExecutionProvider_CUDA, the user needs to instantiate ::OrtCUDAProviderOptions - * as well as allocate/release buffers for some members of ::OrtCUDAProviderOptions. - * Here, OrtApi::CreateCUDAProviderOptions and Ortapi::ReleaseCUDAProviderOptions will do the memory management for you. - * - * \param[in] options - * \param[in] cuda_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.11. - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA_V2, - _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptionsV2* cuda_options); - - /// @} - /// \name OrtCUDAProviderOptionsV2 - /// @{ - - /** \brief Create an OrtCUDAProviderOptionsV2 - * - * \param[out] out Newly created ::OrtCUDAProviderOptionsV2. Must be released with OrtApi::ReleaseCudaProviderOptions - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.11. - */ - ORT_API2_STATUS(CreateCUDAProviderOptions, _Outptr_ OrtCUDAProviderOptionsV2** out); - - /** \brief Set options in a CUDA Execution Provider. - * - * Please refer to https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#configuration-options - * to know the available keys and values. Key should be in null terminated string format of the member of ::OrtCUDAProviderOptionsV2 - * and value should be its related range. - * - * For example, key="device_id" and value="0" - * - * \param[in] cuda_options - * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys - * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values - * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.11. - */ - ORT_API2_STATUS(UpdateCUDAProviderOptions, _Inout_ OrtCUDAProviderOptionsV2* cuda_options, - _In_reads_(num_keys) const char* const* provider_options_keys, - _In_reads_(num_keys) const char* const* provider_options_values, - _In_ size_t num_keys); - - /** - * Get serialized CUDA provider options string. - * - * For example, "device_id=0;arena_extend_strategy=0;......" - * - * \param cuda_options - OrtCUDAProviderOptionsV2 instance - * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions() - * the specified allocator will be used to allocate continuous buffers for output strings and lengths. - * \param ptr - is a UTF-8 null terminated string allocated using 'allocator'. The caller is responsible for using the same allocator to free it. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.11. - */ - ORT_API2_STATUS(GetCUDAProviderOptionsAsString, _In_ const OrtCUDAProviderOptionsV2* cuda_options, _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr); - - /** \brief Release an ::OrtCUDAProviderOptionsV2 - * - * \note This is an exception in the naming convention of other Release* functions, as the name of the method does not have the V2 suffix, but the type does - * - * \since Version 1.11. - */ - void(ORT_API_CALL* ReleaseCUDAProviderOptions)(_Frees_ptr_opt_ OrtCUDAProviderOptionsV2* input); - - /// @} - - /** \brief Append MIGraphX provider to session options - * - * If MIGraphX is not available (due to a non MIGraphX enabled build, or if MIGraphX is not installed on the system), this function will return failure. - * - * \param[in] options - * \param[in] migraphx_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.11. - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_MIGraphX, - _In_ OrtSessionOptions* options, _In_ const OrtMIGraphXProviderOptions* migraphx_options); - - /** \brief Replace initialized Tensors with external data with the data provided in initializers. - * - * The function will find the initialized TensorProtos with external data in the graph with the provided names and - * replace them with the provided tensors. The API verifies that the TensorProto being replaced - * has an external data reference and has the same name, dimensions and data type as its replacement. The replacement - * will occur before any of the optimizations take place. The data will be copied into the graph - * since TensorProto can't refer to the user provided buffers. - * - * Once the model has been loaded, the OrtValue(s) added to SessionOptions instance will be removed - * from the internal SessionOptions copy to save memory, the user provided buffers can then be deallocated - * and the SessionOptions instance that refers to them can be destroyed. - * - * \param[in] options - * \param[in] initializer_names Array of null terminated UTF-8 encoded strings of the initializers names. - * \param[in] initializers Array of ::OrtValue type - * \param[in] initializers_num Number of elements in the initializer_names and initializers - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.12. - */ - ORT_API2_STATUS(AddExternalInitializers, _In_ OrtSessionOptions* options, - _In_reads_(input_len) const char* const* initializer_names, - _In_reads_(input_len) const OrtValue* const* initializers, size_t initializers_num); - - /** \brief: Create attribute of onnxruntime operator - * - * \param[in] name Name of the attribute - * \param[in] data Data content of the attribute - * \param[in] len Number of bytes stored in data - * \param[in] type Data type - * \param[out] op_attr Attribute that has been created, which must be released by OrtApi::ReleaseOpAttr - * - * \since Version 1.12. - */ - ORT_API2_STATUS(CreateOpAttr, - _In_ const char* name, - _In_ const void* data, - _In_ int len, - _In_ OrtOpAttrType type, - _Outptr_ OrtOpAttr** op_attr); - - /* \brief: Release op attribute - * - * \param[in] opAttr Attribute created by OrtApi::CreateOpAttr - * - * \since Version 1.12. - */ - ORT_CLASS_RELEASE(OpAttr); - - /** \brief: Create onnxruntime native operator - * - * \param[in] info Kernel info - * \param[in] op_name Operator name - * \param[in] domain Operator domain - * \param[in] version Operator opset version - * \param[in] type_constraint_names Name of the type contraints, such as "T" or "T1" - * \param[in] type_constraint_values Type of each contraints - * \param[in] type_constraint_count Number of contraints - * \param[in] attr_values Attributes used to initialize the operator - * \param[in] attr_count Number of the attributes - * \param[in] input_count Number of inputs - * \param[in] output_count Number of outputs - * \param[out] ort_op Operator that has been created - * - * \since Version 1.12. - */ - ORT_API2_STATUS(CreateOp, - _In_ const OrtKernelInfo* info, - _In_ const char* op_name, - _In_ const char* domain, - _In_ int version, - _In_opt_ const char** type_constraint_names, - _In_opt_ const ONNXTensorElementDataType* type_constraint_values, - _In_opt_ int type_constraint_count, - _In_opt_ const OrtOpAttr* const* attr_values, - _In_opt_ int attr_count, - _In_ int input_count, - _In_ int output_count, - _Outptr_ OrtOp** ort_op); - - /** \brief: Invoke the operator created by OrtApi::CreateOp - * The inputs must follow the order as specified in onnx specification - * - * \param[in] context Kernel context - * \param[in] ort_op Operator that has been created - * \param[in] input_values Array of inputs - * \param[in] input_count Number of inputs - * \param[in] output_values Array of outputs - * \param[in] output_count Number of outputs - * - * \since Version 1.12. - */ - ORT_API2_STATUS(InvokeOp, - _In_ const OrtKernelContext* context, - _In_ const OrtOp* ort_op, - _In_ const OrtValue* const* input_values, - _In_ int input_count, - _Inout_ OrtValue* const* output_values, - _In_ int output_count); - - /* \brief: Release an onnxruntime operator - * - * \param[in] Op Operator created by OrtApi::CreateOp - * - * \since Version 1.12. - */ - ORT_CLASS_RELEASE(Op); - - /** \brief: Append execution provider to the session options. - * \param[in] options - * \param[in] provider_name - provider to add. - * \param[in] provider_options_keys - keys to configure the provider options - * \param[in] provider_options_values - values to configure the provider options - * \param[in] num_keys - number of keys passed in - * - * Currently supported providers: - * SNPE - * XNNPACK - * - * Note: If an execution provider has a dedicated SessionOptionsAppendExecutionProvider_ function - * that should be used to add it. - * - * SNPE supported keys: - * "runtime": SNPE runtime engine, options: "CPU", "CPU_FLOAT32", "GPU", "GPU_FLOAT32_16_HYBRID", "GPU_FLOAT16", - * "DSP", "DSP_FIXED8_TF", "AIP_FIXED_TF", "AIP_FIXED8_TF". - * Mapping to SNPE Runtime_t definition: CPU, CPU_FLOAT32 => zdl::DlSystem::Runtime_t::CPU; - * GPU, GPU_FLOAT32_16_HYBRID => zdl::DlSystem::Runtime_t::GPU; - * GPU_FLOAT16 => zdl::DlSystem::Runtime_t::GPU_FLOAT16; - * DSP, DSP_FIXED8_TF => zdl::DlSystem::Runtime_t::DSP. - * AIP_FIXED_TF, AIP_FIXED8_TF => zdl::DlSystem::Runtime_t::AIP_FIXED_TF. - * "priority": execution priority, options: "low", "normal". - * "buffer_type": ITensor or user buffers, options: "ITENSOR", user buffer with different types - "TF8", "TF16", "UINT8", "FLOAT". - * "ITENSOR" -- default, ITensor which is float only. - * "TF8" -- quantized model required, "FLOAT" -- for both quantized or non-quantized model - * If SNPE is not available (due to a non Snpe enabled build or its dependencies not being installed), this function will fail. - * - * XNNPACK supported keys: - * "intra_op_num_threads": number of thread-pool size to use for XNNPACK execution provider. - * default value is 0, which means to use the session thread-pool size. - * - * \since Version 1.12. - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider, _In_ OrtSessionOptions* options, - _In_ const char* provider_name, - _In_reads_(num_keys) const char* const* provider_options_keys, - _In_reads_(num_keys) const char* const* provider_options_values, - _In_ size_t num_keys); - - /* \brief: Get a copy of kernel info - * - * \param[in] info Kernel info - * \param[out] info_copy Copy of kernel info - * - * \since Version 1.12. - */ - ORT_API2_STATUS(CopyKernelInfo, - _In_ const OrtKernelInfo* info, - _Outptr_ OrtKernelInfo** info_copy); - - /* \brief: Release kernel info - * - * \param[in] KernelInfo A copy of kernel info returned by CopyKernelInfo - * - * \since Version 1.12. - */ - ORT_CLASS_RELEASE(KernelInfo); - - /* \brief: Get the training C Api - * - * \since Version 1.13 - */ - const OrtTrainingApi*(ORT_API_CALL* GetTrainingApi)(uint32_t version)NO_EXCEPTION; - - /** \brief Append CANN provider to session options - * - * If CANN is not available (due to a non CANN enabled build, or if CANN is not installed on the system), this function will return failure. - * - * \param[in] options - * \param[in] cann_options - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.13. - */ - ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CANN, - _In_ OrtSessionOptions* options, _In_ const OrtCANNProviderOptions* cann_options); - - /** \brief Create an OrtCANNProviderOptions - * - * \param[out] out created ::OrtCANNProviderOptions. Must be released with OrtApi::ReleaseCANNProviderOptions - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.13. - */ - ORT_API2_STATUS(CreateCANNProviderOptions, _Outptr_ OrtCANNProviderOptions** out); - - /** \brief Set options in a CANN Execution Provider. - * - * \param[in] cann_options - * \param[in] provider_options_keys Array of UTF-8 null-terminated string for provider options keys - * \param[in] provider_options_values Array of UTF-8 null-terminated string for provider options values - * \param[in] num_keys Number of elements in the `provider_option_keys` and `provider_options_values` arrays - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.13. - */ - ORT_API2_STATUS(UpdateCANNProviderOptions, _Inout_ OrtCANNProviderOptions* cann_options, - _In_reads_(num_keys) const char* const* provider_options_keys, - _In_reads_(num_keys) const char* const* provider_options_values, - _In_ size_t num_keys); - - /** \brief Get serialized CANN provider options string. - * - * \param[in] cann_options OrtCANNProviderOptions instance - * \param[in] allocator a ptr to an instance of OrtAllocator obtained with CreateAllocator() - * or GetAllocatorWithDefaultOptions(), the specified allocator will be used to allocate - * continuous buffers for output strings and lengths. - * \param[out] ptr is a UTF-8 null terminated string allocated using 'allocator'. - * The caller is responsible for using the same allocator to free it. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * - * \since Version 1.13. - */ - ORT_API2_STATUS(GetCANNProviderOptionsAsString, _In_ const OrtCANNProviderOptions* cann_options, - _Inout_ OrtAllocator* allocator, _Outptr_ char** ptr); - - /** \brief Release an OrtCANNProviderOptions - * - * \param[in] the pointer of OrtCANNProviderOptions which will been deleted - * - * \since Version 1.13. - */ - void(ORT_API_CALL* ReleaseCANNProviderOptions)(_Frees_ptr_opt_ OrtCANNProviderOptions* input); - - /* \brief Get OrtDevice type from MemoryInfo - * - * \since Version 1.14 - */ - void(ORT_API_CALL* MemoryInfoGetDeviceType)(_In_ const OrtMemoryInfo* ptr, _Out_ OrtMemoryInfoDeviceType* out); - - /* \brief Update the OrtEnv instance with custom log severity level - * - * \param[in] ort_env The OrtEnv instance being used - * \param[in] log_severity_level The log severity level. - * - * \since Version 1.14. - */ - ORT_API2_STATUS(UpdateEnvWithCustomLogLevel, _In_ OrtEnv* ort_env, OrtLoggingLevel log_severity_level); - - /* \brief Set affinities for intra op threads - * - * Affinity string follows format: - * logical_processor_id,logical_processor_id;logical_processor_id,logical_processor_id - * Semicolon isolates configurations among threads, while comma split processors where ith thread expected to attach to. - * e.g. 1,2,3;4,5 - * specifies affinities for two threads, with the 1st thread attach to the 1st, 2nd, and 3rd processor, and 2nd thread to the 4th and 5th. - * To ease the configuration, an "interval" is also allowed: - * e.g. 1-8;8-16;17-24 - * orders that the 1st thread runs on first eight processors, 2nd thread runs on next eight processors, and so forth. - * Note: - * 1. Once set, the number of thread affinities must equal to intra_op_num_threads - 1, - * ort does not set affinity on the main thread which is started and managed by the calling app; - * 2. For windows, ort will infer the group id from a logical processor id, for example, assuming there are two groups with each has 64 logical processors, - * an id of 64 will be inferred as the last processor of the 1st group, while 65 will be interpreted as the 1st processor of the second group. - * Hence 64-65 is an invalid configuration, because a windows thread cannot be attached to processors across group boundary. - * - * \since Version 1.14 - */ - ORT_API2_STATUS(SetGlobalIntraOpThreadAffinity, _Inout_ OrtThreadingOptions* tp_options, const char* affinity_string); - - /** \brief Register custom ops from a shared library. - * - * Loads a shared library (.dll on windows, .so on linux, etc) named 'library_name' and looks for this entry point: - * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api); - * It then passes in the provided session options to this function along with the api base. - * - * The handle to the loaded library is automatically released by ORT when the last OrtSession that references the - * library handle is released. If no OrtSession is created, then the library handle is released when the provided - * OrtSessionOptions is released. - * - * \param[in] options The session options. - * \param[in] library_name The name of the shared library to load and register. Refer to OS-specific dynamic library - * loading utilities (e.g., LoadLibraryEx on Windows or dlopen on Linux/MacOS) for information - * on the format of library names and search paths. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(RegisterCustomOpsLibrary_V2, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* library_name); - - /** \brief Register custom ops by calling a RegisterCustomOpsFn function. - * - * Searches for registration_func_name and if found calls it. - * - * The library containing the function must either be linked against or previously loaded by the executable. - * - * If you want ONNX Runtime to load the library and manage its lifetime, use RegisterCustomOpsLibrary_V2. - * - * RegisterCustomOpsUsingFunction can be used in scenarios where it may not be possible for ONNX Runtime to load - * the library from a path. e.g. mobile platforms where the library must be linked into the app. - * - * The registration function must have the signature of RegisterCustomOpsFn: - * OrtStatus* (*fn)(OrtSessionOptions* options, const OrtApiBase* api); - * - * See https://onnxruntime.ai/docs/reference/operators/add-custom-op.html for details on how the registration - * function should be implemented. - * - * \param[in] options OrtSessionOptions that is passed through as the first argument in the call to the - * registration function. - * \param[in] registration_func_name Name of registration function to use. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(RegisterCustomOpsUsingFunction, _Inout_ OrtSessionOptions* options, - _In_ const char* registration_func_name); - - /// @} - /// \name OrtKernelInfo - /// Custom operator APIs. - /// @{ - - /** \brief Get the number of inputs from ::OrtKernelInfo. - * - * Used in the CreateKernel callback of an OrtCustomOp to query the number of inputs - * during kernel/session creation. - * - * \param[in] info Instance of ::OrtKernelInfo. - * \param[out] out Pointer to variable assigned with the result on success. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(KernelInfo_GetInputCount, _In_ const OrtKernelInfo* info, _Out_ size_t* out); - - /** \brief Get the number of outputs from ::OrtKernelInfo. - * - * Used in the CreateKernel callback of an OrtCustomOp to query the number of outputs - * during kernel/session creation. - * - * \param[in] info Instance of ::OrtKernelInfo. - * \param[out] out Pointer to variable assigned with the result on success. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(KernelInfo_GetOutputCount, _In_ const OrtKernelInfo* info, _Out_ size_t* out); - - /** \brief Get the name of a ::OrtKernelInfo's input. - * - * Used in the CreateKernel callback of an OrtCustomOp to query an input's name - * during kernel/session creation. - * - * If `out` is nullptr, the value of `size` is set to the size of the name - * string (including null-terminator), and a success status is returned. - * - * If the `size` parameter is greater than or equal to the name string's size, - * the value of `size` is set to the true size of the string (including null-terminator), - * the provided memory is filled with the string's contents, and a success status is returned. - * - * If the `size` parameter is less than the actual string's size and `out` - * is not nullptr, the value of `size` is set to the true size of the string - * and a failure status is returned. - * - * \param[in] info An instance of ::OrtKernelInfo. - * \param[in] index The index of the input name to get. Returns a failure status if out-of-bounds. - * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the input's name. - * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(KernelInfo_GetInputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out, - _Inout_ size_t* size); - - /** \brief Get the name of a ::OrtKernelInfo's output. - * - * Used in the CreateKernel callback of an OrtCustomOp to query an output's name - * during kernel/session creation. - * - * If `out` is nullptr, the value of `size` is set to the size of the name - * string (including null-terminator), and a success status is returned. - * - * If the `size` parameter is greater than or equal to the name string's size, - * the value of `size` is set to the true size of the string (including null-terminator), - * the provided memory is filled with the string's contents, and a success status is returned. - * - * If the `size` parameter is less than the actual string's size and `out` - * is not nullptr, the value of `size` is set to the true size of the string - * and a failure status is returned. - * - * \param[in] info An instance of ::OrtKernelInfo. - * \param[in] index The index of the output name to get. Returns a failure status if out-of-bounds. - * \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the output's - * name. - * \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(KernelInfo_GetOutputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out, - _Inout_ size_t* size); - - /** \brief Get the type information for a ::OrtKernelInfo's input. - * - * Used in the CreateKernel callback of an OrtCustomOp to query the shape and type information - * of an input during kernel/session creation. - * - * \param[in] info An instance of ::OrtKernelInfo. - * \param[out] type_info Pointer set to the resulting ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(KernelInfo_GetInputTypeInfo, _In_ const OrtKernelInfo* info, size_t index, - _Outptr_ OrtTypeInfo** type_info); - - /** \brief Get the type information for a ::OrtKernelInfo's output. - * - * Used in the CreateKernel callback of an OrtCustomOp to query the shape and type information - * of an output during kernel/session creation. - * - * \param[in] info An instance of ::OrtKernelInfo. - * \param[out] type_info Pointer set to the resulting ::OrtTypeInfo. Must be freed with OrtApi::ReleaseTypeInfo. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(KernelInfo_GetOutputTypeInfo, _In_ const OrtKernelInfo* info, size_t index, - _Outptr_ OrtTypeInfo** type_info); - - /** \brief Get a ::OrtValue tensor stored as an attribute in the graph node. - * - * Used in the CreateKernel callback of an OrtCustomOp to get a tensor attribute. - * - * \param[in] info ::OrtKernelInfo instance. - * \param[in] name UTF-8 null-terminated string representing the attribute's name. - * \param[in] allocator Allocator used to allocate the internal tensor state. - * \param[out] out Returns newly created ::OrtValue. Must be freed with OrtApi::ReleaseValue, - * which will also free internal tensor state allocated with the provided allocator. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - */ - ORT_API2_STATUS(KernelInfoGetAttribute_tensor, _In_ const OrtKernelInfo* info, _In_z_ const char* name, - _Inout_ OrtAllocator* allocator, _Outptr_ OrtValue** out); - - /// @} - /// \name OrtSessionOptions - /// Custom operator APIs - /// @{ - - /** \brief Checks if the given session configuration entry exists. - * - * The config_key formats are defined in onnxruntime_session_options_config_keys.h - * - * Can be used in a custom operator library to check for session configuration entries - * that target one or more custom operators in the library. Example: The config entry - * custom_op.myop.some_key targets a custom op named "myop". - * - * \param[in] options The ::OrtSessionOptions instance. - * \param[in] config_key A null-terminated UTF-8 string representation of the configuration key. - * \param[out] out Pointer set to 1 if the entry exists and 0 otherwise. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(HasSessionConfigEntry, _In_ const OrtSessionOptions* options, - _In_z_ const char* config_key, _Out_ int* out); - - /** \brief Get a session configuration value. - * - * Returns a failure status if the configuration key does not exist. - * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h - * - * If `config_value` is nullptr, the value of `size` is set to the true size of the string - * value (including null-terminator), and a success status is returned. - * - * If the `size` parameter is greater than or equal to the actual string value's size, - * the value of `size` is set to the true size of the string value, the provided memory - * is filled with the value's contents, and a success status is returned. - * - * If the `size` parameter is less than the actual string value's size and `config_value` - * is not nullptr, the value of `size` is set to the true size of the string value - * and a failure status is returned. - * - * Can be used in a custom operator library to get session configuration entries - * that target one or more custom operators in the library. Example: The config entry - * custom_op.myop.some_key targets a custom op named "myop". - * - * \param[in] options The session options. - * \param[in] config_key A null-terminated UTF-8 string representation of the config key. - * \param[in] config_value Pointer to memory where the null-terminated UTF-8 string value will be stored. - * \param[in,out] size Pointer to the size of the `config_value` buffer. See above comments for details. - * - * \snippet{doc} snippets.dox OrtStatus Return Value - * \since Version 1.14 - */ - ORT_API2_STATUS(GetSessionConfigEntry, _In_ const OrtSessionOptions* options, - _In_z_ const char* config_key, _Out_ char* config_value, _Inout_ size_t* size); - - /// @} - -#ifdef __cplusplus - OrtApi(const OrtApi&) = delete; // Prevent users from accidentally copying the API structure, it should always be passed as a pointer -#endif -}; - -/* - * Steps to use a custom op: - * 1 Create an OrtCustomOpDomain with the domain name used by the custom ops - * 2 Create an OrtCustomOp structure for each op and add them to the domain - * 3 Call OrtAddCustomOpDomain to add the custom domain of ops to the session options - */ - -// Specifies some characteristics of inputs/outputs of custom ops: -// Specify if the inputs/outputs are one of: -// 1) Non-optional (input/output must be present in the node) -// 2) Optional (input/output may be absent in the node) -// 3) Variadic: A variadic input or output specifies N (i.e., the minimum arity) or more operands. -// Only the last input or output of a custom op may be marked as variadic. -// The homogeneity of the variadic input or output determines whether all operands must be of the same -// tensor element type. -typedef enum OrtCustomOpInputOutputCharacteristic { - INPUT_OUTPUT_REQUIRED = 0, - INPUT_OUTPUT_OPTIONAL, - INPUT_OUTPUT_VARIADIC, -} OrtCustomOpInputOutputCharacteristic; - -/* - * The OrtCustomOp structure defines a custom op's schema and its kernel callbacks. The callbacks are filled in by - * the implementor of the custom op. - */ -struct OrtCustomOp { - uint32_t version; // Must be initialized to ORT_API_VERSION - - // This callback creates the kernel, which is a user defined parameter that is passed to the Kernel* callbacks below. - void*(ORT_API_CALL* CreateKernel)(_In_ const struct OrtCustomOp* op, _In_ const OrtApi* api, - _In_ const OrtKernelInfo* info); - - // Returns the name of the op - const char*(ORT_API_CALL* GetName)(_In_ const struct OrtCustomOp* op); - - // Returns the type of the execution provider, return nullptr to use CPU execution provider - const char*(ORT_API_CALL* GetExecutionProviderType)(_In_ const struct OrtCustomOp* op); - - // Returns the count and types of the input & output tensors - ONNXTensorElementDataType(ORT_API_CALL* GetInputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index); - size_t(ORT_API_CALL* GetInputTypeCount)(_In_ const struct OrtCustomOp* op); - ONNXTensorElementDataType(ORT_API_CALL* GetOutputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index); - size_t(ORT_API_CALL* GetOutputTypeCount)(_In_ const struct OrtCustomOp* op); - - // Op kernel callbacks - void(ORT_API_CALL* KernelCompute)(_In_ void* op_kernel, _In_ OrtKernelContext* context); - void(ORT_API_CALL* KernelDestroy)(_In_ void* op_kernel); - - // Returns the characteristics of the input & output tensors - OrtCustomOpInputOutputCharacteristic(ORT_API_CALL* GetInputCharacteristic)(_In_ const struct OrtCustomOp* op, _In_ size_t index); - OrtCustomOpInputOutputCharacteristic(ORT_API_CALL* GetOutputCharacteristic)(_In_ const struct OrtCustomOp* op, _In_ size_t index); - - // Returns the memory type of the input tensors. This API allows the custom op - // to place the inputs on specific devices. By default, it returns - // OrtMemTypeDefault, which means the input is placed on the default device for - // the execution provider. If the inputs need to be with different memory tyeps, - // this function can be overridden to return the specific memory types. - OrtMemType(ORT_API_CALL* GetInputMemoryType)(_In_ const struct OrtCustomOp* op, _In_ size_t index); - - // Returns the minimum number of input arguments expected for the variadic input. - // Applicable only for custom ops that have a variadic input. - int(ORT_API_CALL* GetVariadicInputMinArity)(_In_ const struct OrtCustomOp* op); - - // Returns true (non-zero) if all arguments of a variadic input have to be of the same type (homogeneous), - // and false (zero) otherwise. - // Applicable only for custom ops that have a variadic input. - int(ORT_API_CALL* GetVariadicInputHomogeneity)(_In_ const struct OrtCustomOp* op); - - // Returns the minimum number of output values expected for the variadic output. - // Applicable only for custom ops that have a variadic output. - int(ORT_API_CALL* GetVariadicOutputMinArity)(_In_ const struct OrtCustomOp* op); - - // Returns true (non-zero) if all outputs values of a variadic output have to be of the same type (homogeneous), - // and false (zero) otherwise. - // Applicable only for custom ops that have a variadic output. - int(ORT_API_CALL* GetVariadicOutputHomogeneity)(_In_ const struct OrtCustomOp* op); -}; - -/* - * This is the old way to add the CUDA provider to the session, please use SessionOptionsAppendExecutionProvider_CUDA above to access the latest functionality - * This function always exists, but will only succeed if Onnxruntime was built with CUDA support and the CUDA provider shared library exists - * - * \param device_id CUDA device id, starts from zero. - */ -ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CUDA, _In_ OrtSessionOptions* options, int device_id); - -/* - * This is the old way to add the MIGraphX provider to the session, please use - * SessionOptionsAppendExecutionProvider_MIGraphX above to access the latest functionality - * This function always exists, but will only succeed if Onnxruntime was built with - * HIP support and the MIGraphX provider shared library exists - * - * \param device_id HIP device id, starts from zero. - */ -ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_MIGraphX, _In_ OrtSessionOptions* options, int device_id); - -#ifdef __cplusplus -} -#endif - -//! @} diff --git a/lab/onnx/include/onnxruntime_cxx_api.h b/lab/onnx/include/onnxruntime_cxx_api.h deleted file mode 100644 index 97b2aa48..00000000 --- a/lab/onnx/include/onnxruntime_cxx_api.h +++ /dev/null @@ -1,1876 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// Summary: The Ort C++ API is a header only wrapper around the Ort C API. -// -// The C++ API simplifies usage by returning values directly instead of error codes, throwing exceptions on errors -// and automatically releasing resources in the destructors. The primary purpose of C++ API is exception safety so -// all the resources follow RAII and do not leak memory. -// -// Each of the C++ wrapper classes holds only a pointer to the C internal object. Treat them like smart pointers. -// To create an empty object, pass 'nullptr' to the constructor (for example, Env e{nullptr};). However, you can't use them -// until you assign an instance that actually holds an underlying object. -// -// For Ort objects only move assignment between objects is allowed, there are no copy constructors. -// Some objects have explicit 'Clone' methods for this purpose. -// -// ConstXXXX types are copyable since they do not own the underlying C object, so you can pass them to functions as arguments -// by value or by reference. ConstXXXX types are restricted to const only interfaces. -// -// UnownedXXXX are similar to ConstXXXX but also allow non-const interfaces. -// -// The lifetime of the corresponding owning object must eclipse the lifetimes of the ConstXXXX/UnownedXXXX types. They exists so you do not -// have to fallback to C types and the API with the usual pitfalls. In general, do not use C API from your C++ code. - -#pragma once -#include "onnxruntime_c_api.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef ORT_NO_EXCEPTIONS -#include -#endif - -/** \brief All C++ Onnxruntime APIs are defined inside this namespace - * - */ -namespace Ort { - -/** \brief All C++ methods that can fail will throw an exception of this type - * - * If ORT_NO_EXCEPTIONS is defined, then any error will result in a call to abort() - */ -struct Exception : std::exception { - Exception(std::string&& string, OrtErrorCode code) : message_{std::move(string)}, code_{code} {} - - OrtErrorCode GetOrtErrorCode() const { return code_; } - const char* what() const noexcept override { return message_.c_str(); } - - private: - std::string message_; - OrtErrorCode code_; -}; - -#ifdef ORT_NO_EXCEPTIONS -// The #ifndef is for the very special case where the user of this library wants to define their own way of handling errors. -// NOTE: This header expects control flow to not continue after calling ORT_CXX_API_THROW -#ifndef ORT_CXX_API_THROW -#define ORT_CXX_API_THROW(string, code) \ - do { \ - std::cerr << Ort::Exception(string, code) \ - .what() \ - << std::endl; \ - abort(); \ - } while (false) -#endif -#else -#define ORT_CXX_API_THROW(string, code) \ - throw Ort::Exception(string, code) -#endif - -// This is used internally by the C++ API. This class holds the global variable that points to the OrtApi, -// it's in a template so that we can define a global variable in a header and make -// it transparent to the users of the API. -template -struct Global { - static const OrtApi* api_; -}; - -// If macro ORT_API_MANUAL_INIT is defined, no static initialization will be performed. Instead, user must call InitApi() before using it. -template -#ifdef ORT_API_MANUAL_INIT -const OrtApi* Global::api_{}; -inline void InitApi() { Global::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION); } - -// Used by custom operator libraries that are not linked to onnxruntime. Sets the global API object, which is -// required by C++ APIs. -// -// Example mycustomop.cc: -// -// #define ORT_API_MANUAL_INIT -// #include -// #undef ORT_API_MANUAL_INIT -// -// OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, const OrtApiBase* api_base) { -// Ort::InitApi(api_base->GetApi(ORT_API_VERSION)); -// // ... -// } -// -inline void InitApi(const OrtApi* api) { Global::api_ = api; } -#else -#if defined(_MSC_VER) && !defined(__clang__) -#pragma warning(push) -// "Global initializer calls a non-constexpr function." Therefore you can't use ORT APIs in the other global initializers. -// Please define ORT_API_MANUAL_INIT if it conerns you. -#pragma warning(disable : 26426) -#endif -const OrtApi* Global::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION); -#if defined(_MSC_VER) && !defined(__clang__) -#pragma warning(pop) -#endif -#endif - -/// This returns a reference to the OrtApi interface in use -inline const OrtApi& GetApi() { return *Global::api_; } - -/// -/// This is a C++ wrapper for OrtApi::GetAvailableProviders() and -/// returns a vector of strings representing the available execution providers. -/// -/// vector of strings -std::vector GetAvailableProviders(); - -/** \brief IEEE 754 half-precision floating point data type - * \details It is necessary for type dispatching to make use of C++ API - * The type is implicitly convertible to/from uint16_t. - * The size of the structure should align with uint16_t and one can freely cast - * uint16_t buffers to/from Ort::Float16_t to feed and retrieve data. - * - * Generally, you can feed any of your types as float16/blfoat16 data to create a tensor - * on top of it, providing it can form a continuous buffer with 16-bit elements with no padding. - * And you can also feed a array of uint16_t elements directly. For example, - * - * \code{.unparsed} - * uint16_t values[] = { 15360, 16384, 16896, 17408, 17664}; - * constexpr size_t values_length = sizeof(values) / sizeof(values[0]); - * std::vector dims = {values_length}; // one dimensional example - * Ort::MemoryInfo info("Cpu", OrtDeviceAllocator, 0, OrtMemTypeDefault); - * // Note we are passing bytes count in this api, not number of elements -> sizeof(values) - * auto float16_tensor = Ort::Value::CreateTensor(info, values, sizeof(values), - * dims.data(), dims.size(), ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16); - * \endcode - * - * Here is another example, a little bit more elaborate. Let's assume that you use your own float16 type and you want to use - * a templated version of the API above so the type is automatically set based on your type. You will need to supply an extra - * template specialization. - * - * \code{.unparsed} - * namespace yours { struct half {}; } // assume this is your type, define this: - * namespace Ort { - * template<> - * struct TypeToTensorType { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16; }; - * } //namespace Ort - * - * std::vector values; - * std::vector dims = {values.size()}; // one dimensional example - * Ort::MemoryInfo info("Cpu", OrtDeviceAllocator, 0, OrtMemTypeDefault); - * // Here we are passing element count -> values.size() - * auto float16_tensor = Ort::Value::CreateTensor(info, values.data(), values.size(), dims.data(), dims.size()); - * - * \endcode - */ -struct Float16_t { - uint16_t value; - constexpr Float16_t() noexcept : value(0) {} - constexpr Float16_t(uint16_t v) noexcept : value(v) {} - constexpr operator uint16_t() const noexcept { return value; } - constexpr bool operator==(const Float16_t& rhs) const noexcept { return value == rhs.value; }; - constexpr bool operator!=(const Float16_t& rhs) const noexcept { return value != rhs.value; }; -}; - -static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match"); - -/** \brief bfloat16 (Brain Floating Point) data type - * \details It is necessary for type dispatching to make use of C++ API - * The type is implicitly convertible to/from uint16_t. - * The size of the structure should align with uint16_t and one can freely cast - * uint16_t buffers to/from Ort::BFloat16_t to feed and retrieve data. - * - * See also code examples for Float16_t above. - */ -struct BFloat16_t { - uint16_t value; - constexpr BFloat16_t() noexcept : value(0) {} - constexpr BFloat16_t(uint16_t v) noexcept : value(v) {} - constexpr operator uint16_t() const noexcept { return value; } - constexpr bool operator==(const BFloat16_t& rhs) const noexcept { return value == rhs.value; }; - constexpr bool operator!=(const BFloat16_t& rhs) const noexcept { return value != rhs.value; }; -}; - -static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match"); - -namespace detail { -// This is used internally by the C++ API. This macro is to make it easy to generate overloaded methods for all of the various OrtRelease* functions for every Ort* type -// This can't be done in the C API since C doesn't have function overloading. -#define ORT_DEFINE_RELEASE(NAME) \ - inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); } - -ORT_DEFINE_RELEASE(Allocator); -ORT_DEFINE_RELEASE(MemoryInfo); -ORT_DEFINE_RELEASE(CustomOpDomain); -ORT_DEFINE_RELEASE(ThreadingOptions); -ORT_DEFINE_RELEASE(Env); -ORT_DEFINE_RELEASE(RunOptions); -ORT_DEFINE_RELEASE(Session); -ORT_DEFINE_RELEASE(SessionOptions); -ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo); -ORT_DEFINE_RELEASE(SequenceTypeInfo); -ORT_DEFINE_RELEASE(MapTypeInfo); -ORT_DEFINE_RELEASE(TypeInfo); -ORT_DEFINE_RELEASE(Value); -ORT_DEFINE_RELEASE(ModelMetadata); -ORT_DEFINE_RELEASE(IoBinding); -ORT_DEFINE_RELEASE(ArenaCfg); -ORT_DEFINE_RELEASE(Status); -ORT_DEFINE_RELEASE(OpAttr); -ORT_DEFINE_RELEASE(Op); -ORT_DEFINE_RELEASE(KernelInfo); - -#undef ORT_DEFINE_RELEASE - -/** \brief This is a tagging template type. Use it with Base to indicate that the C++ interface object - * has no ownership of the underlying C object. - */ -template -struct Unowned { - using Type = T; -}; - -/** \brief Used internally by the C++ API. C++ wrapper types inherit from this. - * This is a zero cost abstraction to wrap the C API objects and delete them on destruction. - * - * All of the C++ classes - * a) serve as containers for pointers to objects that are created by the underlying C API. - * Their size is just a pointer size, no need to dynamically allocate them. Use them by value. - * b) Each of struct XXXX, XXX instances function as smart pointers to the underlying C API objects. - * they would release objects owned automatically when going out of scope, they are move-only. - * c) ConstXXXX and UnownedXXX structs function as non-owning, copyable containers for the above pointers. - * ConstXXXX allow calling const interfaces only. They give access to objects that are owned by somebody else - * such as Onnxruntime or instances of XXXX classes. - * d) serve convenient interfaces that return C++ objects and further enhance exception and type safety so they can be used - * in C++ code. - * - */ - -/// -/// This is a non-const pointer holder that is move-only. Disposes of the pointer on destruction. -/// -template -struct Base { - using contained_type = T; - - constexpr Base() = default; - constexpr explicit Base(contained_type* p) noexcept : p_{p} {} - ~Base() { OrtRelease(p_); } - - Base(const Base&) = delete; - Base& operator=(const Base&) = delete; - - Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; } - Base& operator=(Base&& v) noexcept { - OrtRelease(p_); - p_ = v.release(); - return *this; - } - - constexpr operator contained_type*() const noexcept { return p_; } - - /// \brief Relinquishes ownership of the contained C object pointer - /// The underlying object is not destroyed - contained_type* release() { - T* p = p_; - p_ = nullptr; - return p; - } - - protected: - contained_type* p_{}; -}; - -// Undefined. For const types use Base> -template -struct Base; - -/// -/// Covers unowned pointers owned by either the ORT -/// or some other instance of CPP wrappers. -/// Used for ConstXXX and UnownedXXXX types that are copyable. -/// Also convenient to wrap raw OrtXX pointers . -/// -/// -template -struct Base> { - using contained_type = typename Unowned::Type; - - constexpr Base() = default; - constexpr explicit Base(contained_type* p) noexcept : p_{p} {} - - ~Base() = default; - - Base(const Base&) = default; - Base& operator=(const Base&) = default; - - Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; } - Base& operator=(Base&& v) noexcept { - p_ = nullptr; - std::swap(p_, v.p_); - return *this; - } - - constexpr operator contained_type*() const noexcept { return p_; } - - protected: - contained_type* p_{}; -}; - -// Light functor to release memory with OrtAllocator -struct AllocatedFree { - OrtAllocator* allocator_; - explicit AllocatedFree(OrtAllocator* allocator) - : allocator_(allocator) {} - void operator()(void* ptr) const { - if (ptr) allocator_->Free(allocator_, ptr); - } -}; - -} // namespace detail - -struct AllocatorWithDefaultOptions; -struct Env; -struct TypeInfo; -struct Value; -struct ModelMetadata; - -/** \brief unique_ptr typedef used to own strings allocated by OrtAllocators - * and release them at the end of the scope. The lifespan of the given allocator - * must eclipse the lifespan of AllocatedStringPtr instance - */ -using AllocatedStringPtr = std::unique_ptr; - -/** \brief The Status that holds ownership of OrtStatus received from C API - * Use it to safely destroy OrtStatus* returned from the C API. Use appropriate - * constructors to construct an instance of a Status object from exceptions. - */ -struct Status : detail::Base { - explicit Status(std::nullptr_t) {} ///< Create an empty object, must be assigned a valid one to be used - explicit Status(OrtStatus* status); ///< Takes ownership of OrtStatus instance returned from the C API. Must be non-null - explicit Status(const Exception&); ///< Creates status instance out of exception - explicit Status(const std::exception&); ///< Creates status instance out of exception - std::string GetErrorMessage() const; - OrtErrorCode GetErrorCode() const; -}; - -/** \brief The ThreadingOptions - * - * The ThreadingOptions used for set global threadpools' options of The Env. - */ -struct ThreadingOptions : detail::Base { - /// \brief Wraps OrtApi::CreateThreadingOptions - ThreadingOptions(); - - /// \brief Wraps OrtApi::SetGlobalIntraOpNumThreads - ThreadingOptions& SetGlobalIntraOpNumThreads(int intra_op_num_threads); - - /// \brief Wraps OrtApi::SetGlobalInterOpNumThreads - ThreadingOptions& SetGlobalInterOpNumThreads(int inter_op_num_threads); - - /// \brief Wraps OrtApi::SetGlobalSpinControl - ThreadingOptions& SetGlobalSpinControl(int allow_spinning); - - /// \brief Wraps OrtApi::SetGlobalDenormalAsZero - ThreadingOptions& SetGlobalDenormalAsZero(); - - /// \brief Wraps OrtApi::SetGlobalCustomCreateThreadFn - ThreadingOptions& SetGlobalCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn); - - /// \brief Wraps OrtApi::SetGlobalCustomThreadCreationOptions - ThreadingOptions& SetGlobalCustomThreadCreationOptions(void* ort_custom_thread_creation_options); - - /// \brief Wraps OrtApi::SetGlobalCustomJoinThreadFn - ThreadingOptions& SetGlobalCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn); -}; - -/** \brief The Env (Environment) - * - * The Env holds the logging state used by all other objects. - * Note: One Env must be created before using any other Onnxruntime functionality - */ -struct Env : detail::Base { - explicit Env(std::nullptr_t) {} ///< Create an empty Env object, must be assigned a valid one to be used - - /// \brief Wraps OrtApi::CreateEnv - Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = ""); - - /// \brief Wraps OrtApi::CreateEnvWithCustomLogger - Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param); - - /// \brief Wraps OrtApi::CreateEnvWithGlobalThreadPools - Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = ""); - - /// \brief Wraps OrtApi::CreateEnvWithCustomLoggerAndGlobalThreadPools - Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param, - OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = ""); - - /// \brief C Interop Helper - explicit Env(OrtEnv* p) : Base{p} {} - - Env& EnableTelemetryEvents(); ///< Wraps OrtApi::EnableTelemetryEvents - Env& DisableTelemetryEvents(); ///< Wraps OrtApi::DisableTelemetryEvents - - Env& UpdateEnvWithCustomLogLevel(OrtLoggingLevel log_severity_level); ///< Wraps OrtApi::UpdateEnvWithCustomLogLevel - - Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg); ///< Wraps OrtApi::CreateAndRegisterAllocator -}; - -/** \brief Custom Op Domain - * - */ -struct CustomOpDomain : detail::Base { - explicit CustomOpDomain(std::nullptr_t) {} ///< Create an empty CustomOpDomain object, must be assigned a valid one to be used - - /// \brief Wraps OrtApi::CreateCustomOpDomain - explicit CustomOpDomain(const char* domain); - - // This does not take ownership of the op, simply registers it. - void Add(const OrtCustomOp* op); ///< Wraps CustomOpDomain_Add -}; - -/** \brief RunOptions - * - */ -struct RunOptions : detail::Base { - explicit RunOptions(std::nullptr_t) {} ///< Create an empty RunOptions object, must be assigned a valid one to be used - RunOptions(); ///< Wraps OrtApi::CreateRunOptions - - RunOptions& SetRunLogVerbosityLevel(int); ///< Wraps OrtApi::RunOptionsSetRunLogVerbosityLevel - int GetRunLogVerbosityLevel() const; ///< Wraps OrtApi::RunOptionsGetRunLogVerbosityLevel - - RunOptions& SetRunLogSeverityLevel(int); ///< Wraps OrtApi::RunOptionsSetRunLogSeverityLevel - int GetRunLogSeverityLevel() const; ///< Wraps OrtApi::RunOptionsGetRunLogSeverityLevel - - RunOptions& SetRunTag(const char* run_tag); ///< wraps OrtApi::RunOptionsSetRunTag - const char* GetRunTag() const; ///< Wraps OrtApi::RunOptionsGetRunTag - - RunOptions& AddConfigEntry(const char* config_key, const char* config_value); ///< Wraps OrtApi::AddRunConfigEntry - - /** \brief Terminates all currently executing Session::Run calls that were made using this RunOptions instance - * - * If a currently executing session needs to be force terminated, this can be called from another thread to force it to fail with an error - * Wraps OrtApi::RunOptionsSetTerminate - */ - RunOptions& SetTerminate(); - - /** \brief Clears the terminate flag so this RunOptions instance can be used in a new Session::Run call without it instantly terminating - * - * Wraps OrtApi::RunOptionsUnsetTerminate - */ - RunOptions& UnsetTerminate(); -}; - - -namespace detail { -// Utility function that returns a SessionOption config entry key for a specific custom operator. -// Ex: custom_op.[custom_op_name].[config] -std::string MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config); -} // namespace detail - -/// -/// Class that represents session configuration entries for one or more custom operators. -/// -/// Example: -/// Ort::CustomOpConfigs op_configs; -/// op_configs.AddConfig("my_custom_op", "device_type", "CPU"); -/// -/// Passed to Ort::SessionOptions::RegisterCustomOpsLibrary. -/// -struct CustomOpConfigs { - CustomOpConfigs() = default; - ~CustomOpConfigs() = default; - CustomOpConfigs(const CustomOpConfigs&) = default; - CustomOpConfigs& operator=(const CustomOpConfigs&) = default; - CustomOpConfigs(CustomOpConfigs&& o) = default; - CustomOpConfigs& operator=(CustomOpConfigs&& o) = default; - - /** \brief Adds a session configuration entry/value for a specific custom operator. - * - * \param custom_op_name The name of the custom operator for which to add a configuration entry. - * Must match the name returned by the CustomOp's GetName() method. - * \param config_key The name of the configuration entry. - * \param config_value The value of the configuration entry. - * \return A reference to this object to enable call chaining. - */ - CustomOpConfigs& AddConfig(const char* custom_op_name, const char* config_key, const char* config_value); - - /** \brief Returns a flattened map of custom operator configuration entries and their values. - * - * The keys has been flattened to include both the custom operator name and the configuration entry key name. - * For example, a prior call to AddConfig("my_op", "key", "value") corresponds to the flattened key/value pair - * {"my_op.key", "value"}. - * - * \return An unordered map of flattened configurations. - */ - const std::unordered_map& GetFlattenedConfigs() const; - - private: - std::unordered_map flat_configs_; -}; - -/** \brief Options object used when creating a new Session object - * - * Wraps ::OrtSessionOptions object and methods - */ - -struct SessionOptions; - -namespace detail { -// we separate const-only methods because passing const ptr to non-const methods -// is only discovered when inline methods are compiled which is counter-intuitive -template -struct ConstSessionOptionsImpl : Base { - using B = Base; - using B::B; - - SessionOptions Clone() const; ///< Creates and returns a copy of this SessionOptions object. Wraps OrtApi::CloneSessionOptions - - std::string GetConfigEntry(const char* config_key) const; ///< Wraps OrtApi::GetSessionConfigEntry - bool HasConfigEntry(const char* config_key) const; ///< Wraps OrtApi::HasSessionConfigEntry - std::string GetConfigEntryOrDefault(const char* config_key, const std::string& def); -}; - -template -struct SessionOptionsImpl : ConstSessionOptionsImpl { - using B = ConstSessionOptionsImpl; - using B::B; - - SessionOptionsImpl& SetIntraOpNumThreads(int intra_op_num_threads); ///< Wraps OrtApi::SetIntraOpNumThreads - SessionOptionsImpl& SetInterOpNumThreads(int inter_op_num_threads); ///< Wraps OrtApi::SetInterOpNumThreads - SessionOptionsImpl& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level); ///< Wraps OrtApi::SetSessionGraphOptimizationLevel - - SessionOptionsImpl& EnableCpuMemArena(); ///< Wraps OrtApi::EnableCpuMemArena - SessionOptionsImpl& DisableCpuMemArena(); ///< Wraps OrtApi::DisableCpuMemArena - - SessionOptionsImpl& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file); ///< Wraps OrtApi::SetOptimizedModelFilePath - - SessionOptionsImpl& EnableProfiling(const ORTCHAR_T* profile_file_prefix); ///< Wraps OrtApi::EnableProfiling - SessionOptionsImpl& DisableProfiling(); ///< Wraps OrtApi::DisableProfiling - - SessionOptionsImpl& EnableOrtCustomOps(); ///< Wraps OrtApi::EnableOrtCustomOps - - SessionOptionsImpl& EnableMemPattern(); ///< Wraps OrtApi::EnableMemPattern - SessionOptionsImpl& DisableMemPattern(); ///< Wraps OrtApi::DisableMemPattern - - SessionOptionsImpl& SetExecutionMode(ExecutionMode execution_mode); ///< Wraps OrtApi::SetSessionExecutionMode - - SessionOptionsImpl& SetLogId(const char* logid); ///< Wraps OrtApi::SetSessionLogId - SessionOptionsImpl& SetLogSeverityLevel(int level); ///< Wraps OrtApi::SetSessionLogSeverityLevel - - SessionOptionsImpl& Add(OrtCustomOpDomain* custom_op_domain); ///< Wraps OrtApi::AddCustomOpDomain - - SessionOptionsImpl& DisablePerSessionThreads(); ///< Wraps OrtApi::DisablePerSessionThreads - - SessionOptionsImpl& AddConfigEntry(const char* config_key, const char* config_value); ///< Wraps OrtApi::AddSessionConfigEntry - - SessionOptionsImpl& AddInitializer(const char* name, const OrtValue* ort_val); ///< Wraps OrtApi::AddInitializer - SessionOptionsImpl& AddExternalInitializers(const std::vector& names, const std::vector& ort_values); ///< Wraps OrtApi::AddExternalInitializers - - SessionOptionsImpl& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_CUDA - SessionOptionsImpl& AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_CUDA_V2 - SessionOptionsImpl& AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_ROCM - SessionOptionsImpl& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_OpenVINO - SessionOptionsImpl& AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_TensorRT - SessionOptionsImpl& AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_TensorRT - SessionOptionsImpl& AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options); ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_MIGraphX - ///< Wraps OrtApi::SessionOptionsAppendExecutionProvider_CANN - SessionOptionsImpl& AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options); - /// Wraps OrtApi::SessionOptionsAppendExecutionProvider. Currently supports SNPE and XNNPACK. - SessionOptionsImpl& AppendExecutionProvider(const std::string& provider_name, - const std::unordered_map& provider_options = {}); - - SessionOptionsImpl& SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn); ///< Wraps OrtApi::SessionOptionsSetCustomCreateThreadFn - SessionOptionsImpl& SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options); ///< Wraps OrtApi::SessionOptionsSetCustomThreadCreationOptions - SessionOptionsImpl& SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn); ///< Wraps OrtApi::SessionOptionsSetCustomJoinThreadFn - - ///< Registers the custom operator from the specified shared library via OrtApi::RegisterCustomOpsLibrary_V2. - ///< The custom operator configurations are optional. If provided, custom operator configs are set via - ///< OrtApi::AddSessionConfigEntry. - SessionOptionsImpl& RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, const CustomOpConfigs& custom_op_configs = {}); - - SessionOptionsImpl& RegisterCustomOpsUsingFunction(const char* function_name); ///< Wraps OrtApi::RegisterCustomOpsUsingFunction -}; -} // namespace detail - -using UnownedSessionOptions = detail::SessionOptionsImpl>; -using ConstSessionOptions = detail::ConstSessionOptionsImpl>; - -/** \brief Wrapper around ::OrtSessionOptions - * - */ -struct SessionOptions : detail::SessionOptionsImpl { - explicit SessionOptions(std::nullptr_t) {} ///< Create an empty SessionOptions object, must be assigned a valid one to be used - SessionOptions(); ///< Wraps OrtApi::CreateSessionOptions - explicit SessionOptions(OrtSessionOptions* p) : SessionOptionsImpl{p} {} ///< Used for interop with the C API - UnownedSessionOptions GetUnowned() const { return UnownedSessionOptions{this->p_}; } - ConstSessionOptions GetConst() const { return ConstSessionOptions{this->p_}; } -}; - -/** \brief Wrapper around ::OrtModelMetadata - * - */ -struct ModelMetadata : detail::Base { - explicit ModelMetadata(std::nullptr_t) {} ///< Create an empty ModelMetadata object, must be assigned a valid one to be used - explicit ModelMetadata(OrtModelMetadata* p) : Base{p} {} ///< Used for interop with the C API - - /** \brief Returns a copy of the producer name. - * - * \param allocator to allocate memory for the copy of the name returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr GetProducerNameAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetProducerName - - /** \brief Returns a copy of the graph name. - * - * \param allocator to allocate memory for the copy of the name returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr GetGraphNameAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetGraphName - - /** \brief Returns a copy of the domain name. - * - * \param allocator to allocate memory for the copy of the name returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr GetDomainAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetDomain - - /** \brief Returns a copy of the description. - * - * \param allocator to allocate memory for the copy of the string returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr GetDescriptionAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetDescription - - /** \brief Returns a copy of the graph description. - * - * \param allocator to allocate memory for the copy of the string returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr GetGraphDescriptionAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetGraphDescription - - /** \brief Returns a vector of copies of the custom metadata keys. - * - * \param allocator to allocate memory for the copy of the string returned - * \return a instance std::vector of smart pointers that would deallocate the buffers when out of scope. - * The OrtAllocator instance must be valid at the point of memory release. - */ - std::vector GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetCustomMetadataMapKeys - - /** \brief Looks up a value by a key in the Custom Metadata map - * - * \param key zero terminated string key to lookup - * \param allocator to allocate memory for the copy of the string returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * maybe nullptr if key is not found. - * - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr LookupCustomMetadataMapAllocated(const char* key, OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataLookupCustomMetadataMap - - int64_t GetVersion() const; ///< Wraps OrtApi::ModelMetadataGetVersion -}; - -struct IoBinding; - -namespace detail { - -// we separate const-only methods because passing const ptr to non-const methods -// is only discovered when inline methods are compiled which is counter-intuitive -template -struct ConstSessionImpl : Base { - using B = Base; - using B::B; - - size_t GetInputCount() const; ///< Returns the number of model inputs - size_t GetOutputCount() const; ///< Returns the number of model outputs - size_t GetOverridableInitializerCount() const; ///< Returns the number of inputs that have defaults that can be overridden - - /** \brief Returns a copy of input name at the specified index. - * - * \param index must less than the value returned by GetInputCount() - * \param allocator to allocate memory for the copy of the name returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr GetInputNameAllocated(size_t index, OrtAllocator* allocator) const; - - /** \brief Returns a copy of output name at then specified index. - * - * \param index must less than the value returned by GetOutputCount() - * \param allocator to allocate memory for the copy of the name returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr GetOutputNameAllocated(size_t index, OrtAllocator* allocator) const; - - /** \brief Returns a copy of the overridable initializer name at then specified index. - * - * \param index must less than the value returned by GetOverridableInitializerCount() - * \param allocator to allocate memory for the copy of the name returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr GetOverridableInitializerNameAllocated(size_t index, OrtAllocator* allocator) const; ///< Wraps OrtApi::SessionGetOverridableInitializerName - - uint64_t GetProfilingStartTimeNs() const; ///< Wraps OrtApi::SessionGetProfilingStartTimeNs - ModelMetadata GetModelMetadata() const; ///< Wraps OrtApi::SessionGetModelMetadata - - TypeInfo GetInputTypeInfo(size_t index) const; ///< Wraps OrtApi::SessionGetInputTypeInfo - TypeInfo GetOutputTypeInfo(size_t index) const; ///< Wraps OrtApi::SessionGetOutputTypeInfo - TypeInfo GetOverridableInitializerTypeInfo(size_t index) const; ///< Wraps OrtApi::SessionGetOverridableInitializerTypeInfo -}; - -template -struct SessionImpl : ConstSessionImpl { - using B = ConstSessionImpl; - using B::B; - - /** \brief Run the model returning results in an Ort allocated vector. - * - * Wraps OrtApi::Run - * - * The caller provides a list of inputs and a list of the desired outputs to return. - * - * See the output logs for more information on warnings/errors that occur while processing the model. - * Common errors are.. (TODO) - * - * \param[in] run_options - * \param[in] input_names Array of null terminated strings of length input_count that is the list of input names - * \param[in] input_values Array of Value objects of length input_count that is the list of input values - * \param[in] input_count Number of inputs (the size of the input_names & input_values arrays) - * \param[in] output_names Array of C style strings of length output_count that is the list of output names - * \param[in] output_count Number of outputs (the size of the output_names array) - * \return A std::vector of Value objects that directly maps to the output_names array (eg. output_name[0] is the first entry of the returned vector) - */ - std::vector Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count, - const char* const* output_names, size_t output_count); - - /** \brief Run the model returning results in user provided outputs - * Same as Run(const RunOptions&, const char* const*, const Value*, size_t,const char* const*, size_t) - */ - void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count, - const char* const* output_names, Value* output_values, size_t output_count); - - void Run(const RunOptions& run_options, const IoBinding&); ///< Wraps OrtApi::RunWithBinding - - /** \brief End profiling and return a copy of the profiling file name. - * - * \param allocator to allocate memory for the copy of the string returned - * \return a instance of smart pointer that would deallocate the buffer when out of scope. - * The OrtAllocator instances must be valid at the point of memory release. - */ - AllocatedStringPtr EndProfilingAllocated(OrtAllocator* allocator); ///< Wraps OrtApi::SessionEndProfiling -}; - -} // namespace detail - -using ConstSession = detail::ConstSessionImpl>; -using UnownedSession = detail::SessionImpl>; - -/** \brief Wrapper around ::OrtSession - * - */ -struct Session : detail::SessionImpl { - explicit Session(std::nullptr_t) {} ///< Create an empty Session object, must be assigned a valid one to be used - Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options); ///< Wraps OrtApi::CreateSession - Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options, - OrtPrepackedWeightsContainer* prepacked_weights_container); ///< Wraps OrtApi::CreateSessionWithPrepackedWeightsContainer - Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options); ///< Wraps OrtApi::CreateSessionFromArray - Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options, - OrtPrepackedWeightsContainer* prepacked_weights_container); ///< Wraps OrtApi::CreateSessionFromArrayWithPrepackedWeightsContainer - - ConstSession GetConst() const { return ConstSession{this->p_}; } - UnownedSession GetUnowned() const { return UnownedSession{this->p_}; } -}; - -namespace detail { -template -struct MemoryInfoImpl : Base { - using B = Base; - using B::B; - - std::string GetAllocatorName() const; - OrtAllocatorType GetAllocatorType() const; - int GetDeviceId() const; - OrtMemoryInfoDeviceType GetDeviceType() const; - OrtMemType GetMemoryType() const; - - template - bool operator==(const MemoryInfoImpl& o) const; -}; -} // namespace detail - -// Const object holder that does not own the underlying object -using ConstMemoryInfo = detail::MemoryInfoImpl>; - -/** \brief Wrapper around ::OrtMemoryInfo - * - */ -struct MemoryInfo : detail::MemoryInfoImpl { - static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1); - explicit MemoryInfo(std::nullptr_t) {} ///< No instance is created - explicit MemoryInfo(OrtMemoryInfo* p) : MemoryInfoImpl{p} {} ///< Take ownership of a pointer created by C Api - MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type); - ConstMemoryInfo GetConst() const { return ConstMemoryInfo{this->p_}; } -}; - -namespace detail { -template -struct TensorTypeAndShapeInfoImpl : Base { - using B = Base; - using B::B; - - ONNXTensorElementDataType GetElementType() const; ///< Wraps OrtApi::GetTensorElementType - size_t GetElementCount() const; ///< Wraps OrtApi::GetTensorShapeElementCount - - size_t GetDimensionsCount() const; ///< Wraps OrtApi::GetDimensionsCount - - /** \deprecated use GetShape() returning std::vector - * [[deprecated]] - * This interface is unsafe to use - */ - [[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const; ///< Wraps OrtApi::GetDimensions - - void GetSymbolicDimensions(const char** values, size_t values_count) const; ///< Wraps OrtApi::GetSymbolicDimensions - - std::vector GetShape() const; ///< Uses GetDimensionsCount & GetDimensions to return a std::vector of the shape -}; - -} // namespace detail - -using ConstTensorTypeAndShapeInfo = detail::TensorTypeAndShapeInfoImpl>; - -/** \brief Wrapper around ::OrtTensorTypeAndShapeInfo - * - */ -struct TensorTypeAndShapeInfo : detail::TensorTypeAndShapeInfoImpl { - explicit TensorTypeAndShapeInfo(std::nullptr_t) {} ///< Create an empty TensorTypeAndShapeInfo object, must be assigned a valid one to be used - explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : TensorTypeAndShapeInfoImpl{p} {} ///< Used for interop with the C API - ConstTensorTypeAndShapeInfo GetConst() const { return ConstTensorTypeAndShapeInfo{this->p_}; } -}; - -namespace detail { -template -struct SequenceTypeInfoImpl : Base { - using B = Base; - using B::B; - TypeInfo GetSequenceElementType() const; ///< Wraps OrtApi::GetSequenceElementType -}; - -} // namespace detail - -using ConstSequenceTypeInfo = detail::SequenceTypeInfoImpl>; - -/** \brief Wrapper around ::OrtSequenceTypeInfo - * - */ -struct SequenceTypeInfo : detail::SequenceTypeInfoImpl { - explicit SequenceTypeInfo(std::nullptr_t) {} ///< Create an empty SequenceTypeInfo object, must be assigned a valid one to be used - explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : SequenceTypeInfoImpl{p} {} ///< Used for interop with the C API - ConstSequenceTypeInfo GetConst() const { return ConstSequenceTypeInfo{this->p_}; } -}; - -namespace detail { -template -struct MapTypeInfoImpl : detail::Base { - using B = Base; - using B::B; - ONNXTensorElementDataType GetMapKeyType() const; ///< Wraps OrtApi::GetMapKeyType - TypeInfo GetMapValueType() const; ///< Wraps OrtApi::GetMapValueType -}; - -} // namespace detail - -using ConstMapTypeInfo = detail::MapTypeInfoImpl>; - -/** \brief Wrapper around ::OrtMapTypeInfo - * - */ -struct MapTypeInfo : detail::MapTypeInfoImpl { - explicit MapTypeInfo(std::nullptr_t) {} ///< Create an empty MapTypeInfo object, must be assigned a valid one to be used - explicit MapTypeInfo(OrtMapTypeInfo* p) : MapTypeInfoImpl{p} {} ///< Used for interop with the C API - ConstMapTypeInfo GetConst() const { return ConstMapTypeInfo{this->p_}; } -}; - -namespace detail { -template -struct TypeInfoImpl : detail::Base { - using B = Base; - using B::B; - - ConstTensorTypeAndShapeInfo GetTensorTypeAndShapeInfo() const; ///< Wraps OrtApi::CastTypeInfoToTensorInfo - ConstSequenceTypeInfo GetSequenceTypeInfo() const; ///< Wraps OrtApi::CastTypeInfoToSequenceTypeInfo - ConstMapTypeInfo GetMapTypeInfo() const; ///< Wraps OrtApi::CastTypeInfoToMapTypeInfo - - ONNXType GetONNXType() const; -}; -} // namespace detail - -/// -/// Contains a constant, unowned OrtTypeInfo that can be copied and passed around by value. -/// Provides access to const OrtTypeInfo APIs. -/// -using ConstTypeInfo = detail::TypeInfoImpl>; - -/// -/// Type information that may contain either TensorTypeAndShapeInfo or -/// the information about contained sequence or map depending on the ONNXType. -/// -struct TypeInfo : detail::TypeInfoImpl { - explicit TypeInfo(std::nullptr_t) {} ///< Create an empty TypeInfo object, must be assigned a valid one to be used - explicit TypeInfo(OrtTypeInfo* p) : TypeInfoImpl{p} {} ///< C API Interop - - ConstTypeInfo GetConst() const { return ConstTypeInfo{this->p_}; } -}; - -namespace detail { -// This structure is used to feed sparse tensor values -// information for use with FillSparseTensor() API -// if the data type for the sparse tensor values is numeric -// use data.p_data, otherwise, use data.str pointer to feed -// values. data.str is an array of const char* that are zero terminated. -// number of strings in the array must match shape size. -// For fully sparse tensors use shape {0} and set p_data/str -// to nullptr. -struct OrtSparseValuesParam { - const int64_t* values_shape; - size_t values_shape_len; - union { - const void* p_data; - const char** str; - } data; -}; - -// Provides a way to pass shape in a single -// argument -struct Shape { - const int64_t* shape; - size_t shape_len; -}; - -template -struct ConstValueImpl : Base { - using B = Base; - using B::B; - - /// - /// Obtains a pointer to a user defined data for experimental purposes - /// - template - void GetOpaqueData(const char* domain, const char* type_name, R&) const; ///< Wraps OrtApi::GetOpaqueValue - - bool IsTensor() const; ///< Returns true if Value is a tensor, false for other types like map/sequence/etc - bool HasValue() const; /// < Return true if OrtValue contains data and returns false if the OrtValue is a None - - size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements - Value GetValue(int index, OrtAllocator* allocator) const; - - /// - /// This API returns a full length of string data contained within either a tensor or a sparse Tensor. - /// For sparse tensor it returns a full length of stored non-empty strings (values). The API is useful - /// for allocating necessary memory and calling GetStringTensorContent(). - /// - /// total length of UTF-8 encoded bytes contained. No zero terminators counted. - size_t GetStringTensorDataLength() const; - - /// - /// The API copies all of the UTF-8 encoded string data contained within a tensor or a sparse tensor - /// into a supplied buffer. Use GetStringTensorDataLength() to find out the length of the buffer to allocate. - /// The user must also allocate offsets buffer with the number of entries equal to that of the contained - /// strings. - /// - /// Strings are always assumed to be on CPU, no X-device copy. - /// - /// user allocated buffer - /// length in bytes of the allocated buffer - /// a pointer to the offsets user allocated buffer - /// count of offsets, must be equal to the number of strings contained. - /// that can be obtained from the shape of the tensor or from GetSparseTensorValuesTypeAndShapeInfo() - /// for sparse tensors - void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const; - - /// - /// Returns a const typed pointer to the tensor contained data. - /// No type checking is performed, the caller must ensure the type matches the tensor type. - /// - /// - /// const pointer to data, no copies made - template - const R* GetTensorData() const; ///< Wraps OrtApi::GetTensorMutableData /// - - /// - /// Returns a non-typed pointer to a tensor contained data. - /// - /// const pointer to data, no copies made - const void* GetTensorRawData() const; - - /// - /// The API returns type information for data contained in a tensor. For sparse - /// tensors it returns type information for contained non-zero values. - /// It returns dense shape for sparse tensors. - /// - /// TypeInfo - TypeInfo GetTypeInfo() const; - - /// - /// The API returns type information for data contained in a tensor. For sparse - /// tensors it returns type information for contained non-zero values. - /// It returns dense shape for sparse tensors. - /// - /// TensorTypeAndShapeInfo - TensorTypeAndShapeInfo GetTensorTypeAndShapeInfo() const; - - /// - /// This API returns information about the memory allocation used to hold data. - /// - /// Non owning instance of MemoryInfo - ConstMemoryInfo GetTensorMemoryInfo() const; - - /// - /// The API copies UTF-8 encoded bytes for the requested string element - /// contained within a tensor or a sparse tensor into a provided buffer. - /// Use GetStringTensorElementLength() to obtain the length of the buffer to allocate. - /// - /// - /// - /// - void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const; - - /// - /// The API returns a byte length of UTF-8 encoded string element - /// contained in either a tensor or a spare tensor values. - /// - /// - /// byte length for the specified string element - size_t GetStringTensorElementLength(size_t element_index) const; - -#if !defined(DISABLE_SPARSE_TENSORS) - /// - /// The API returns the sparse data format this OrtValue holds in a sparse tensor. - /// If the sparse tensor was not fully constructed, i.e. Use*() or Fill*() API were not used - /// the value returned is ORT_SPARSE_UNDEFINED. - /// - /// Format enum - OrtSparseFormat GetSparseFormat() const; - - /// - /// The API returns type and shape information for stored non-zero values of the - /// sparse tensor. Use GetSparseTensorValues() to obtain values buffer pointer. - /// - /// TensorTypeAndShapeInfo values information - TensorTypeAndShapeInfo GetSparseTensorValuesTypeAndShapeInfo() const; - - /// - /// The API returns type and shape information for the specified indices. Each supported - /// indices have their own enum values even if a give format has more than one kind of indices. - /// Use GetSparseTensorIndicesData() to obtain pointer to indices buffer. - /// - /// enum requested - /// type and shape information - TensorTypeAndShapeInfo GetSparseTensorIndicesTypeShapeInfo(OrtSparseIndicesFormat format) const; - - /// - /// The API retrieves a pointer to the internal indices buffer. The API merely performs - /// a convenience data type casting on the return type pointer. Make sure you are requesting - /// the right type, use GetSparseTensorIndicesTypeShapeInfo(); - /// - /// type to cast to - /// requested indices kind - /// number of indices entries - /// Pinter to the internal sparse tensor buffer containing indices. Do not free this pointer. - template - const R* GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const; - - /// - /// Returns true if the OrtValue contains a sparse tensor - /// - /// - bool IsSparseTensor() const; - - /// - /// The API returns a pointer to an internal buffer of the sparse tensor - /// containing non-zero values. The API merely does casting. Make sure you - /// are requesting the right data type by calling GetSparseTensorValuesTypeAndShapeInfo() - /// first. - /// - /// numeric data types only. Use GetStringTensor*() to retrieve strings. - /// a pointer to the internal values buffer. Do not free this pointer. - template - const R* GetSparseTensorValues() const; - -#endif -}; - -template -struct ValueImpl : ConstValueImpl { - using B = ConstValueImpl; - using B::B; - - /// - /// Returns a non-const typed pointer to an OrtValue/Tensor contained buffer - /// No type checking is performed, the caller must ensure the type matches the tensor type. - /// - /// non-const pointer to data, no copies made - template - R* GetTensorMutableData(); - - /// - /// Returns a non-typed non-const pointer to a tensor contained data. - /// - /// pointer to data, no copies made - void* GetTensorMutableRawData(); - - /// - // Obtain a reference to an element of data at the location specified - /// by the vector of dims. - /// - /// - /// [in] expressed by a vecotr of dimensions offsets - /// - template - R& At(const std::vector& location); - - /// - /// Set all strings at once in a string tensor - /// - /// [in] An array of strings. Each string in this array must be null terminated. - /// [in] Count of strings in s (Must match the size of \p value's tensor shape) - void FillStringTensor(const char* const* s, size_t s_len); - - /// - /// Set a single string in a string tensor - /// - /// [in] A null terminated UTF-8 encoded string - /// [in] Index of the string in the tensor to set - void FillStringTensorElement(const char* s, size_t index); - -#if !defined(DISABLE_SPARSE_TENSORS) - /// - /// Supplies COO format specific indices and marks the contained sparse tensor as being a COO format tensor. - /// Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user - /// allocated buffers lifespan must eclipse that of the OrtValue. - /// The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time. - /// - /// pointer to the user allocated buffer with indices. Use nullptr for fully sparse tensors. - /// number of indices entries. Use 0 for fully sparse tensors - void UseCooIndices(int64_t* indices_data, size_t indices_num); - - /// - /// Supplies CSR format specific indices and marks the contained sparse tensor as being a CSR format tensor. - /// Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user - /// allocated buffers lifespan must eclipse that of the OrtValue. - /// The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time. - /// - /// pointer to the user allocated buffer with inner indices or nullptr for fully sparse tensors - /// number of csr inner indices or 0 for fully sparse tensors - /// pointer to the user allocated buffer with outer indices or nullptr for fully sparse tensors - /// number of csr outer indices or 0 for fully sparse tensors - void UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num); - - /// - /// Supplies BlockSparse format specific indices and marks the contained sparse tensor as being a BlockSparse format tensor. - /// Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user - /// allocated buffers lifespan must eclipse that of the OrtValue. - /// The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time. - /// - /// indices shape or a {0} for fully sparse - /// user allocated buffer with indices or nullptr for fully spare tensors - void UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data); - - /// - /// The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API - /// and copy the values and COO indices into it. If data_mem_info specifies that the data is located - /// at difference device than the allocator, a X-device copy will be performed if possible. - /// - /// specified buffer memory description - /// values buffer information. - /// coo indices buffer or nullptr for fully sparse data - /// number of COO indices or 0 for fully sparse data - void FillSparseTensorCoo(const OrtMemoryInfo* data_mem_info, const OrtSparseValuesParam& values_param, - const int64_t* indices_data, size_t indices_num); - - /// - /// The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API - /// and copy the values and CSR indices into it. If data_mem_info specifies that the data is located - /// at difference device than the allocator, a X-device copy will be performed if possible. - /// - /// specified buffer memory description - /// values buffer information - /// csr inner indices pointer or nullptr for fully sparse tensors - /// number of csr inner indices or 0 for fully sparse tensors - /// pointer to csr indices data or nullptr for fully sparse tensors - /// number of csr outer indices or 0 - void FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info, - const OrtSparseValuesParam& values, - const int64_t* inner_indices_data, size_t inner_indices_num, - const int64_t* outer_indices_data, size_t outer_indices_num); - - /// - /// The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API - /// and copy the values and BlockSparse indices into it. If data_mem_info specifies that the data is located - /// at difference device than the allocator, a X-device copy will be performed if possible. - /// - /// specified buffer memory description - /// values buffer information - /// indices shape. use {0} for fully sparse tensors - /// pointer to indices data or nullptr for fully sparse tensors - void FillSparseTensorBlockSparse(const OrtMemoryInfo* data_mem_info, - const OrtSparseValuesParam& values, - const Shape& indices_shape, - const int32_t* indices_data); - -#endif -}; - -} // namespace detail - -using ConstValue = detail::ConstValueImpl>; -using UnownedValue = detail::ValueImpl>; - -/** \brief Wrapper around ::OrtValue - * - */ -struct Value : detail::ValueImpl { - using Base = detail::ValueImpl; - using OrtSparseValuesParam = detail::OrtSparseValuesParam; - using Shape = detail::Shape; - - explicit Value(std::nullptr_t) {} ///< Create an empty Value object, must be assigned a valid one to be used - explicit Value(OrtValue* p) : Base{p} {} ///< Used for interop with the C API - Value(Value&&) = default; - Value& operator=(Value&&) = default; - - ConstValue GetConst() const { return ConstValue{this->p_}; } - UnownedValue GetUnowned() const { return UnownedValue{this->p_}; } - - /** \brief Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue. - * \tparam T The numeric datatype. This API is not suitable for strings. - * \param info Memory description of where the p_data buffer resides (CPU vs GPU etc). - * \param p_data Pointer to the data buffer. - * \param p_data_element_count The number of elements in the data buffer. - * \param shape Pointer to the tensor shape dimensions. - * \param shape_len The number of tensor shape dimensions. - */ - template - static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len); - - /** \brief Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue. - * \param info Memory description of where the p_data buffer resides (CPU vs GPU etc). - * \param p_data Pointer to the data buffer. - * \param p_data_byte_count The number of bytes in the data buffer. - * \param shape Pointer to the tensor shape dimensions. - * \param shape_len The number of tensor shape dimensions. - * \param type The data type. - */ - static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len, - ONNXTensorElementDataType type); - - /** \brief Creates a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue. - * \tparam T The numeric datatype. This API is not suitable for strings. - * \param allocator The allocator to use. - * \param shape Pointer to the tensor shape dimensions. - * \param shape_len The number of tensor shape dimensions. - */ - template - static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len); - - /** \brief Creates a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue. - * \param allocator The allocator to use. - * \param shape Pointer to the tensor shape dimensions. - * \param shape_len The number of tensor shape dimensions. - * \param type The data type. - */ - static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type); - - static Value CreateMap(Value& keys, Value& values); ///< Wraps OrtApi::CreateValue - static Value CreateSequence(std::vector& values); ///< Wraps OrtApi::CreateValue - - template - static Value CreateOpaque(const char* domain, const char* type_name, const T&); ///< Wraps OrtApi::CreateOpaqueValue - -#if !defined(DISABLE_SPARSE_TENSORS) - /// - /// This is a simple forwarding method to the other overload that helps deducing - /// data type enum value from the type of the buffer. - /// - /// numeric datatype. This API is not suitable for strings. - /// Memory description where the user buffers reside (CPU vs GPU etc) - /// pointer to the user supplied buffer, use nullptr for fully sparse tensors - /// a would be dense shape of the tensor - /// non zero values shape. Use a single 0 shape for fully sparse tensors. - /// - template - static Value CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape, - const Shape& values_shape); - - /// - /// Creates an OrtValue instance containing SparseTensor. This constructs - /// a sparse tensor that makes use of user allocated buffers. It does not make copies - /// of the user provided data and does not modify it. The lifespan of user provided buffers should - /// eclipse the life span of the resulting OrtValue. This call constructs an instance that only contain - /// a pointer to non-zero values. To fully populate the sparse tensor call UseIndices() API below - /// to supply a sparse format specific indices. - /// This API is not suitable for string data. Use CreateSparseTensor() with allocator specified so strings - /// can be properly copied into the allocated buffer. - /// - /// Memory description where the user buffers reside (CPU vs GPU etc) - /// pointer to the user supplied buffer, use nullptr for fully sparse tensors - /// a would be dense shape of the tensor - /// non zero values shape. Use a single 0 shape for fully sparse tensors. - /// data type - /// Ort::Value instance containing SparseTensor - static Value CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape, - const Shape& values_shape, ONNXTensorElementDataType type); - - /// - /// This is a simple forwarding method to the below CreateSparseTensor. - /// This helps to specify data type enum in terms of C++ data type. - /// Use CreateSparseTensor - /// - /// numeric data type only. String data enum must be specified explicitly. - /// allocator to use - /// a would be dense shape of the tensor - /// Ort::Value - template - static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape); - - /// - /// Creates an instance of OrtValue containing sparse tensor. The created instance has no data. - /// The data must be supplied by on of the FillSparseTensor() methods that take both non-zero values - /// and indices. The data will be copied into a buffer that would be allocated using the supplied allocator. - /// Use this API to create OrtValues that contain sparse tensors with all supported data types including - /// strings. - /// - /// allocator to use. The allocator lifespan must eclipse that of the resulting OrtValue - /// a would be dense shape of the tensor - /// data type - /// an instance of Ort::Value - static Value CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, ONNXTensorElementDataType type); - -#endif // !defined(DISABLE_SPARSE_TENSORS) -}; - -/// -/// Represents native memory allocation coming from one of the -/// OrtAllocators registered with OnnxRuntime. -/// Use it to wrap an allocation made by an allocator -/// so it can be automatically released when no longer needed. -/// -struct MemoryAllocation { - MemoryAllocation(OrtAllocator* allocator, void* p, size_t size); - ~MemoryAllocation(); - MemoryAllocation(const MemoryAllocation&) = delete; - MemoryAllocation& operator=(const MemoryAllocation&) = delete; - MemoryAllocation(MemoryAllocation&&) noexcept; - MemoryAllocation& operator=(MemoryAllocation&&) noexcept; - - void* get() { return p_; } - size_t size() const { return size_; } - - private: - OrtAllocator* allocator_; - void* p_; - size_t size_; -}; - -namespace detail { -template -struct AllocatorImpl : Base { - using B = Base; - using B::B; - - void* Alloc(size_t size); - MemoryAllocation GetAllocation(size_t size); - void Free(void* p); - ConstMemoryInfo GetInfo() const; -}; - -} // namespace detail - -/** \brief Wrapper around ::OrtAllocator default instance that is owned by Onnxruntime - * - */ -struct AllocatorWithDefaultOptions : detail::AllocatorImpl> { - explicit AllocatorWithDefaultOptions(std::nullptr_t) {} ///< Convenience to create a class member and then replace with an instance - AllocatorWithDefaultOptions(); -}; - -/** \brief Wrapper around ::OrtAllocator - * - */ -struct Allocator : detail::AllocatorImpl { - explicit Allocator(std::nullptr_t) {} ///< Convenience to create a class member and then replace with an instance - Allocator(const Session& session, const OrtMemoryInfo*); -}; - -using UnownedAllocator = detail::AllocatorImpl>; - -namespace detail { -namespace binding_utils { -// Bring these out of template -std::vector GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator*); -std::vector GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator*); -} // namespace binding_utils - -template -struct ConstIoBindingImpl : Base { - using B = Base; - using B::B; - - std::vector GetOutputNames() const; - std::vector GetOutputNames(OrtAllocator*) const; - std::vector GetOutputValues() const; - std::vector GetOutputValues(OrtAllocator*) const; -}; - -template -struct IoBindingImpl : ConstIoBindingImpl { - using B = ConstIoBindingImpl; - using B::B; - - void BindInput(const char* name, const Value&); - void BindOutput(const char* name, const Value&); - void BindOutput(const char* name, const OrtMemoryInfo*); - void ClearBoundInputs(); - void ClearBoundOutputs(); - void SynchronizeInputs(); - void SynchronizeOutputs(); -}; - -} // namespace detail - -using ConstIoBinding = detail::ConstIoBindingImpl>; -using UnownedIoBinding = detail::IoBindingImpl>; - -/** \brief Wrapper around ::OrtIoBinding - * - */ -struct IoBinding : detail::IoBindingImpl { - explicit IoBinding(std::nullptr_t) {} ///< Create an empty object for convenience. Sometimes, we want to initialize members later. - explicit IoBinding(Session& session); - ConstIoBinding GetConst() const { return ConstIoBinding{this->p_}; } - UnownedIoBinding GetUnowned() const { return UnownedIoBinding{this->p_}; } -}; - -/*! \struct Ort::ArenaCfg - * \brief it is a structure that represents the configuration of an arena based allocator - * \details Please see docs/C_API.md for details - */ -struct ArenaCfg : detail::Base { - explicit ArenaCfg(std::nullptr_t) {} ///< Create an empty ArenaCfg object, must be assigned a valid one to be used - /** - * Wraps OrtApi::CreateArenaCfg - * \param max_mem - use 0 to allow ORT to choose the default - * \param arena_extend_strategy - use -1 to allow ORT to choose the default, 0 = kNextPowerOfTwo, 1 = kSameAsRequested - * \param initial_chunk_size_bytes - use -1 to allow ORT to choose the default - * \param max_dead_bytes_per_chunk - use -1 to allow ORT to choose the default - * See docs/C_API.md for details on what the following parameters mean and how to choose these values - */ - ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk); -}; - -// -// Custom OPs (only needed to implement custom OPs) -// - -/// -/// This struct provides life time management for custom op attribute -/// -struct OpAttr : detail::Base { - OpAttr(const char* name, const void* data, int len, OrtOpAttrType type); -}; - -/// -/// This class wraps a raw pointer OrtKernelContext* that is being passed -/// to the custom kernel Compute() method. Use it to safely access context -/// attributes, input and output parameters with exception safety guarantees. -/// See usage example in onnxruntime/test/testdata/custom_op_library/custom_op_library.cc -/// -struct KernelContext { - explicit KernelContext(OrtKernelContext* context); - size_t GetInputCount() const; - size_t GetOutputCount() const; - ConstValue GetInput(size_t index) const; - UnownedValue GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const; - UnownedValue GetOutput(size_t index, const std::vector& dims) const; - void* GetGPUComputeStream() const; - - private: - OrtKernelContext* ctx_; -}; - -struct KernelInfo; - -namespace detail { -namespace attr_utils { -void GetAttr(const OrtKernelInfo* p, const char* name, float&); -void GetAttr(const OrtKernelInfo* p, const char* name, int64_t&); -void GetAttr(const OrtKernelInfo* p, const char* name, std::string&); -void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector&); -void GetAttrs(const OrtKernelInfo* p, const char* name, std::vector&); -} // namespace attr_utils - -template -struct KernelInfoImpl : Base { - using B = Base; - using B::B; - - KernelInfo Copy() const; - - template // R is only implemented for float, int64_t, and string - R GetAttribute(const char* name) const { - R val; - attr_utils::GetAttr(this->p_, name, val); - return val; - } - - template // R is only implemented for std::vector, std::vector - std::vector GetAttributes(const char* name) const { - std::vector result; - attr_utils::GetAttrs(this->p_, name, result); - return result; - } - - Value GetTensorAttribute(const char* name, OrtAllocator* allocator) const; - - size_t GetInputCount() const; - size_t GetOutputCount() const; - - std::string GetInputName(size_t index) const; - std::string GetOutputName(size_t index) const; - - TypeInfo GetInputTypeInfo(size_t index) const; - TypeInfo GetOutputTypeInfo(size_t index) const; -}; - -} // namespace detail - -using ConstKernelInfo = detail::KernelInfoImpl>; - -/// -/// This struct owns the OrtKernInfo* pointer when a copy is made. -/// For convenient wrapping of OrtKernelInfo* passed to kernel constructor -/// and query attributes, warp the pointer with Ort::Unowned instance -/// so it does not destroy the pointer the kernel does not own. -/// -struct KernelInfo : detail::KernelInfoImpl { - explicit KernelInfo(std::nullptr_t) {} ///< Create an empty instance to initialize later - explicit KernelInfo(OrtKernelInfo* info); ///< Take ownership of the instance - ConstKernelInfo GetConst() const { return ConstKernelInfo{this->p_}; } -}; - -/// -/// Create and own custom defined operation. -/// -struct Op : detail::Base { - explicit Op(std::nullptr_t) {} ///< Create an empty Operator object, must be assigned a valid one to be used - - explicit Op(OrtOp*); ///< Take ownership of the OrtOp - - static Op Create(const OrtKernelInfo* info, const char* op_name, const char* domain, - int version, const char** type_constraint_names, - const ONNXTensorElementDataType* type_constraint_values, - size_t type_constraint_count, - const OpAttr* attr_values, - size_t attr_count, - size_t input_count, size_t output_count); - - void Invoke(const OrtKernelContext* context, - const Value* input_values, - size_t input_count, - Value* output_values, - size_t output_count); - - // For easier refactoring - void Invoke(const OrtKernelContext* context, - const OrtValue* const* input_values, - size_t input_count, - OrtValue* const* output_values, - size_t output_count); -}; - -/// -/// This entire structure is deprecated, but we not marking -/// it as a whole yet since we want to preserve for the next release. -/// -struct CustomOpApi { - CustomOpApi(const OrtApi& api) : api_(api) {} - - /** \deprecated use Ort::Value::GetTensorTypeAndShape() - * [[deprecated]] - * This interface produces a pointer that must be released. Not exception safe. - */ - [[deprecated("use Ort::Value::GetTensorTypeAndShape()")]] OrtTensorTypeAndShapeInfo* GetTensorTypeAndShape(_In_ const OrtValue* value); - - /** \deprecated use Ort::TensorTypeAndShapeInfo::GetElementCount() - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::TensorTypeAndShapeInfo::GetElementCount()")]] size_t GetTensorShapeElementCount(_In_ const OrtTensorTypeAndShapeInfo* info); - - /** \deprecated use Ort::TensorTypeAndShapeInfo::GetElementType() - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::TensorTypeAndShapeInfo::GetElementType()")]] ONNXTensorElementDataType GetTensorElementType(const OrtTensorTypeAndShapeInfo* info); - - /** \deprecated use Ort::TensorTypeAndShapeInfo::GetDimensionsCount() - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::TensorTypeAndShapeInfo::GetDimensionsCount()")]] size_t GetDimensionsCount(_In_ const OrtTensorTypeAndShapeInfo* info); - - /** \deprecated use Ort::TensorTypeAndShapeInfo::GetShape() - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::TensorTypeAndShapeInfo::GetShape()")]] void GetDimensions(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, size_t dim_values_length); - - /** \deprecated - * [[deprecated]] - * This interface sets dimensions to TensorTypeAndShapeInfo, but has no effect on the OrtValue. - */ - [[deprecated("Do not use")]] void SetDimensions(OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count); - - /** \deprecated use Ort::Value::GetTensorMutableData() - * [[deprecated]] - * This interface is redundant. - */ - template - [[deprecated("use Ort::Value::GetTensorMutableData()")]] T* GetTensorMutableData(_Inout_ OrtValue* value); - - /** \deprecated use Ort::Value::GetTensorData() - * [[deprecated]] - * This interface is redundant. - */ - template - [[deprecated("use Ort::Value::GetTensorData()")]] const T* GetTensorData(_Inout_ const OrtValue* value); - - /** \deprecated use Ort::Value::GetTensorMemoryInfo() - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::Value::GetTensorMemoryInfo()")]] const OrtMemoryInfo* GetTensorMemoryInfo(_In_ const OrtValue* value); - - /** \deprecated use Ort::TensorTypeAndShapeInfo::GetShape() - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::TensorTypeAndShapeInfo::GetShape()")]] std::vector GetTensorShape(const OrtTensorTypeAndShapeInfo* info); - - /** \deprecated use TensorTypeAndShapeInfo instances for automatic ownership. - * [[deprecated]] - * This interface is not exception safe. - */ - [[deprecated("use TensorTypeAndShapeInfo")]] void ReleaseTensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* input); - - /** \deprecated use Ort::KernelContext::GetInputCount - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::KernelContext::GetInputCount")]] size_t KernelContext_GetInputCount(const OrtKernelContext* context); - - /** \deprecated use Ort::KernelContext::GetInput - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::KernelContext::GetInput")]] const OrtValue* KernelContext_GetInput(const OrtKernelContext* context, _In_ size_t index); - - /** \deprecated use Ort::KernelContext::GetOutputCount - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::KernelContext::GetOutputCount")]] size_t KernelContext_GetOutputCount(const OrtKernelContext* context); - - /** \deprecated use Ort::KernelContext::GetOutput - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::KernelContext::GetOutput")]] OrtValue* KernelContext_GetOutput(OrtKernelContext* context, _In_ size_t index, _In_ const int64_t* dim_values, size_t dim_count); - - /** \deprecated use Ort::KernelContext::GetGPUComputeStream - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::KernelContext::GetGPUComputeStream")]] void* KernelContext_GetGPUComputeStream(const OrtKernelContext* context); - - /** \deprecated use Ort::ThrowOnError() - * [[deprecated]] - * This interface is redundant. - */ - [[deprecated("use Ort::ThrowOnError()")]] void ThrowOnError(OrtStatus* result); - - /** \deprecated use Ort::OpAttr - * [[deprecated]] - * This interface is not exception safe. - */ - [[deprecated("use Ort::OpAttr")]] OrtOpAttr* CreateOpAttr(_In_ const char* name, - _In_ const void* data, - _In_ int len, - _In_ OrtOpAttrType type); - - /** \deprecated use Ort::OpAttr - * [[deprecated]] - * This interface is not exception safe. - */ - [[deprecated("use Ort::OpAttr")]] void ReleaseOpAttr(_Frees_ptr_opt_ OrtOpAttr* op_attr); - - /** \deprecated use Ort::Op - * [[deprecated]] - * This interface is not exception safe. - */ - [[deprecated("use Ort::Op")]] OrtOp* CreateOp(_In_ const OrtKernelInfo* info, - _In_ const char* op_name, - _In_ const char* domain, - _In_ int version, - _In_opt_ const char** type_constraint_names, - _In_opt_ const ONNXTensorElementDataType* type_constraint_values, - _In_opt_ int type_constraint_count, - _In_opt_ const OrtOpAttr* const* attr_values, - _In_opt_ int attr_count, - _In_ int input_count, - _In_ int output_count); - - /** \deprecated use Ort::Op::Invoke - * [[deprecated]] - * This interface is redundant - */ - [[deprecated("use Ort::Op::Invoke")]] void InvokeOp(_In_ const OrtKernelContext* context, - _In_ const OrtOp* ort_op, - _In_ const OrtValue* const* input_values, - _In_ int input_count, - _Inout_ OrtValue* const* output_values, - _In_ int output_count); - - /** \deprecated use Ort::Op for automatic lifespan management. - * [[deprecated]] - * This interface is not exception safe. - */ - [[deprecated("use Ort::Op")]] void ReleaseOp(_Frees_ptr_opt_ OrtOp* ort_op); - - /** \deprecated use Ort::KernelInfo for automatic lifespan management or for - * querying attributes - * [[deprecated]] - * This interface is redundant - */ - template // T is only implemented for std::vector, std::vector, float, int64_t, and string - [[deprecated("use Ort::KernelInfo::GetAttribute")]] T KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name); - - /** \deprecated use Ort::KernelInfo::Copy - * querying attributes - * [[deprecated]] - * This interface is not exception safe - */ - [[deprecated("use Ort::KernelInfo::Copy")]] OrtKernelInfo* CopyKernelInfo(_In_ const OrtKernelInfo* info); - - /** \deprecated use Ort::KernelInfo for lifespan management - * querying attributes - * [[deprecated]] - * This interface is not exception safe - */ - [[deprecated("use Ort::KernelInfo")]] void ReleaseKernelInfo(_Frees_ptr_opt_ OrtKernelInfo* info_copy); - - private: - const OrtApi& api_; -}; - -template -struct CustomOpBase : OrtCustomOp { - CustomOpBase() { - OrtCustomOp::version = ORT_API_VERSION; - OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast(this_)->CreateKernel(*api, info); }; - OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast(this_)->GetName(); }; - - OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast(this_)->GetExecutionProviderType(); }; - - OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast(this_)->GetInputTypeCount(); }; - OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast(this_)->GetInputType(index); }; - OrtCustomOp::GetInputMemoryType = [](const OrtCustomOp* this_, size_t index) { return static_cast(this_)->GetInputMemoryType(index); }; - - OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast(this_)->GetOutputTypeCount(); }; - OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast(this_)->GetOutputType(index); }; - - OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) { static_cast(op_kernel)->Compute(context); }; -#if defined(_MSC_VER) && !defined(__clang__) -#pragma warning(push) -#pragma warning(disable : 26409) -#endif - OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast(op_kernel); }; -#if defined(_MSC_VER) && !defined(__clang__) -#pragma warning(pop) -#endif - OrtCustomOp::GetInputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast(this_)->GetInputCharacteristic(index); }; - OrtCustomOp::GetOutputCharacteristic = [](const OrtCustomOp* this_, size_t index) { return static_cast(this_)->GetOutputCharacteristic(index); }; - - OrtCustomOp::GetVariadicInputMinArity = [](const OrtCustomOp* this_) { return static_cast(this_)->GetVariadicInputMinArity(); }; - OrtCustomOp::GetVariadicInputHomogeneity = [](const OrtCustomOp* this_) { return static_cast(static_cast(this_)->GetVariadicInputHomogeneity()); }; - OrtCustomOp::GetVariadicOutputMinArity = [](const OrtCustomOp* this_) { return static_cast(this_)->GetVariadicOutputMinArity(); }; - OrtCustomOp::GetVariadicOutputHomogeneity = [](const OrtCustomOp* this_) { return static_cast(static_cast(this_)->GetVariadicOutputHomogeneity()); }; - } - - // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider - const char* GetExecutionProviderType() const { return nullptr; } - - // Default implementations of GetInputCharacteristic() and GetOutputCharacteristic() below - // (inputs and outputs are required by default) - OrtCustomOpInputOutputCharacteristic GetInputCharacteristic(size_t /*index*/) const { - return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED; - } - - OrtCustomOpInputOutputCharacteristic GetOutputCharacteristic(size_t /*index*/) const { - return OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_REQUIRED; - } - - // Default implemention of GetInputMemoryType() that returns OrtMemTypeDefault - OrtMemType GetInputMemoryType(size_t /*index*/) const { - return OrtMemTypeDefault; - } - - // Default implementation of GetVariadicInputMinArity() returns 1 to specify that a variadic input - // should expect at least 1 argument. - int GetVariadicInputMinArity() const { - return 1; - } - - // Default implementation of GetVariadicInputHomegeneity() returns true to specify that all arguments - // to a variadic input should be of the same type. - bool GetVariadicInputHomogeneity() const { - return true; - } - - // Default implementation of GetVariadicOutputMinArity() returns 1 to specify that a variadic output - // should produce at least 1 output value. - int GetVariadicOutputMinArity() const { - return 1; - } - - // Default implementation of GetVariadicOutputHomegeneity() returns true to specify that all output values - // produced by a variadic output should be of the same type. - bool GetVariadicOutputHomogeneity() const { - return true; - } - - // Declare list of session config entries used by this Custom Op. - // Implement this function in order to get configs from CustomOpBase::GetSessionConfigs(). - // This default implementation returns an empty vector of config entries. - std::vector GetSessionConfigKeys() const { - return std::vector{}; - } - - protected: - // Helper function that returns a map of session config entries specified by CustomOpBase::GetSessionConfigKeys. - void GetSessionConfigs(std::unordered_map& out, ConstSessionOptions options) const; -}; - -} // namespace Ort - -#include "onnxruntime_cxx_inline.h" diff --git a/lab/onnx/include/onnxruntime_cxx_inline.h b/lab/onnx/include/onnxruntime_cxx_inline.h deleted file mode 100644 index 6d391ad0..00000000 --- a/lab/onnx/include/onnxruntime_cxx_inline.h +++ /dev/null @@ -1,1874 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// Do not include this file directly. Please include "onnxruntime_cxx_api.h" instead. -// If interested in trying out features of the new experimental C++ API, include "experimental_onnxruntime_cxx_api.h" instead. -// -// These are the inline implementations of the C++ header APIs. They're in this separate file as to not clutter -// the main C++ file with implementation details. - -namespace Ort { - -namespace detail { -inline void ThrowStatus(const Status& st) { - std::string error_message = st.GetErrorMessage(); - OrtErrorCode error_code = st.GetErrorCode(); - ORT_CXX_API_THROW(std::move(error_message), error_code); -} -} // namespace detail - -inline void ThrowOnError(OrtStatus* ort_status) { - if (ort_status) { - Ort::Status st(ort_status); - detail::ThrowStatus(st); - } -} - -inline void ThrowOnError(const Status& st) { - if (st) { - detail::ThrowStatus(st); - } -} - -inline Status::Status(OrtStatus* status) : Base{status} { -} - -inline Status::Status(const std::exception& e) { - p_ = GetApi().CreateStatus(ORT_FAIL, e.what()); -} - -inline Status::Status(const Exception& e) { - p_ = GetApi().CreateStatus(e.GetOrtErrorCode(), e.what()); -} - -inline std::string Status::GetErrorMessage() const { - std::string message(GetApi().GetErrorMessage(p_)); - return message; -} - -inline OrtErrorCode Status::GetErrorCode() const { - return GetApi().GetErrorCode(p_); -} - -// This template converts a C++ type into it's ONNXTensorElementDataType -template -struct TypeToTensorType; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64; -}; -template <> -struct TypeToTensorType { - static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL; -}; - -inline MemoryAllocation::MemoryAllocation(OrtAllocator* allocator, void* p, size_t size) - : allocator_(allocator), p_(p), size_(size) { -} - -inline MemoryAllocation::~MemoryAllocation() { - if (p_ != nullptr) { - // We do not throw out of destructor - auto ret = GetApi().AllocatorFree(allocator_, p_); - static_cast(ret); - } -} - -inline MemoryAllocation::MemoryAllocation(MemoryAllocation&& o) noexcept : allocator_(nullptr), p_(nullptr), size_(0) { - *this = std::move(o); -} - -inline MemoryAllocation& MemoryAllocation::operator=(MemoryAllocation&& o) noexcept { - OrtAllocator* alloc = nullptr; - void* p = nullptr; - size_t sz = 0; - - // Swap out this - std::swap(alloc, allocator_); - std::swap(p, p_); - std::swap(sz, size_); - - // Swap with incoming - std::swap(allocator_, o.allocator_); - std::swap(p_, o.p_); - std::swap(size_, o.size_); - - // Destroy this instance if needed - MemoryAllocation this_alloc(alloc, p, sz); - return *this; -} - -namespace detail { - -template -inline void* AllocatorImpl::Alloc(size_t size) { - void* out; - ThrowOnError(GetApi().AllocatorAlloc(this->p_, size, &out)); - return out; -} - -template -inline MemoryAllocation AllocatorImpl::GetAllocation(size_t size) { - void* out; - ThrowOnError(GetApi().AllocatorAlloc(this->p_, size, &out)); - MemoryAllocation result(this->p_, out, size); - return result; -} - -template -inline void AllocatorImpl::Free(void* p) { - ThrowOnError(GetApi().AllocatorFree(this->p_, p)); -} - -template -inline ConstMemoryInfo AllocatorImpl::GetInfo() const { - const OrtMemoryInfo* out; - ThrowOnError(GetApi().AllocatorGetInfo(this->p_, &out)); - return ConstMemoryInfo{out}; -} - -} // namespace detail - -inline AllocatorWithDefaultOptions::AllocatorWithDefaultOptions() { - ThrowOnError(GetApi().GetAllocatorWithDefaultOptions(&this->p_)); -} - -inline Allocator::Allocator(const Session& sess, const OrtMemoryInfo* mem_info) { - ThrowOnError(GetApi().CreateAllocator(sess, mem_info, &this->p_)); -} - -namespace detail { - -template -inline std::string MemoryInfoImpl::GetAllocatorName() const { - const char* name = nullptr; - ThrowOnError(GetApi().MemoryInfoGetName(this->p_, &name)); - return std::string(name); -} - -template -inline OrtAllocatorType MemoryInfoImpl::GetAllocatorType() const { - OrtAllocatorType type; - ThrowOnError(GetApi().MemoryInfoGetType(this->p_, &type)); - return type; -} - -template -inline int MemoryInfoImpl::GetDeviceId() const { - int id = 0; - ThrowOnError(GetApi().MemoryInfoGetId(this->p_, &id)); - return id; -} - -template -inline OrtMemoryInfoDeviceType MemoryInfoImpl::GetDeviceType() const { - OrtMemoryInfoDeviceType type; - GetApi().MemoryInfoGetDeviceType(this->p_, &type); - return type; -} - -template -inline OrtMemType MemoryInfoImpl::GetMemoryType() const { - OrtMemType type; - ThrowOnError(GetApi().MemoryInfoGetMemType(this->p_, &type)); - return type; -} - -template -template -inline bool MemoryInfoImpl::operator==(const MemoryInfoImpl& o) const { - int comp_result = 0; - ThrowOnError(Ort::GetApi().CompareMemoryInfo(this->p_, o, &comp_result)); - return comp_result == 0; -} - -} // namespace detail - -inline MemoryInfo MemoryInfo::CreateCpu(OrtAllocatorType type, OrtMemType mem_type) { - OrtMemoryInfo* p; - ThrowOnError(GetApi().CreateCpuMemoryInfo(type, mem_type, &p)); - return MemoryInfo(p); -} - -inline MemoryInfo::MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type) { - ThrowOnError(GetApi().CreateMemoryInfo(name, type, id, mem_type, &this->p_)); -} - -namespace detail { -template -inline std::vector ConstIoBindingImpl::GetOutputNames() const { - AllocatorWithDefaultOptions allocator; - return binding_utils::GetOutputNamesHelper(this->p_, allocator); -} - -template -inline std::vector ConstIoBindingImpl::GetOutputNames(OrtAllocator* allocator) const { - return binding_utils::GetOutputNamesHelper(this->p_, allocator); -} - -template -inline std::vector ConstIoBindingImpl::GetOutputValues() const { - AllocatorWithDefaultOptions allocator; - return binding_utils::GetOutputValuesHelper(this->p_, allocator); -} - -template -inline std::vector ConstIoBindingImpl::GetOutputValues(OrtAllocator* allocator) const { - return binding_utils::GetOutputValuesHelper(this->p_, allocator); -} - -template -inline void IoBindingImpl::BindInput(const char* name, const Value& value) { - ThrowOnError(GetApi().BindInput(this->p_, name, value)); -} - -template -inline void IoBindingImpl::BindOutput(const char* name, const Value& value) { - ThrowOnError(GetApi().BindOutput(this->p_, name, value)); -} - -template -inline void IoBindingImpl::BindOutput(const char* name, const OrtMemoryInfo* mem_info) { - ThrowOnError(GetApi().BindOutputToDevice(this->p_, name, mem_info)); -} - -template -inline void IoBindingImpl::ClearBoundInputs() { - GetApi().ClearBoundInputs(this->p_); -} - -template -inline void IoBindingImpl::ClearBoundOutputs() { - GetApi().ClearBoundOutputs(this->p_); -} - -template -inline void IoBindingImpl::SynchronizeInputs() { - ThrowOnError(GetApi().SynchronizeBoundInputs(this->p_)); -} - -template -inline void IoBindingImpl::SynchronizeOutputs() { - ThrowOnError(GetApi().SynchronizeBoundOutputs(this->p_)); -} - -namespace binding_utils { -inline std::vector GetOutputNamesHelper(const OrtIoBinding* binding, OrtAllocator* allocator) { - std::vector result; - auto free_fn = detail::AllocatedFree(allocator); - using Ptr = std::unique_ptr; - - char* buffer = nullptr; - size_t* lengths = nullptr; - size_t count = 0; - ThrowOnError(GetApi().GetBoundOutputNames(binding, allocator, &buffer, &lengths, &count)); - - if (count == 0) { - return result; - } - - Ptr buffer_g(buffer, free_fn); - Ptr lengths_g(lengths, free_fn); - - result.reserve(count); - for (size_t i = 0; i < count; ++i) { - auto sz = *lengths; - result.emplace_back(buffer, sz); - buffer += sz; - ++lengths; - } - return result; -} - -inline std::vector GetOutputValuesHelper(const OrtIoBinding* binding, OrtAllocator* allocator) { - std::vector result; - size_t owned = 0; - size_t output_count = 0; - // Lambda to release the buffer when no longer needed and - // make sure that we destroy all instances on exception - auto free_fn = [&owned, &output_count, allocator](OrtValue** buffer) { - if (buffer) { - while (owned < output_count) { - auto* p = buffer + owned++; - GetApi().ReleaseValue(*p); - } - allocator->Free(allocator, buffer); - } - }; - using Ptr = std::unique_ptr; - - OrtValue** output_buffer = nullptr; - ThrowOnError(GetApi().GetBoundOutputValues(binding, allocator, &output_buffer, &output_count)); - if (output_count == 0) { - return result; - } - - Ptr buffer_g(output_buffer, free_fn); - - result.reserve(output_count); - for (size_t i = 0; i < output_count; ++i) { - result.emplace_back(output_buffer[i]); - ++owned; - } - return result; -} - -} // namespace binding_utils -} // namespace detail - -inline IoBinding::IoBinding(Session& session) { - ThrowOnError(GetApi().CreateIoBinding(session, &this->p_)); -} - -inline ArenaCfg::ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk) { - ThrowOnError(GetApi().CreateArenaCfg(max_mem, arena_extend_strategy, initial_chunk_size_bytes, max_dead_bytes_per_chunk, &p_)); -} - -inline ThreadingOptions::ThreadingOptions() { - ThrowOnError(GetApi().CreateThreadingOptions(&p_)); -} - -inline ThreadingOptions& ThreadingOptions::SetGlobalIntraOpNumThreads(int intra_op_num_threads) { - ThrowOnError(GetApi().SetGlobalIntraOpNumThreads(p_, intra_op_num_threads)); - return *this; -} - -inline ThreadingOptions& ThreadingOptions::SetGlobalInterOpNumThreads(int inter_op_num_threads) { - ThrowOnError(GetApi().SetGlobalInterOpNumThreads(p_, inter_op_num_threads)); - return *this; -} - -inline ThreadingOptions& ThreadingOptions::SetGlobalSpinControl(int allow_spinning) { - ThrowOnError(GetApi().SetGlobalSpinControl(p_, allow_spinning)); - return *this; -} - -inline ThreadingOptions& ThreadingOptions::SetGlobalDenormalAsZero() { - ThrowOnError(GetApi().SetGlobalDenormalAsZero(p_)); - return *this; -} - -inline ThreadingOptions& ThreadingOptions::SetGlobalCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn) { - ThrowOnError(GetApi().SetGlobalCustomCreateThreadFn(p_, ort_custom_create_thread_fn)); - return *this; -} - -inline ThreadingOptions& ThreadingOptions::SetGlobalCustomThreadCreationOptions(void* ort_custom_thread_creation_options) { - ThrowOnError(GetApi().SetGlobalCustomThreadCreationOptions(p_, ort_custom_thread_creation_options)); - return *this; -} - -inline ThreadingOptions& ThreadingOptions::SetGlobalCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn) { - ThrowOnError(GetApi().SetGlobalCustomJoinThreadFn(p_, ort_custom_join_thread_fn)); - return *this; -} - -inline Env::Env(OrtLoggingLevel logging_level, _In_ const char* logid) { - ThrowOnError(GetApi().CreateEnv(logging_level, logid, &p_)); - if (strcmp(logid, "onnxruntime-node") == 0) { - ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_NODEJS)); - } else { - ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_CPLUSPLUS)); - } -} - -inline Env::Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param) { - ThrowOnError(GetApi().CreateEnvWithCustomLogger(logging_function, logger_param, logging_level, logid, &p_)); - if (strcmp(logid, "onnxruntime-node") == 0) { - ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_NODEJS)); - } else { - ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_CPLUSPLUS)); - } -} - -inline Env::Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level, _In_ const char* logid) { - ThrowOnError(GetApi().CreateEnvWithGlobalThreadPools(logging_level, logid, tp_options, &p_)); - if (strcmp(logid, "onnxruntime-node") == 0) { - ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_NODEJS)); - } else { - ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_CPLUSPLUS)); - } -} - -inline Env::Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param, - OrtLoggingLevel logging_level, _In_ const char* logid) { - ThrowOnError(GetApi().CreateEnvWithCustomLoggerAndGlobalThreadPools(logging_function, logger_param, logging_level, logid, tp_options, &p_)); - if (strcmp(logid, "onnxruntime-node") == 0) { - ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_NODEJS)); - } else { - ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_CPLUSPLUS)); - } -} - -inline Env& Env::EnableTelemetryEvents() { - ThrowOnError(GetApi().EnableTelemetryEvents(p_)); - return *this; -} - -inline Env& Env::DisableTelemetryEvents() { - ThrowOnError(GetApi().DisableTelemetryEvents(p_)); - return *this; -} - -inline Env& Env::UpdateEnvWithCustomLogLevel(OrtLoggingLevel log_severity_level) { - ThrowOnError(GetApi().UpdateEnvWithCustomLogLevel(p_, log_severity_level)); - return *this; -} - -inline Env& Env::CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg) { - ThrowOnError(GetApi().CreateAndRegisterAllocator(p_, mem_info, arena_cfg)); - return *this; -} - -inline CustomOpDomain::CustomOpDomain(const char* domain) { - ThrowOnError(GetApi().CreateCustomOpDomain(domain, &p_)); -} - -inline void CustomOpDomain::Add(const OrtCustomOp* op) { - ThrowOnError(GetApi().CustomOpDomain_Add(p_, op)); -} - -inline RunOptions::RunOptions() { - ThrowOnError(GetApi().CreateRunOptions(&p_)); -} - -inline RunOptions& RunOptions::SetRunLogVerbosityLevel(int level) { - ThrowOnError(GetApi().RunOptionsSetRunLogVerbosityLevel(p_, level)); - return *this; -} - -inline RunOptions& RunOptions::SetRunLogSeverityLevel(int level) { - ThrowOnError(GetApi().RunOptionsSetRunLogSeverityLevel(p_, level)); - return *this; -} - -inline int RunOptions::GetRunLogVerbosityLevel() const { - int out; - ThrowOnError(GetApi().RunOptionsGetRunLogVerbosityLevel(p_, &out)); - return out; -} - -inline int RunOptions::GetRunLogSeverityLevel() const { - int out; - ThrowOnError(GetApi().RunOptionsGetRunLogSeverityLevel(p_, &out)); - return out; -} - -inline RunOptions& RunOptions::SetRunTag(const char* run_tag) { - ThrowOnError(GetApi().RunOptionsSetRunTag(p_, run_tag)); - return *this; -} - -inline const char* RunOptions::GetRunTag() const { - const char* out; - ThrowOnError(GetApi().RunOptionsGetRunTag(p_, &out)); - return out; -} - -inline RunOptions& RunOptions::AddConfigEntry(const char* config_key, const char* config_value) { - ThrowOnError(GetApi().AddRunConfigEntry(p_, config_key, config_value)); - return *this; -} - -inline RunOptions& RunOptions::SetTerminate() { - ThrowOnError(GetApi().RunOptionsSetTerminate(p_)); - return *this; -} - -inline RunOptions& RunOptions::UnsetTerminate() { - ThrowOnError(GetApi().RunOptionsUnsetTerminate(p_)); - return *this; -} - -namespace detail { - -template -inline Ort::SessionOptions ConstSessionOptionsImpl::Clone() const { - OrtSessionOptions* out; - ThrowOnError(GetApi().CloneSessionOptions(this->p_, &out)); - return SessionOptions{out}; -} - -template -inline std::string ConstSessionOptionsImpl::GetConfigEntry(const char* config_key) const { - size_t size = 0; - // Feed nullptr for the data buffer to query the true size of the string value - Ort::ThrowOnError(GetApi().GetSessionConfigEntry(this->p_, config_key, nullptr, &size)); - - std::string out; - out.resize(size); - Ort::ThrowOnError(GetApi().GetSessionConfigEntry(this->p_, config_key, &out[0], &size)); - out.resize(size - 1); // remove the terminating character '\0' - - return out; -} - -template -inline bool ConstSessionOptionsImpl::HasConfigEntry(const char* config_key) const { - int out = 0; - Ort::ThrowOnError(GetApi().HasSessionConfigEntry(this->p_, config_key, &out)); - return static_cast(out); -} - -template -inline std::string ConstSessionOptionsImpl::GetConfigEntryOrDefault(const char* config_key, const std::string& def) { - if (!this->HasConfigEntry(config_key)) { - return def; - } - - return this->GetConfigEntry(config_key); -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetIntraOpNumThreads(int intra_op_num_threads) { - ThrowOnError(GetApi().SetIntraOpNumThreads(this->p_, intra_op_num_threads)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetInterOpNumThreads(int inter_op_num_threads) { - ThrowOnError(GetApi().SetInterOpNumThreads(this->p_, inter_op_num_threads)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level) { - ThrowOnError(GetApi().SetSessionGraphOptimizationLevel(this->p_, graph_optimization_level)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_filepath) { - ThrowOnError(GetApi().SetOptimizedModelFilePath(this->p_, optimized_model_filepath)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::EnableProfiling(const ORTCHAR_T* profile_file_prefix) { - ThrowOnError(GetApi().EnableProfiling(this->p_, profile_file_prefix)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::DisableProfiling() { - ThrowOnError(GetApi().DisableProfiling(this->p_)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::EnableOrtCustomOps() { - ThrowOnError(GetApi().EnableOrtCustomOps(this->p_)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::EnableMemPattern() { - ThrowOnError(GetApi().EnableMemPattern(this->p_)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::DisableMemPattern() { - ThrowOnError(GetApi().DisableMemPattern(this->p_)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::EnableCpuMemArena() { - ThrowOnError(GetApi().EnableCpuMemArena(this->p_)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::DisableCpuMemArena() { - ThrowOnError(GetApi().DisableCpuMemArena(this->p_)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetExecutionMode(ExecutionMode execution_mode) { - ThrowOnError(GetApi().SetSessionExecutionMode(this->p_, execution_mode)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetLogId(const char* logid) { - ThrowOnError(GetApi().SetSessionLogId(this->p_, logid)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetLogSeverityLevel(int level) { - ThrowOnError(GetApi().SetSessionLogSeverityLevel(this->p_, level)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::Add(OrtCustomOpDomain* custom_op_domain) { - ThrowOnError(GetApi().AddCustomOpDomain(this->p_, custom_op_domain)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AddConfigEntry(const char* config_key, const char* config_value) { - ThrowOnError(GetApi().AddSessionConfigEntry(this->p_, config_key, config_value)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AddInitializer(const char* name, const OrtValue* ort_val) { - ThrowOnError(GetApi().AddInitializer(this->p_, name, ort_val)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::DisablePerSessionThreads() { - ThrowOnError(GetApi().DisablePerSessionThreads(this->p_)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AddExternalInitializers(const std::vector& names, - const std::vector& ort_values) { - const size_t inputs_num = names.size(); - if (inputs_num != ort_values.size()) { - ORT_CXX_API_THROW("Expecting names and ort_values to have the same length", ORT_INVALID_ARGUMENT); - } - std::vector names_ptr; - std::vector ort_values_ptrs; - names_ptr.reserve(inputs_num); - ort_values_ptrs.reserve(inputs_num); - for (size_t i = 0; i < inputs_num; ++i) { - names_ptr.push_back(names[i].c_str()); - ort_values_ptrs.push_back(ort_values[i]); - } - ThrowOnError(GetApi().AddExternalInitializers(this->p_, names_ptr.data(), ort_values_ptrs.data(), inputs_num)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options) { - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_CUDA(this->p_, &provider_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider_CUDA_V2(const OrtCUDAProviderOptionsV2& provider_options) { - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_CUDA_V2(this->p_, &provider_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider_ROCM(const OrtROCMProviderOptions& provider_options) { - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_ROCM(this->p_, &provider_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider_TensorRT(const OrtTensorRTProviderOptions& provider_options) { - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_TensorRT(this->p_, &provider_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider_TensorRT_V2(const OrtTensorRTProviderOptionsV2& provider_options) { - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_TensorRT_V2(this->p_, &provider_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider_MIGraphX(const OrtMIGraphXProviderOptions& provider_options) { - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_MIGraphX(this->p_, &provider_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider_CANN(const OrtCANNProviderOptions& provider_options) { - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_CANN(this->p_, &provider_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider( - const std::string& provider_name, - const std::unordered_map& provider_options) { - auto num_entries = provider_options.size(); - std::vector keys, values; - if (num_entries > 0) { - keys.reserve(num_entries); - values.reserve(num_entries); - - for (const auto& entry : provider_options) { - keys.push_back(entry.first.c_str()); - values.push_back(entry.second.c_str()); - } - } - - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider(this->p_, provider_name.c_str(), - keys.data(), values.data(), num_entries)); - - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetCustomCreateThreadFn(OrtCustomCreateThreadFn ort_custom_create_thread_fn) { - ThrowOnError(GetApi().SessionOptionsSetCustomCreateThreadFn(this->p_, ort_custom_create_thread_fn)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetCustomThreadCreationOptions(void* ort_custom_thread_creation_options) { - ThrowOnError(GetApi().SessionOptionsSetCustomThreadCreationOptions(this->p_, ort_custom_thread_creation_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::SetCustomJoinThreadFn(OrtCustomJoinThreadFn ort_custom_join_thread_fn) { - ThrowOnError(GetApi().SessionOptionsSetCustomJoinThreadFn(this->p_, ort_custom_join_thread_fn)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options) { - ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_OpenVINO(this->p_, &provider_options)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::RegisterCustomOpsLibrary(const ORTCHAR_T* library_name, - const CustomOpConfigs& custom_op_configs) { - // Add custom op config entries before registering the custom op library. Otherwise, the config entries _may_ be ignored by - // the custom op library. - for (const auto& config_iter : custom_op_configs.GetFlattenedConfigs()) { - AddConfigEntry(config_iter.first.c_str(), config_iter.second.c_str()); - } - - ThrowOnError(GetApi().RegisterCustomOpsLibrary_V2(this->p_, library_name)); - return *this; -} - -template -inline SessionOptionsImpl& SessionOptionsImpl::RegisterCustomOpsUsingFunction(const char* registration_function_name) { - ThrowOnError(GetApi().RegisterCustomOpsUsingFunction(this->p_, registration_function_name)); - return *this; -} - -/// Session -template -inline size_t ConstSessionImpl::GetInputCount() const { - size_t out; - ThrowOnError(GetApi().SessionGetInputCount(this->p_, &out)); - return out; -} - -template -inline size_t ConstSessionImpl::GetOutputCount() const { - size_t out; - ThrowOnError(GetApi().SessionGetOutputCount(this->p_, &out)); - return out; -} - -template -inline size_t ConstSessionImpl::GetOverridableInitializerCount() const { - size_t out; - ThrowOnError(GetApi().SessionGetOverridableInitializerCount(this->p_, &out)); - return out; -} - -template -inline AllocatedStringPtr ConstSessionImpl::GetInputNameAllocated(size_t index, OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().SessionGetInputName(this->p_, index, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -template -inline AllocatedStringPtr ConstSessionImpl::GetOutputNameAllocated(size_t index, OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().SessionGetOutputName(this->p_, index, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -template -inline AllocatedStringPtr ConstSessionImpl::GetOverridableInitializerNameAllocated(size_t index, OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().SessionGetOverridableInitializerName(this->p_, index, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -template -inline uint64_t ConstSessionImpl::GetProfilingStartTimeNs() const { - uint64_t out; - ThrowOnError(GetApi().SessionGetProfilingStartTimeNs(this->p_, &out)); - return out; -} - -template -inline ModelMetadata ConstSessionImpl::GetModelMetadata() const { - OrtModelMetadata* out; - ThrowOnError(GetApi().SessionGetModelMetadata(this->p_, &out)); - return ModelMetadata{out}; -} - -template -inline TypeInfo ConstSessionImpl::GetInputTypeInfo(size_t index) const { - OrtTypeInfo* out; - ThrowOnError(GetApi().SessionGetInputTypeInfo(this->p_, index, &out)); - return TypeInfo{out}; -} - -template -inline TypeInfo ConstSessionImpl::GetOutputTypeInfo(size_t index) const { - OrtTypeInfo* out; - ThrowOnError(GetApi().SessionGetOutputTypeInfo(this->p_, index, &out)); - return TypeInfo{out}; -} - -template -inline TypeInfo ConstSessionImpl::GetOverridableInitializerTypeInfo(size_t index) const { - OrtTypeInfo* out; - ThrowOnError(GetApi().SessionGetOverridableInitializerTypeInfo(this->p_, index, &out)); - return TypeInfo{out}; -} - -template -inline std::vector SessionImpl::Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count, - const char* const* output_names, size_t output_count) { - std::vector output_values; - output_values.reserve(output_count); - for (size_t i = 0; i < output_count; i++) - output_values.emplace_back(nullptr); - Run(run_options, input_names, input_values, input_count, output_names, output_values.data(), output_count); - return output_values; -} - -template -inline void SessionImpl::Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count, - const char* const* output_names, Value* output_values, size_t output_count) { - static_assert(sizeof(Value) == sizeof(OrtValue*), "Value is really just an array of OrtValue* in memory, so we can reinterpret_cast safely"); - auto ort_input_values = reinterpret_cast(input_values); - auto ort_output_values = reinterpret_cast(output_values); - ThrowOnError(GetApi().Run(this->p_, run_options, input_names, ort_input_values, input_count, output_names, output_count, ort_output_values)); -} - -template -inline void SessionImpl::Run(const RunOptions& run_options, const IoBinding& io_binding) { - ThrowOnError(GetApi().RunWithBinding(this->p_, run_options, io_binding)); -} - -template -inline AllocatedStringPtr SessionImpl::EndProfilingAllocated(OrtAllocator* allocator) { - char* out = nullptr; - ThrowOnError(GetApi().SessionEndProfiling(this->p_, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -} // namespace detail - -inline SessionOptions::SessionOptions() { - ThrowOnError(GetApi().CreateSessionOptions(&this->p_)); -} - -/// CustomOpConfigs -inline std::string detail::MakeCustomOpConfigEntryKey(const char* custom_op_name, const char* config) { - std::string config_key = "custom_op."; - - config_key += custom_op_name; - config_key += "."; - config_key += config; - - return config_key; -} - -inline CustomOpConfigs& CustomOpConfigs::AddConfig(const char* custom_op_name, const char* config_key, const char* config_value) { - const std::string full_flat_key = detail::MakeCustomOpConfigEntryKey(custom_op_name, config_key); - flat_configs_[full_flat_key] = config_value; - return *this; -} - -inline const std::unordered_map& CustomOpConfigs::GetFlattenedConfigs() const { - return flat_configs_; -} - -inline Session::Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options) { - ThrowOnError(GetApi().CreateSession(env, model_path, options, &this->p_)); -} - -inline Session::Session(const Env& env, const ORTCHAR_T* model_path, const SessionOptions& options, - OrtPrepackedWeightsContainer* prepacked_weights_container) { - ThrowOnError(GetApi().CreateSessionWithPrepackedWeightsContainer(env, model_path, options, prepacked_weights_container, &this->p_)); -} - -inline Session::Session(const Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options) { - ThrowOnError(GetApi().CreateSessionFromArray(env, model_data, model_data_length, options, &this->p_)); -} - -inline Session::Session(const Env& env, const void* model_data, size_t model_data_length, - const SessionOptions& options, OrtPrepackedWeightsContainer* prepacked_weights_container) { - ThrowOnError(GetApi().CreateSessionFromArrayWithPrepackedWeightsContainer(env, model_data, model_data_length, options, - prepacked_weights_container, &this->p_)); -} - -inline AllocatedStringPtr ModelMetadata::GetProducerNameAllocated(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetProducerName(p_, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -inline AllocatedStringPtr ModelMetadata::GetGraphNameAllocated(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetGraphName(p_, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -inline AllocatedStringPtr ModelMetadata::GetDomainAllocated(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetDomain(p_, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -inline AllocatedStringPtr Ort::ModelMetadata::GetDescriptionAllocated(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetDescription(p_, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -inline AllocatedStringPtr ModelMetadata::GetGraphDescriptionAllocated(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetGraphDescription(p_, allocator, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -inline AllocatedStringPtr ModelMetadata::LookupCustomMetadataMapAllocated(const char* key, OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataLookupCustomMetadataMap(p_, allocator, key, &out)); - return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); -} - -inline std::vector ModelMetadata::GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const { - auto deletor = detail::AllocatedFree(allocator); - std::vector result; - - char** out = nullptr; - int64_t num_keys = 0; - ThrowOnError(GetApi().ModelMetadataGetCustomMetadataMapKeys(p_, allocator, &out, &num_keys)); - if (num_keys <= 0) { - return result; - } - - // array of pointers will be freed - std::unique_ptr array_guard(out, deletor); - // reserve may throw - auto strings_deletor = [&deletor, num_keys](char** out) { for(int64_t i = 0; i < num_keys; ++i) deletor(out[i]); }; - std::unique_ptr strings_guard(out, strings_deletor); - result.reserve(static_cast(num_keys)); - strings_guard.release(); - for (int64_t i = 0; i < num_keys; ++i) { - result.push_back(AllocatedStringPtr(out[i], deletor)); - } - - return result; -} - -inline int64_t ModelMetadata::GetVersion() const { - int64_t out; - ThrowOnError(GetApi().ModelMetadataGetVersion(p_, &out)); - return out; -} - -namespace detail { - -template -inline ONNXTensorElementDataType TensorTypeAndShapeInfoImpl::GetElementType() const { - ONNXTensorElementDataType out; - ThrowOnError(GetApi().GetTensorElementType(this->p_, &out)); - return out; -} - -template -inline size_t TensorTypeAndShapeInfoImpl::GetElementCount() const { - size_t out; - ThrowOnError(GetApi().GetTensorShapeElementCount(this->p_, &out)); - return static_cast(out); -} - -template -inline size_t TensorTypeAndShapeInfoImpl::GetDimensionsCount() const { - size_t out; - ThrowOnError(GetApi().GetDimensionsCount(this->p_, &out)); - return out; -} - -template -inline void TensorTypeAndShapeInfoImpl::GetDimensions(int64_t* values, size_t values_count) const { - ThrowOnError(GetApi().GetDimensions(this->p_, values, values_count)); -} - -template -inline void TensorTypeAndShapeInfoImpl::GetSymbolicDimensions(const char** values, size_t values_count) const { - ThrowOnError(GetApi().GetSymbolicDimensions(this->p_, values, values_count)); -} - -template -inline std::vector TensorTypeAndShapeInfoImpl::GetShape() const { - std::vector out(GetDimensionsCount(), 0); - ThrowOnError(GetApi().GetDimensions(this->p_, out.data(), out.size())); - return out; -} - -} // namespace detail - -namespace detail { -template -inline ConstTensorTypeAndShapeInfo TypeInfoImpl::GetTensorTypeAndShapeInfo() const { - const OrtTensorTypeAndShapeInfo* out; - ThrowOnError(GetApi().CastTypeInfoToTensorInfo(this->p_, &out)); - return ConstTensorTypeAndShapeInfo{out}; -} - -template -inline ConstSequenceTypeInfo TypeInfoImpl::GetSequenceTypeInfo() const { - const OrtSequenceTypeInfo* out; - ThrowOnError(GetApi().CastTypeInfoToSequenceTypeInfo(this->p_, &out)); - return ConstSequenceTypeInfo{out}; -} - -template -inline ConstMapTypeInfo TypeInfoImpl::GetMapTypeInfo() const { - const OrtMapTypeInfo* out; - ThrowOnError(GetApi().CastTypeInfoToMapTypeInfo(this->p_, &out)); - return ConstMapTypeInfo{out}; -} - -template -inline ONNXType TypeInfoImpl::GetONNXType() const { - ONNXType out; - ThrowOnError(GetApi().GetOnnxTypeFromTypeInfo(this->p_, &out)); - return out; -} - -} // namespace detail - -namespace detail { -template -inline TypeInfo SequenceTypeInfoImpl::GetSequenceElementType() const { - OrtTypeInfo* output; - ThrowOnError(GetApi().GetSequenceElementType(this->p_, &output)); - return TypeInfo{output}; -} - -} // namespace detail - -namespace detail { -template -inline ONNXTensorElementDataType MapTypeInfoImpl::GetMapKeyType() const { - ONNXTensorElementDataType out; - ThrowOnError(GetApi().GetMapKeyType(this->p_, &out)); - return out; -} - -template -inline TypeInfo MapTypeInfoImpl::GetMapValueType() const { - OrtTypeInfo* output; - ThrowOnError(GetApi().GetMapValueType(this->p_, &output)); - return TypeInfo{output}; -} -} // namespace detail - -namespace detail { - -template -template -inline void ConstValueImpl::GetOpaqueData(const char* domain, const char* type_name, R& out) const { - ThrowOnError(GetApi().GetOpaqueValue(domain, type_name, this->p_, &out, sizeof(R))); -} - -template -inline bool ConstValueImpl::IsTensor() const { - int out; - ThrowOnError(GetApi().IsTensor(this->p_, &out)); - return out != 0; -} - -template -inline bool ConstValueImpl::HasValue() const { - int out; - ThrowOnError(GetApi().HasValue(this->p_, &out)); - return out != 0; -} - -template -inline size_t ConstValueImpl::GetCount() const { - size_t out; - ThrowOnError(GetApi().GetValueCount(this->p_, &out)); - return out; -} - -template -inline Value ConstValueImpl::GetValue(int index, OrtAllocator* allocator) const { - OrtValue* out; - ThrowOnError(GetApi().GetValue(this->p_, index, allocator, &out)); - return Value{out}; -} - -template -inline size_t ConstValueImpl::GetStringTensorDataLength() const { - size_t out; - ThrowOnError(GetApi().GetStringTensorDataLength(this->p_, &out)); - return out; -} - -template -inline size_t ConstValueImpl::GetStringTensorElementLength(size_t element_index) const { - size_t out; - ThrowOnError(GetApi().GetStringTensorElementLength(this->p_, element_index, &out)); - return out; -} - -template -template -inline const R* ConstValueImpl::GetTensorData() const { - R* out; - ThrowOnError(GetApi().GetTensorMutableData(const_cast(this->p_), (void**)&out)); - return out; -} - -template -inline const void* ConstValueImpl::GetTensorRawData() const { - void* out; - ThrowOnError(GetApi().GetTensorMutableData(const_cast(this->p_), &out)); - return out; -} - -template -inline TypeInfo ConstValueImpl::GetTypeInfo() const { - OrtTypeInfo* output; - ThrowOnError(GetApi().GetTypeInfo(this->p_, &output)); - return TypeInfo{output}; -} - -template -inline TensorTypeAndShapeInfo ConstValueImpl::GetTensorTypeAndShapeInfo() const { - OrtTensorTypeAndShapeInfo* output; - ThrowOnError(GetApi().GetTensorTypeAndShape(this->p_, &output)); - return TensorTypeAndShapeInfo{output}; -} - -template -inline ConstMemoryInfo ConstValueImpl::GetTensorMemoryInfo() const { - const OrtMemoryInfo* mem_info; - ThrowOnError(GetApi().GetTensorMemoryInfo(this->p_, &mem_info)); - return ConstMemoryInfo(mem_info); -} - -template -inline void ConstValueImpl::GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const { - ThrowOnError(GetApi().GetStringTensorElement(this->p_, buffer_length, element_index, buffer)); -} - -template -inline void ConstValueImpl::GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const { - ThrowOnError(GetApi().GetStringTensorContent(this->p_, buffer, buffer_length, offsets, offsets_count)); -} - -#if !defined(DISABLE_SPARSE_TENSORS) -template -inline OrtSparseFormat ConstValueImpl::GetSparseFormat() const { - OrtSparseFormat format; - ThrowOnError(GetApi().GetSparseTensorFormat(this->p_, &format)); - return format; -} - -template -inline TensorTypeAndShapeInfo ConstValueImpl::GetSparseTensorValuesTypeAndShapeInfo() const { - OrtTensorTypeAndShapeInfo* output; - ThrowOnError(GetApi().GetSparseTensorValuesTypeAndShape(this->p_, &output)); - return TensorTypeAndShapeInfo{output}; -} - -template -inline TensorTypeAndShapeInfo ConstValueImpl::GetSparseTensorIndicesTypeShapeInfo(OrtSparseIndicesFormat indices_format) const { - OrtTensorTypeAndShapeInfo* output; - ThrowOnError(GetApi().GetSparseTensorIndicesTypeShape(this->p_, indices_format, &output)); - return TensorTypeAndShapeInfo{output}; -} - -template -template -inline const R* ConstValueImpl::GetSparseTensorIndicesData(OrtSparseIndicesFormat indices_format, size_t& num_indices) const { - const void* out; - ThrowOnError(GetApi().GetSparseTensorIndices(this->p_, indices_format, &num_indices, &out)); - return reinterpret_cast(out); -} - -template -inline bool ConstValueImpl::IsSparseTensor() const { - int out; - ThrowOnError(GetApi().IsSparseTensor(this->p_, &out)); - return out != 0; -} - -template -template -inline const R* ConstValueImpl::GetSparseTensorValues() const { - const void* out; - ThrowOnError(GetApi().GetSparseTensorValues(this->p_, &out)); - return reinterpret_cast(out); -} - -#endif - -template -void ValueImpl::FillStringTensor(const char* const* s, size_t s_len) { - ThrowOnError(GetApi().FillStringTensor(this->p_, s, s_len)); -} - -template -void ValueImpl::FillStringTensorElement(const char* s, size_t index) { - ThrowOnError(GetApi().FillStringTensorElement(this->p_, s, index)); -} - -template -void* ValueImpl::GetTensorMutableRawData() { - void* out; - ThrowOnError(GetApi().GetTensorMutableData(this->p_, &out)); - return out; -} - -template -template -R* ValueImpl::GetTensorMutableData() { - R* out; - ThrowOnError(GetApi().GetTensorMutableData(this->p_, (void**)&out)); - return out; -} - -template -template -R& ValueImpl::At(const std::vector& location) { - static_assert(!std::is_same::value, "this api does not support std::string"); - R* out; - ThrowOnError(GetApi().TensorAt(this->p_, location.data(), location.size(), (void**)&out)); - return *out; -} - -#if !defined(DISABLE_SPARSE_TENSORS) -template -void ValueImpl::UseCooIndices(int64_t* indices_data, size_t indices_num) { - ThrowOnError(GetApi().UseCooIndices(this->p_, indices_data, indices_num)); -} - -template -void ValueImpl::UseCsrIndices(int64_t* inner_data, size_t inner_num, int64_t* outer_data, size_t outer_num) { - ThrowOnError(GetApi().UseCsrIndices(this->p_, inner_data, inner_num, outer_data, outer_num)); -} - -template -void ValueImpl::UseBlockSparseIndices(const Shape& indices_shape, int32_t* indices_data) { - ThrowOnError(GetApi().UseBlockSparseIndices(this->p_, indices_shape.shape, indices_shape.shape_len, indices_data)); -} - -template -void ValueImpl::FillSparseTensorCoo(const OrtMemoryInfo* mem_info, const OrtSparseValuesParam& values_param, - const int64_t* indices_data, size_t indices_num) { - ThrowOnError(GetApi().FillSparseTensorCoo(this->p_, mem_info, values_param.values_shape, - values_param.values_shape_len, values_param.data.p_data, - indices_data, indices_num)); -} - -template -void ValueImpl::FillSparseTensorCsr(const OrtMemoryInfo* data_mem_info, - const OrtSparseValuesParam& values, - const int64_t* inner_indices_data, size_t inner_indices_num, - const int64_t* outer_indices_data, size_t outer_indices_num) { - ThrowOnError(GetApi().FillSparseTensorCsr(this->p_, data_mem_info, values.values_shape, values.values_shape_len, values.data.p_data, - inner_indices_data, inner_indices_num, - outer_indices_data, outer_indices_num)); -} - -template -void ValueImpl::FillSparseTensorBlockSparse(const OrtMemoryInfo* data_mem_info, - const OrtSparseValuesParam& values, - const Shape& indices_shape, - const int32_t* indices_data) { - ThrowOnError(GetApi().FillSparseTensorBlockSparse(this->p_, data_mem_info, values.values_shape, values.values_shape_len, values.data.p_data, - indices_shape.shape, indices_shape.shape_len, - indices_data)); -} - -#endif // !defined(DISABLE_SPARSE_TENSORS) - -} // namespace detail - -template -inline Value Value::CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len) { - return CreateTensor(info, p_data, p_data_element_count * sizeof(T), shape, shape_len, TypeToTensorType::type); -} - -inline Value Value::CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len, - ONNXTensorElementDataType type) { - OrtValue* out; - ThrowOnError(GetApi().CreateTensorWithDataAsOrtValue(info, p_data, p_data_byte_count, shape, shape_len, type, &out)); - return Value{out}; -} - -template -inline Value Value::CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len) { - return CreateTensor(allocator, shape, shape_len, TypeToTensorType::type); -} - -inline Value Value::CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type) { - OrtValue* out; - ThrowOnError(GetApi().CreateTensorAsOrtValue(allocator, shape, shape_len, type, &out)); - return Value{out}; -} - -#if !defined(DISABLE_SPARSE_TENSORS) - -template -inline Value Value::CreateSparseTensor(const OrtMemoryInfo* info, T* p_data, const Shape& dense_shape, - const Shape& values_shape) { - return CreateSparseTensor(info, p_data, dense_shape, values_shape, TypeToTensorType::type); -} - -inline Value Value::CreateSparseTensor(const OrtMemoryInfo* info, void* p_data, const Shape& dense_shape, - const Shape& values_shape, ONNXTensorElementDataType type) { - OrtValue* out; - ThrowOnError(GetApi().CreateSparseTensorWithValuesAsOrtValue(info, p_data, dense_shape.shape, dense_shape.shape_len, - values_shape.shape, values_shape.shape_len, type, &out)); - return Value{out}; -} - -template -inline Value Value::CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape) { - return CreateSparseTensor(allocator, dense_shape, TypeToTensorType::type); -} - -inline Value Value::CreateSparseTensor(OrtAllocator* allocator, const Shape& dense_shape, - ONNXTensorElementDataType type) { - OrtValue* out; - ThrowOnError(GetApi().CreateSparseTensorAsOrtValue(allocator, dense_shape.shape, dense_shape.shape_len, type, &out)); - return Value{out}; -} -#endif // !defined(DISABLE_SPARSE_TENSORS) - -inline Value Value::CreateMap(Value& keys, Value& values) { - OrtValue* out; - OrtValue* inputs[2] = {keys, values}; - ThrowOnError(GetApi().CreateValue(inputs, 2, ONNX_TYPE_MAP, &out)); - return Value{out}; -} - -inline Value Value::CreateSequence(std::vector& values) { - OrtValue* out; - std::vector values_ort{values.data(), values.data() + values.size()}; - ThrowOnError(GetApi().CreateValue(values_ort.data(), values_ort.size(), ONNX_TYPE_SEQUENCE, &out)); - return Value{out}; -} - -template -inline Value Value::CreateOpaque(const char* domain, const char* type_name, const T& data_container) { - OrtValue* out; - ThrowOnError(GetApi().CreateOpaqueValue(domain, type_name, &data_container, sizeof(T), &out)); - return Value{out}; -} - -// -// Custom OP Inlines -// -inline KernelContext::KernelContext(OrtKernelContext* context) : ctx_(context) { -} - -inline size_t KernelContext::GetInputCount() const { - size_t out = 0; - Ort::ThrowOnError(GetApi().KernelContext_GetInputCount(ctx_, &out)); - return out; -} - -inline size_t KernelContext::GetOutputCount() const { - size_t out = 0; - Ort::ThrowOnError(GetApi().KernelContext_GetOutputCount(ctx_, &out)); - return out; -} - -inline ConstValue KernelContext::GetInput(size_t index) const { - const OrtValue* out = nullptr; - Ort::ThrowOnError(GetApi().KernelContext_GetInput(ctx_, index, &out)); - return ConstValue{out}; -} - -inline UnownedValue KernelContext::GetOutput(size_t index, const int64_t* dim_values, size_t dim_count) const { - OrtValue* out = nullptr; - Ort::ThrowOnError(GetApi().KernelContext_GetOutput(ctx_, index, dim_values, dim_count, &out)); - return UnownedValue(out); -} - -inline UnownedValue KernelContext::GetOutput(size_t index, const std::vector& dims) const { - OrtValue* out = nullptr; - Ort::ThrowOnError(GetApi().KernelContext_GetOutput(ctx_, index, dims.data(), dims.size(), &out)); - return UnownedValue(out); -} - -inline void* KernelContext::GetGPUComputeStream() const { - void* out = nullptr; - Ort::ThrowOnError(GetApi().KernelContext_GetGPUComputeStream(ctx_, &out)); - return out; -} - -inline OpAttr::OpAttr(const char* name, const void* data, int len, OrtOpAttrType type) { - Ort::ThrowOnError(GetApi().CreateOpAttr(name, data, len, type, &p_)); -} - -namespace detail { -template -inline KernelInfo KernelInfoImpl::Copy() const { - OrtKernelInfo* info_copy = nullptr; - Ort::ThrowOnError(GetApi().CopyKernelInfo(this->p_, &info_copy)); - return KernelInfo{info_copy}; -} - -template -inline size_t KernelInfoImpl::GetInputCount() const { - size_t out = 0; - ThrowOnError(GetApi().KernelInfo_GetInputCount(this->p_, &out)); - return out; -} - -template -inline size_t KernelInfoImpl::GetOutputCount() const { - size_t out = 0; - ThrowOnError(GetApi().KernelInfo_GetOutputCount(this->p_, &out)); - return out; -} - -template -inline std::string KernelInfoImpl::GetInputName(size_t index) const { - size_t size = 0; - - // Feed nullptr for the data buffer to query the true size of the string value - Ort::ThrowOnError(GetApi().KernelInfo_GetInputName(this->p_, index, nullptr, &size)); - - std::string out; - out.resize(size); - Ort::ThrowOnError(GetApi().KernelInfo_GetInputName(this->p_, index, &out[0], &size)); - out.resize(size - 1); // remove the terminating character '\0' - - return out; -} - -template -inline std::string KernelInfoImpl::GetOutputName(size_t index) const { - size_t size = 0; - - // Feed nullptr for the data buffer to query the true size of the string value - Ort::ThrowOnError(GetApi().KernelInfo_GetOutputName(this->p_, index, nullptr, &size)); - - std::string out; - out.resize(size); - Ort::ThrowOnError(GetApi().KernelInfo_GetOutputName(this->p_, index, &out[0], &size)); - out.resize(size - 1); // remove the terminating character '\0' - - return out; -} - -template -inline TypeInfo KernelInfoImpl::GetInputTypeInfo(size_t index) const { - OrtTypeInfo* out = nullptr; - ThrowOnError(GetApi().KernelInfo_GetInputTypeInfo(this->p_, index, &out)); - return TypeInfo{out}; -} - -template -inline TypeInfo KernelInfoImpl::GetOutputTypeInfo(size_t index) const { - OrtTypeInfo* out = nullptr; - ThrowOnError(GetApi().KernelInfo_GetOutputTypeInfo(this->p_, index, &out)); - return TypeInfo{out}; -} - -template -inline Value KernelInfoImpl::GetTensorAttribute(const char* name, OrtAllocator* allocator) const { - OrtValue* out = nullptr; - ThrowOnError(GetApi().KernelInfoGetAttribute_tensor(this->p_, name, allocator, &out)); - return Value{out}; -} - -inline void attr_utils::GetAttr(const OrtKernelInfo* p, const char* name, float& out) { - Ort::ThrowOnError(GetApi().KernelInfoGetAttribute_float(p, name, &out)); -} - -inline void attr_utils::GetAttr(const OrtKernelInfo* p, const char* name, int64_t& out) { - Ort::ThrowOnError(GetApi().KernelInfoGetAttribute_int64(p, name, &out)); -} - -inline void attr_utils::GetAttr(const OrtKernelInfo* p, const char* name, std::string& result) { - size_t size = 0; - // Feed nullptr for the data buffer to query the true size of the string attribute - Ort::ThrowOnError(GetApi().KernelInfoGetAttribute_string(p, name, nullptr, &size)); - - std::string out; - out.resize(size); - Ort::ThrowOnError(GetApi().KernelInfoGetAttribute_string(p, name, &out[0], &size)); - out.resize(size - 1); // remove the terminating character '\0' - out.swap(result); -} - -inline void attr_utils::GetAttrs(const OrtKernelInfo* p, const char* name, std::vector& result) { - size_t size = 0; - // Feed nullptr for the data buffer to query the true size of the attribute - Ort::ThrowOnError(GetApi().KernelInfoGetAttributeArray_float(p, name, nullptr, &size)); - - std::vector out; - out.resize(size); - Ort::ThrowOnError(GetApi().KernelInfoGetAttributeArray_float(p, name, out.data(), &size)); - out.swap(result); -} - -inline void attr_utils::GetAttrs(const OrtKernelInfo* p, const char* name, std::vector& result) { - size_t size = 0; - - // Feed nullptr for the data buffer to query the true size of the attribute - Ort::ThrowOnError(GetApi().KernelInfoGetAttributeArray_int64(p, name, nullptr, &size)); - - std::vector out; - out.resize(size); - Ort::ThrowOnError(GetApi().KernelInfoGetAttributeArray_int64(p, name, out.data(), &size)); - out.swap(result); -} -} // namespace detail - -inline KernelInfo::KernelInfo(OrtKernelInfo* info) : detail::KernelInfoImpl{info} {} - -inline Op::Op(OrtOp* p) : Base(p) {} - -inline Op Op::Create(const OrtKernelInfo* info, const char* op_name, const char* domain, int version, - const char** type_constraint_names, - const ONNXTensorElementDataType* type_constraint_values, - size_t type_constraint_count, - const OpAttr* attr_values, size_t attr_count, - size_t input_count, size_t output_count) { - static_assert(sizeof(OpAttr) == sizeof(OrtOpAttr*), - "OpAttr's is expected to be just an array of OrtOpAttr in memory so we can reinterpret safely"); - auto attr_input_values = reinterpret_cast(attr_values); - OrtOp* op; - Ort::ThrowOnError(GetApi().CreateOp(info, op_name, domain, version, type_constraint_names, type_constraint_values, - static_cast(type_constraint_count), - attr_input_values, - static_cast(attr_count), - static_cast(input_count), - static_cast(output_count), &op)); - return Op{op}; -} - -inline void Op::Invoke(const OrtKernelContext* context, - const Value* input_values, - size_t input_count, - Value* output_values, - size_t output_count) { - static_assert(sizeof(Value) == sizeof(OrtValue*), - "Value is really just an array of OrtValue* in memory, so we can reinterpret_cast safely"); - auto ort_input_values = reinterpret_cast(input_values); - auto ort_output_values = reinterpret_cast(output_values); - Ort::ThrowOnError(GetApi().InvokeOp(context, p_, ort_input_values, static_cast(input_count), - ort_output_values, static_cast(output_count))); -} - -inline void Op::Invoke(const OrtKernelContext* context, - const OrtValue* const* input_values, - size_t input_count, - OrtValue* const* output_values, - size_t output_count) { - Ort::ThrowOnError(GetApi().InvokeOp(context, p_, input_values, static_cast(input_count), - output_values, static_cast(output_count))); -} - -inline void CustomOpApi::ThrowOnError(OrtStatus* status) { - Ort::ThrowOnError(status); -} - -template <> -inline float CustomOpApi::KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name) { - float out; - Ort::ThrowOnError(api_.KernelInfoGetAttribute_float(info, name, &out)); - return out; -} - -template <> -inline int64_t CustomOpApi::KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name) { - int64_t out; - Ort::ThrowOnError(api_.KernelInfoGetAttribute_int64(info, name, &out)); - return out; -} - -template <> -inline std::string CustomOpApi::KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name) { - size_t size = 0; - std::string out; - - // Feed nullptr for the data buffer to query the true size of the string attribute - OrtStatus* status = api_.KernelInfoGetAttribute_string(info, name, nullptr, &size); - - if (status == nullptr) { - out.resize(size); - Ort::ThrowOnError(api_.KernelInfoGetAttribute_string(info, name, &out[0], &size)); - out.resize(size - 1); // remove the terminating character '\0' - } else { - Ort::ThrowOnError(status); - } - return out; -} - -template <> -inline std::vector CustomOpApi::KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name) { - size_t size = 0; - std::vector out; - - // Feed nullptr for the data buffer to query the true size of the attribute - OrtStatus* status = api_.KernelInfoGetAttributeArray_float(info, name, nullptr, &size); - - if (status == nullptr) { - out.resize(size); - Ort::ThrowOnError(api_.KernelInfoGetAttributeArray_float(info, name, out.data(), &size)); - } else { - Ort::ThrowOnError(status); - } - return out; -} - -template <> -inline std::vector CustomOpApi::KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name) { - size_t size = 0; - std::vector out; - - // Feed nullptr for the data buffer to query the true size of the attribute - OrtStatus* status = api_.KernelInfoGetAttributeArray_int64(info, name, nullptr, &size); - - if (status == nullptr) { - out.resize(size); - Ort::ThrowOnError(api_.KernelInfoGetAttributeArray_int64(info, name, out.data(), &size)); - } else { - Ort::ThrowOnError(status); - } - return out; -} -inline OrtTensorTypeAndShapeInfo* CustomOpApi::GetTensorTypeAndShape(_In_ const OrtValue* value) { - OrtTensorTypeAndShapeInfo* out; - Ort::ThrowOnError(api_.GetTensorTypeAndShape(value, &out)); - return out; -} - -inline size_t CustomOpApi::GetTensorShapeElementCount(_In_ const OrtTensorTypeAndShapeInfo* info) { - size_t out; - Ort::ThrowOnError(api_.GetTensorShapeElementCount(info, &out)); - return out; -} - -inline ONNXTensorElementDataType CustomOpApi::GetTensorElementType(const OrtTensorTypeAndShapeInfo* info) { - ONNXTensorElementDataType out; - Ort::ThrowOnError(api_.GetTensorElementType(info, &out)); - return out; -} - -inline size_t CustomOpApi::GetDimensionsCount(_In_ const OrtTensorTypeAndShapeInfo* info) { - size_t out; - Ort::ThrowOnError(api_.GetDimensionsCount(info, &out)); - return out; -} - -inline void CustomOpApi::GetDimensions(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, size_t dim_values_length) { - Ort::ThrowOnError(api_.GetDimensions(info, dim_values, dim_values_length)); -} - -inline void CustomOpApi::SetDimensions(OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count) { - Ort::ThrowOnError(api_.SetDimensions(info, dim_values, dim_count)); -} - -template -inline T* CustomOpApi::GetTensorMutableData(_Inout_ OrtValue* value) { - T* data; - Ort::ThrowOnError(api_.GetTensorMutableData(value, reinterpret_cast(&data))); - return data; -} - -inline const OrtMemoryInfo* CustomOpApi::GetTensorMemoryInfo(_In_ const OrtValue* value) { - const OrtMemoryInfo* mem_info; - Ort::ThrowOnError(api_.GetTensorMemoryInfo(value, &mem_info)); - return mem_info; -} - -template -inline const T* CustomOpApi::GetTensorData(_Inout_ const OrtValue* value) { - T* data = nullptr; - Ort::ThrowOnError(api_.GetTensorMutableData(const_cast(value), reinterpret_cast(&data))); - return data; -} - -inline std::vector CustomOpApi::GetTensorShape(const OrtTensorTypeAndShapeInfo* info) { - size_t out; - Ort::ThrowOnError(api_.GetDimensionsCount(info, &out)); - std::vector output(out); - Ort::ThrowOnError(api_.GetDimensions(info, output.data(), out)); - return output; -} - -inline void CustomOpApi::ReleaseTensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* input) { - api_.ReleaseTensorTypeAndShapeInfo(input); -} - -inline size_t CustomOpApi::KernelContext_GetInputCount(const OrtKernelContext* context) { - size_t out; - Ort::ThrowOnError(api_.KernelContext_GetInputCount(context, &out)); - return out; -} - -inline const OrtValue* CustomOpApi::KernelContext_GetInput(const OrtKernelContext* context, _In_ size_t index) { - const OrtValue* out; - Ort::ThrowOnError(api_.KernelContext_GetInput(context, index, &out)); - return out; -} - -inline size_t CustomOpApi::KernelContext_GetOutputCount(const OrtKernelContext* context) { - size_t out; - Ort::ThrowOnError(api_.KernelContext_GetOutputCount(context, &out)); - return out; -} - -inline OrtValue* CustomOpApi::KernelContext_GetOutput(OrtKernelContext* context, _In_ size_t index, - _In_ const int64_t* dim_values, size_t dim_count) { - OrtValue* out; - Ort::ThrowOnError(api_.KernelContext_GetOutput(context, index, dim_values, dim_count, &out)); - return out; -} - -inline void* CustomOpApi::KernelContext_GetGPUComputeStream(const OrtKernelContext* context) { - void* out; - Ort::ThrowOnError(api_.KernelContext_GetGPUComputeStream(context, &out)); - return out; -} - -inline OrtOpAttr* CustomOpApi::CreateOpAttr(_In_ const char* name, - _In_ const void* data, - _In_ int len, - _In_ OrtOpAttrType type) { - OrtOpAttr* op_attr{}; - Ort::ThrowOnError(api_.CreateOpAttr(name, data, len, type, &op_attr)); - return op_attr; -} - -inline void CustomOpApi::ReleaseOpAttr(_Frees_ptr_opt_ OrtOpAttr* op_attr) { - api_.ReleaseOpAttr(op_attr); -} - -inline OrtOp* CustomOpApi::CreateOp(_In_ const OrtKernelInfo* info, - _In_ const char* op_name, - _In_ const char* domain, - _In_ int version, - _In_opt_ const char** type_constraint_names, - _In_opt_ const ONNXTensorElementDataType* type_constraint_values, - _In_opt_ int type_constraint_count, - _In_opt_ const OrtOpAttr* const* attr_values, - _In_opt_ int attr_count, - _In_ int input_count, - _In_ int output_count) { - OrtOp* ort_op{}; - Ort::ThrowOnError(api_.CreateOp(info, op_name, domain, version, type_constraint_names, type_constraint_values, - type_constraint_count, attr_values, attr_count, input_count, output_count, &ort_op)); - return ort_op; -} - -inline void CustomOpApi::InvokeOp(_In_ const OrtKernelContext* context, - _In_ const OrtOp* ort_op, - _In_ const OrtValue* const* input_values, - _In_ int input_count, - _Inout_ OrtValue* const* output_values, - _In_ int output_count) { - Ort::ThrowOnError(api_.InvokeOp(context, ort_op, input_values, input_count, output_values, output_count)); -} - -inline void CustomOpApi::ReleaseOp(_Frees_ptr_opt_ OrtOp* ort_op) { - api_.ReleaseOp(ort_op); -} - -inline OrtKernelInfo* CustomOpApi::CopyKernelInfo(_In_ const OrtKernelInfo* info) { - OrtKernelInfo* info_copy{}; - Ort::ThrowOnError(api_.CopyKernelInfo(info, &info_copy)); - return info_copy; -} - -inline void CustomOpApi::ReleaseKernelInfo(_Frees_ptr_opt_ OrtKernelInfo* info_copy) { - api_.ReleaseKernelInfo(info_copy); -} - -inline std::vector GetAvailableProviders() { - int len; - char** providers; - ThrowOnError(GetApi().GetAvailableProviders(&providers, &len)); - std::vector available_providers(providers, providers + len); - ThrowOnError(GetApi().ReleaseAvailableProviders(providers, len)); - return available_providers; -} - -SessionOptions& AddInitializer(const char* name, const OrtValue* ort_val); - -template -void CustomOpBase::GetSessionConfigs(std::unordered_map& out, - ConstSessionOptions options) const { - const TOp* derived = static_cast(this); - std::vector keys = derived->GetSessionConfigKeys(); - - out.reserve(keys.size()); - - std::string config_entry_key = detail::MakeCustomOpConfigEntryKey(derived->GetName(), ""); - const size_t prefix_size = config_entry_key.length(); - - for (const auto& key : keys) { - config_entry_key.resize(prefix_size); - config_entry_key.append(key); - out[key] = options.GetConfigEntryOrDefault(config_entry_key.c_str(), ""); - } -} - -} // namespace Ort diff --git a/lab/onnx/include/onnxruntime_run_options_config_keys.h b/lab/onnx/include/onnxruntime_run_options_config_keys.h deleted file mode 100644 index 1f5fcd50..00000000 --- a/lab/onnx/include/onnxruntime_run_options_config_keys.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -/* - * This file defines RunOptions Config Keys and format of the Config Values. - * - * The Naming Convention for a RunOptions Config Key, - * "[Area][.[SubArea1].[SubArea2]...].[Keyname]" - * Such as "ep.cuda.use_arena" - * The Config Key cannot be empty - * The maximum length of the Config Key is 128 - * - * The string format of a RunOptions Config Value is defined individually for each Config. - * The maximum length of the Config Value is 1024 - */ - -// Key for enabling shrinkages of user listed device memory arenas. -// Expects a list of semi-colon separated key value pairs separated by colon in the following format: -// "device_0:device_id_0;device_1:device_id_1" -// No white-spaces allowed in the provided list string. -// Currently, the only supported devices are : "cpu", "gpu" (case sensitive). -// If "cpu" is included in the list, DisableCpuMemArena() API must not be called (i.e.) arena for cpu should be enabled. -// Example usage: "cpu:0;gpu:0" (or) "gpu:0" -// By default, the value for this key is empty (i.e.) no memory arenas are shrunk -static const char* const kOrtRunOptionsConfigEnableMemoryArenaShrinkage = "memory.enable_memory_arena_shrinkage"; - -// Set to '1' to not synchronize execution providers with CPU at the end of session run. -// Per default it will be set to '0' -// Taking CUDA EP as an example, it omit triggering cudaStreamSynchronize on the compute stream. -static const char* const kOrtRunOptionsConfigDisableSynchronizeExecutionProviders = "disable_synchronize_execution_providers"; diff --git a/lab/onnx/include/onnxruntime_session_options_config_keys.h b/lab/onnx/include/onnxruntime_session_options_config_keys.h deleted file mode 100644 index 92482d71..00000000 --- a/lab/onnx/include/onnxruntime_session_options_config_keys.h +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -/* - * This file defines SessionOptions Config Keys and format of the Config Values. - * - * The Naming Convention for a SessionOptions Config Key, - * "[Area][.[SubArea1].[SubArea2]...].[Keyname]" - * Such as "ep.cuda.use_arena" - * The Config Key cannot be empty - * The maximum length of the Config Key is 128 - * - * The string format of a SessionOptions Config Value is defined individually for each Config. - * The maximum length of the Config Value is 1024 - */ - -// Key for disable PrePacking, -// If the config value is set to "1" then the prepacking is disabled, otherwise prepacking is enabled (default value) -static const char* const kOrtSessionOptionsConfigDisablePrepacking = "session.disable_prepacking"; - -// A value of "1" means allocators registered in the env will be used. "0" means the allocators created in the session -// will be used. Use this to override the usage of env allocators on a per session level. -static const char* const kOrtSessionOptionsConfigUseEnvAllocators = "session.use_env_allocators"; - -// Set to 'ORT' (case sensitive) to load an ORT format model. -// If unset, model type will default to ONNX unless inferred from filename ('.ort' == ORT format) or bytes to be ORT -static const char* const kOrtSessionOptionsConfigLoadModelFormat = "session.load_model_format"; - -// Set to 'ORT' (case sensitive) to save optimized model in ORT format when SessionOptions.optimized_model_path is set. -// If unset, format will default to ONNX unless optimized_model_filepath ends in '.ort'. -static const char* const kOrtSessionOptionsConfigSaveModelFormat = "session.save_model_format"; - -// If a value is "1", flush-to-zero and denormal-as-zero are applied. The default is "0". -// When multiple sessions are created, a main thread doesn't override changes from succeeding session options, -// but threads in session thread pools follow option changes. -// When ORT runs with OpenMP, the same rule is applied, i.e. the first session option to flush-to-zero and -// denormal-as-zero is only applied to global OpenMP thread pool, which doesn't support per-session thread pool. -// Note that an alternative way not using this option at runtime is to train and export a model without denormals -// and that's recommended because turning this option on may hurt model accuracy. -static const char* const kOrtSessionOptionsConfigSetDenormalAsZero = "session.set_denormal_as_zero"; - -// It controls to run quantization model in QDQ (QuantizelinearDeQuantizelinear) format or not. -// "0": enable. ORT does fusion logic for QDQ format. -// "1": disable. ORT doesn't do fusion logic for QDQ format. -// Its default value is "0" -static const char* const kOrtSessionOptionsDisableQuantQDQ = "session.disable_quant_qdq"; - -// It controls whether to enable Double QDQ remover and Identical Children Consolidation -// "0": not to disable. ORT does remove the middle 2 Nodes from a Q->(QD->Q)->QD pairs -// "1": disable. ORT doesn't remove the middle 2 Nodes from a Q->(QD->Q)->QD pairs -// Its default value is "0" -static const char* const kOrtSessionOptionsDisableDoubleQDQRemover = "session.disable_double_qdq_remover"; - -// If set to "1", enables the removal of QuantizeLinear/DequantizeLinear node pairs once all QDQ handling has been -// completed. e.g. If after all QDQ handling has completed and we have -> FloatOp -> Q -> DQ -> FloatOp -> the -// Q -> DQ could potentially be removed. This will provide a performance benefit by avoiding going from float to -// 8-bit and back to float, but could impact accuracy. The impact on accuracy will be model specific and depend on -// other factors like whether the model was created using Quantization Aware Training or Post Training Quantization. -// As such, it's best to test to determine if enabling this works well for your scenario. -// The default value is "0" -// Available since version 1.11. -static const char* const kOrtSessionOptionsEnableQuantQDQCleanup = "session.enable_quant_qdq_cleanup"; - -// Enable or disable gelu approximation in graph optimization. "0": disable; "1": enable. The default is "0". -// GeluApproximation has side effects which may change the inference results. It is disabled by default due to this. -static const char* const kOrtSessionOptionsEnableGeluApproximation = "optimization.enable_gelu_approximation"; - -#ifdef ENABLE_TRAINING -// Specifies a list of op types for memory footprint reduction. -// The value should be a ","-delimited list of pair of -// . -// For example, "Gelu+Cast+:1:0,Dropout+:1:1". -// A valid "subgraph string" should be one subgraph representation output by ORT graph transformations. -// "optimization strategy" currently has valid values: 0 - disabled, 1 - recompute. -// "number of subgraph to apply" is used to control how many subgraphs to apply optimization, to avoid "oversaving" -// the memory. -static const char* const kOrtSessionOptionsMemoryOptimizerEnabler = "optimization.enable_memory_optimizer"; - -// Specifies the level for detecting subgraphs for memory footprint reduction. -// The value should be an integer. The default value is 0. -static const char* const kOrtSessionOptionsMemoryOptimizerProbeLevel = "optimization.enable_memory_probe_recompute_level"; -#endif - -// Enable or disable using device allocator for allocating initialized tensor memory. "1": enable; "0": disable. The default is "0". -// Using device allocators means the memory allocation is made using malloc/new. -static const char* const kOrtSessionOptionsUseDeviceAllocatorForInitializers = "session.use_device_allocator_for_initializers"; - -// Configure whether to allow the inter_op/intra_op threads spinning a number of times before blocking -// "0": thread will block if found no job to run -// "1": default, thread will spin a number of times before blocking -static const char* const kOrtSessionOptionsConfigAllowInterOpSpinning = "session.inter_op.allow_spinning"; -static const char* const kOrtSessionOptionsConfigAllowIntraOpSpinning = "session.intra_op.allow_spinning"; - -// Key for using model bytes directly for ORT format -// If a session is created using an input byte array contains the ORT format model data, -// By default we will copy the model bytes at the time of session creation to ensure the model bytes -// buffer is valid. -// Setting this option to "1" will disable copy the model bytes, and use the model bytes directly. The caller -// has to guarantee that the model bytes are valid until the ORT session using the model bytes is destroyed. -static const char* const kOrtSessionOptionsConfigUseORTModelBytesDirectly = "session.use_ort_model_bytes_directly"; - -/// -/// Key for using the ORT format model flatbuffer bytes directly for initializers. -/// This avoids copying the bytes and reduces peak memory usage during model loading and initialization. -/// Requires `session.use_ort_model_bytes_directly` to be true. -/// If set, the flatbuffer bytes provided when creating the InferenceSession MUST remain valid for the entire -/// duration of the InferenceSession. -/// -static const char* const kOrtSessionOptionsConfigUseORTModelBytesForInitializers = - "session.use_ort_model_bytes_for_initializers"; - -// This should only be specified when exporting an ORT format model for use on a different platform. -// If the ORT format model will be used on ARM platforms set to "1". For other platforms set to "0" -// Available since version 1.11. -static const char* const kOrtSessionOptionsQDQIsInt8Allowed = "session.qdqisint8allowed"; - -// x64 SSE4.1/AVX2/AVX512(with no VNNI) has overflow problem with quantizied matrix multiplication with U8S8. -// To avoid this we need to use slower U8U8 matrix multiplication instead. This option, if -// turned on, use slower U8U8 matrix multiplications. Only effective with AVX2 or AVX512 -// platforms. -static const char* const kOrtSessionOptionsAvx2PrecisionMode = "session.x64quantprecision"; - -// Specifies how minimal build graph optimizations are handled in a full build. -// These optimizations are at the extended level or higher. -// Possible values and their effects are: -// "save": Save runtime optimizations when saving an ORT format model. -// "apply": Only apply optimizations available in a minimal build. -// ""/: Apply optimizations available in a full build. -// Available since version 1.11. -static const char* const kOrtSessionOptionsConfigMinimalBuildOptimizations = - "optimization.minimal_build_optimizations"; - -// Note: The options specific to an EP should be specified prior to appending that EP to the session options object in -// order for them to take effect. - -// Specifies a list of stop op types. Nodes of a type in the stop op types and nodes downstream from them will not be -// run by the NNAPI EP. -// The value should be a ","-delimited list of op types. For example, "Add,Sub". -// If not specified, the default set of stop ops is used. To specify an empty stop ops types list and disable stop op -// exclusion, set the value to "". -static const char* const kOrtSessionOptionsConfigNnapiEpPartitioningStopOps = "ep.nnapi.partitioning_stop_ops"; - -// Enabling dynamic block-sizing for multithreading. -// With a positive value, thread pool will split a task of N iterations to blocks of size starting from: -// N / (num_of_threads * dynamic_block_base) -// As execution progresses, the size will decrease according to the diminishing residual of N, -// meaning the task will be distributed in smaller granularity for better parallelism. -// For some models, it helps to reduce the variance of E2E inference latency and boost performance. -// The feature will not function by default, specify any positive integer, e.g. "4", to enable it. -// Available since version 1.11. -static const char* const kOrtSessionOptionsConfigDynamicBlockBase = "session.dynamic_block_base"; - -// This option allows to decrease CPU usage between infrequent -// requests and forces any TP threads spinning stop immediately when the last of -// concurrent Run() call returns. -// Spinning is restarted on the next Run() call. -// Applies only to internal thread-pools -static const char* const kOrtSessionOptionsConfigForceSpinningStop = "session.force_spinning_stop"; - -// "1": all inconsistencies encountered during shape and type inference -// will result in failures. -// "0": in some cases warnings will be logged but processing will continue. The default. -// May be useful to expose bugs in models. -static const char* const kOrtSessionOptionsConfigStrictShapeTypeInference = "session.strict_shape_type_inference"; - -// The file saves configuration for partitioning node among logic streams -static const char* const kNodePartitionConfigFile = "session.node_partition_config_file"; - -// This Option allows setting affinities for intra op threads. -// Affinity string follows format: -// logical_processor_id,logical_processor_id;logical_processor_id,logical_processor_id -// Semicolon isolates configurations among threads, while comma split processors where ith thread expected to attach to. -// e.g.1,2,3;4,5 -// specifies affinities for two threads, with the 1st thread attach to the 1st, 2nd, and 3rd processor, and 2nd thread to the 4th and 5th. -// To ease the configuration, an "interval" is also allowed: -// e.g. 1-8;8-16;17-24 -// orders that the 1st thread runs on first eight processors, 2nd thread runs on next eight processors, and so forth. -// Note: -// 1. Once set, the number of thread affinities must equal to intra_op_num_threads - 1, since ort does not set affinity on the main thread which -// is started and managed by the calling app; -// 2. For windows, ort will infer the group id from a logical processor id, for example, assuming there are two groups with each has 64 logical processors, -// an id of 64 will be inferred as the last processor of the 1st group, while 65 will be interpreted as the 1st processor of the second group. -// Hence 64-65 is an invalid configuration, because a windows thread cannot be attached to processors across group boundary. -static const char* const kOrtSessionOptionsConfigIntraOpThreadAffinities = "session.intra_op_thread_affinities"; diff --git a/lab/onnx/include/provider_options.h b/lab/onnx/include/provider_options.h deleted file mode 100644 index aab13e80..00000000 --- a/lab/onnx/include/provider_options.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -#include -#include -#include - -namespace onnxruntime { - -// data types for execution provider options - -using ProviderOptions = std::unordered_map; -using ProviderOptionsVector = std::vector; -using ProviderOptionsMap = std::unordered_map; - -} // namespace onnxruntime diff --git a/lab/onnx/linux/libonnxruntime.so b/lab/onnx/linux/libonnxruntime.so deleted file mode 120000 index b5f2af18..00000000 --- a/lab/onnx/linux/libonnxruntime.so +++ /dev/null @@ -1 +0,0 @@ -libonnxruntime.so.1.14.1 \ No newline at end of file diff --git a/lab/onnx/linux/libonnxruntime.so.1.14.1 b/lab/onnx/linux/libonnxruntime.so.1.14.1 deleted file mode 100644 index eb35d62d..00000000 Binary files a/lab/onnx/linux/libonnxruntime.so.1.14.1 and /dev/null differ diff --git a/lab/onnx/macos/libonnxruntime.1.14.1.dylib b/lab/onnx/macos/libonnxruntime.1.14.1.dylib deleted file mode 100644 index 565e7581..00000000 Binary files a/lab/onnx/macos/libonnxruntime.1.14.1.dylib and /dev/null differ diff --git a/lab/onnx/macos/libonnxruntime.dylib b/lab/onnx/macos/libonnxruntime.dylib deleted file mode 120000 index 5b616748..00000000 --- a/lab/onnx/macos/libonnxruntime.dylib +++ /dev/null @@ -1 +0,0 @@ -libonnxruntime.1.14.1.dylib \ No newline at end of file diff --git a/lab/onnx/win32/DirectML.dll b/lab/onnx/win32/DirectML.dll deleted file mode 100644 index b685312c..00000000 Binary files a/lab/onnx/win32/DirectML.dll and /dev/null differ diff --git a/lab/onnx/win32/onnxruntime.dll b/lab/onnx/win32/onnxruntime.dll deleted file mode 100644 index d7e9820f..00000000 Binary files a/lab/onnx/win32/onnxruntime.dll and /dev/null differ diff --git a/lab/onnx/win32/onnxruntime.lib b/lab/onnx/win32/onnxruntime.lib deleted file mode 100644 index d5fcd5cc..00000000 Binary files a/lab/onnx/win32/onnxruntime.lib and /dev/null differ diff --git a/lab/plugins/plugins.c b/lab/plugins/plugins.c deleted file mode 100644 index 02580e73..00000000 --- a/lab/plugins/plugins.c +++ /dev/null @@ -1,26 +0,0 @@ - -#include "../../../base/plugins/plugin_api.h" -#include "iron_array.h" -#include "proc_texsynth/proc_texsynth.h" - -FN(texsynth_inpaint) { - int32_t w; - JS_ToInt32(ctx, &w, argv[0]); - int32_t h; - JS_ToInt32(ctx, &h, argv[1]); - size_t size; - void *out = JS_GetArrayBuffer(ctx, &size, argv[2]); - void *img = JS_GetArrayBuffer(ctx, &size, argv[3]); - void *mask = JS_GetArrayBuffer(ctx, &size, argv[4]); - bool tiling = JS_ToBool(ctx, argv[5]); - texsynth_inpaint(w, h, out, img, mask, tiling); - return JS_UNDEFINED; -} - -void plugin_embed() { - JSValue global_obj = JS_GetGlobalObject(js_ctx); - - BIND(texsynth_inpaint, 6); - - JS_FreeValue(js_ctx, global_obj); -} diff --git a/lab/plugins/proc_texsynth/LICENSE.md b/lab/plugins/proc_texsynth/LICENSE.md deleted file mode 100644 index 85ba8f32..00000000 --- a/lab/plugins/proc_texsynth/LICENSE.md +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2019 Embark Studios - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. - -https://github.com/EmbarkStudios/texture-synthesis diff --git a/lab/plugins/proc_texsynth/linux/libtexsynth.a b/lab/plugins/proc_texsynth/linux/libtexsynth.a deleted file mode 100644 index 3d369f9a..00000000 Binary files a/lab/plugins/proc_texsynth/linux/libtexsynth.a and /dev/null differ diff --git a/lab/plugins/proc_texsynth/macos/libtexsynth.a b/lab/plugins/proc_texsynth/macos/libtexsynth.a deleted file mode 100644 index a7e0678d..00000000 Binary files a/lab/plugins/proc_texsynth/macos/libtexsynth.a and /dev/null differ diff --git a/lab/plugins/proc_texsynth/proc_texsynth.h b/lab/plugins/proc_texsynth/proc_texsynth.h deleted file mode 100644 index fcce4e84..00000000 --- a/lab/plugins/proc_texsynth/proc_texsynth.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void texsynth_inpaint(int w, int h, void *output_ptr, void *image_ptr, void *mask_ptr, bool tiling); diff --git a/lab/plugins/proc_texsynth/win32/texsynth.lib b/lab/plugins/proc_texsynth/win32/texsynth.lib deleted file mode 100644 index 25559028..00000000 Binary files a/lab/plugins/proc_texsynth/win32/texsynth.lib and /dev/null differ diff --git a/lab/plugins/project.js b/lab/plugins/project.js deleted file mode 100644 index 432ac846..00000000 --- a/lab/plugins/project.js +++ /dev/null @@ -1,15 +0,0 @@ -let project = new Project("plugins"); - -project.add_cfiles("plugins.c"); - -if (platform === "windows") { - project.add_lib(project.basedir + '/proc_texsynth/win32/texsynth'); -} -else if (platform === "linux") { - project.add_lib("texsynth -L" + project.basedir + "/proc_texsynth/linux"); -} -else if (platform === "macos") { - project.add_lib(project.basedir + '/proc_texsynth/macos/libtexsynth.a'); -} - -return project; diff --git a/lab/project.js b/lab/project.js deleted file mode 100644 index 371ccb83..00000000 --- a/lab/project.js +++ /dev/null @@ -1,36 +0,0 @@ - -let flags = globalThis.flags; -flags.name = "ArmorLab"; -flags.package = "org.armorlab"; -flags.with_onnx = true; - -let project = new Project(flags.name); -project.add_define("is_lab"); -project.add_project("../base"); - -project.add_tsfiles("sources"); -project.add_tsfiles("sources/nodes"); -project.add_shaders("shaders/*.kong"); -project.add_assets("assets/*", { destination: "data/{name}" }); -project.add_assets("../paint/assets/export_presets/*", { destination: "data/export_presets/{name}" }); -project.add_assets("assets/keymap_presets/*", { destination: "data/keymap_presets/{name}" }); -project.add_assets("assets/licenses/**", { destination: "data/licenses/{name}" }); -project.add_assets("assets/plugins/*", { destination: "data/plugins/{name}" }); -project.add_assets("../paint/assets/plugins/hello_world.js", { destination: "data/plugins/{name}" }); -project.add_assets("../paint/assets/plugins/hello_node_brush.js", { destination: "data/plugins/{name}" }); -project.add_assets("../paint/assets/plugins/import_svg.js", { destination: "data/plugins/{name}" }); -project.add_assets("assets/meshes/*", { destination: "data/meshes/{name}", noembed: true }); -project.add_assets("assets/models/*.onnx", { destination: "data/models/{name}" }); -project.add_assets("assets/models/*.json", { destination: "data/models/{name}" }); -project.add_assets("assets/models/LICENSE.txt", { destination: "data/models/LICENSE.txt" }); -project.add_assets("assets/readme/readme.txt", { destination: "{name}" }); - -if (platform === "windows") { - project.add_assets("onnx/win32/*.dll", { destination: "{name}" }); -} -else if (platform === "linux") { - project.add_assets("onnx/linux/*.so.*", { destination: "{name}" }); // Versioned lib -} - -project.flatten(); -return project; diff --git a/lab/readme.md b/lab/readme.md deleted file mode 100644 index 85775981..00000000 --- a/lab/readme.md +++ /dev/null @@ -1,43 +0,0 @@ -![](https://armory3d.org/lab/img/git.jpg) - -armorlab -============== - -[ArmorLab](https://armory3d.org/lab) is a software for PBR texture authoring - check out the [manual](https://armory3d.org/lab/manual). - -*Note 1: This repository is aimed at developers and may not be stable. Distributed binaries are [paid](https://armory3d.org/lab/download) to help with the project funding. All of the development is happening here in order to make it accessible to everyone. Thank you for support!* - -*Note 2: If you are compiling git version of ArmorLab, then you need to have a compiler ([Visual Studio with clang tools](https://visualstudio.microsoft.com/downloads/) - Windows, [clang + dependencies](https://github.com/armory3d/armortools/wiki/Linux-Dependencies) - Linux, [Xcode](https://developer.apple.com/xcode/resources/) - macOS / iOS, [Android Studio](https://developer.android.com/studio) - Android) and [git](https://git-scm.com/downloads) installed.* - -```bash -git clone https://github.com/armory3d/armortools -cd armortools/lab -# Unpack `models.zip` from https://github.com/armory3d/armorai/releases into `assets/models` using 7-Zip - Extract Here -``` - -**Windows (x64)** -```bash -..\base\make -# Open generated Visual Studio project at `build\ArmorLab.sln` -# Build and run -``` - -**Linux (x64)** *wip - cpu only* -```bash -../base/make --run -``` - -**macOS (arm64)** -```bash -../base/make -# Open generated Xcode project at `build/ArmorLab.xcodeproj` -# Build and run -``` - -**Android (arm64)** *wip* -```bash -``` - -**iOS (arm64)** *wip* -```bash -``` diff --git a/lab/shaders/inpaint_preview.kong b/lab/shaders/inpaint_preview.kong deleted file mode 100644 index 2258a0d8..00000000 --- a/lab/shaders/inpaint_preview.kong +++ /dev/null @@ -1,43 +0,0 @@ - -#[set(everything)] -const constants: { - empty: float4; -}; - -#[set(everything)] -const sampler_linear: sampler; - -#[set(everything)] -const tex0: tex2d; - -#[set(everything)] -const texa: tex2d; - -struct vert_in { - pos: float2; -} - -struct vert_out { - pos: float4; - tex: float2; -} - -fun inpaint_preview_vert(input: vert_in): vert_out { - var output: vert_out; - output.tex = input.pos.xy * 0.5 + 0.5; - output.tex.y = 1.0 - output.tex.y; - output.pos = float4(input.pos.xy, 0.0, 1.0); - return output; -} - -fun inpaint_preview_frag(input: vert_out): float4 { - var col: float4 = sample_lod(tex0, sampler_linear, input.tex, 0.0); - var mask: float = clamp(sample_lod(texa, sampler_linear, input.tex, 0.0).r + 0.5, 0.0, 1.0); - return col * mask; -} - -#[pipe] -struct pipe { - vertex = inpaint_preview_vert; - fragment = inpaint_preview_frag; -} diff --git a/lab/shaders/layer_copy_rrrr.kong b/lab/shaders/layer_copy_rrrr.kong deleted file mode 100644 index a81ccf86..00000000 --- a/lab/shaders/layer_copy_rrrr.kong +++ /dev/null @@ -1,38 +0,0 @@ - -#[set(everything)] -const constants: { - empty: float4; -}; - -#[set(everything)] -const sampler_linear: sampler; - -#[set(everything)] -const tex: tex2d; - -struct vert_in { - pos: float2; -} - -struct vert_out { - pos: float4; - tex: float2; -} - -fun layer_copy_rrrr_vert(input: vert_in): vert_out { - var output: vert_out; - output.tex = input.pos.xy * 0.5 + 0.5; - output.tex.y = 1.0 - output.tex.y; - output.pos = float4(input.pos.xy, 0.0, 1.0); - return output; -} - -fun layer_copy_rrrr_frag(input: vert_out): float4 { - return sample_lod(tex, sampler_linear, input.tex, 0.0).rrrr; -} - -#[pipe] -struct pipe { - vertex = layer_copy_rrrr_vert; - fragment = layer_copy_rrrr_frag; -} diff --git a/lab/sources/base_ext.ts b/lab/sources/base_ext.ts deleted file mode 100644 index 5ea23a69..00000000 --- a/lab/sources/base_ext.ts +++ /dev/null @@ -1,24 +0,0 @@ - -function base_ext_init() { - random_node_set_seed(math_floor(sys_time() * 4294967295)); -} - -function base_ext_render() { - if (context_raw.frame == 2) { - sys_notify_on_next_frame(function () { - sys_notify_on_next_frame(function () { - tab_meshes_set_default_mesh(".Sphere"); - }); - }); - } -} - -function base_ext_init_config(raw: config_t) { - raw.displace_strength = 1.0; - raw.workspace = space_type_t.SPACE2D; - raw.node_preview = false; -} - -function base_ext_update() { - -} diff --git a/lab/sources/context_ext.ts b/lab/sources/context_ext.ts deleted file mode 100644 index e3e12545..00000000 --- a/lab/sources/context_ext.ts +++ /dev/null @@ -1,23 +0,0 @@ - -function context_ext_init(c: context_t) { - c.tool = tool_type_t.ERASER; - c.color_picker_previous_tool = tool_type_t.ERASER; - c.brush_radius = 0.25; - c.brush_radius_handle.value = 0.25; - c.brush_hardness = 0.8; - - c.coords = vec4_create(); - c.start_x = 0.0; - c.start_y = 0.0; - - c.lock_begin = false; - c.lock_x = false; - c.lock_y = false; - c.lock_start_x = 0.0; - c.lock_start_y = 0.0; - c.registered = false; -} - -function context_ext_select_paint_object(o: mesh_object_t) { - context_raw.paint_object = o; -} diff --git a/lab/sources/layers_ext.ts b/lab/sources/layers_ext.ts deleted file mode 100644 index ffd00f66..00000000 --- a/lab/sources/layers_ext.ts +++ /dev/null @@ -1,81 +0,0 @@ - -function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[] = null): slot_layer_t { - let texpaint: gpu_texture_t = context_raw.brush_output_node_inst.texpaint; - let texpaint_nor: gpu_texture_t = context_raw.brush_output_node_inst.texpaint_nor; - let texpaint_pack: gpu_texture_t = context_raw.brush_output_node_inst.texpaint_pack; - - let nodes: ui_nodes_t = ui_nodes_get_nodes(); - let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true); - if (nodes.nodes_selected_id.length > 0) { - let node: ui_node_t = ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]); - let brush_node: logic_node_ext_t = parser_logic_get_logic_node(node); - if (brush_node != null && logic_node_get_cached_image(brush_node.base) != null) { - texpaint = logic_node_get_cached_image(brush_node.base); - let texpaint_nor_rt: render_target_t = map_get(render_path_render_targets, "texpaint_nor_empty"); - let texpaint_pack_rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack_empty"); - texpaint_nor = texpaint_nor_rt._image; - texpaint_pack = texpaint_pack_rt._image; - } - } - - let l: slot_layer_t = { texpaint: texpaint, texpaint_nor: texpaint_nor, texpaint_pack: texpaint_pack }; - return l; -} - -function layers_ext_on_resized() { - iron_delete_texture(context_raw.brush_output_node_inst.texpaint); - let texpaint_rt: render_target_t = map_get(render_path_render_targets, "texpaint"); - context_raw.brush_output_node_inst.texpaint = texpaint_rt._image = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y()); - - iron_delete_texture(context_raw.brush_output_node_inst.texpaint_nor); - let texpaint_nor_rt: render_target_t = map_get(render_path_render_targets, "texpaint_nor"); - context_raw.brush_output_node_inst.texpaint_nor = texpaint_nor_rt._image = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y()); - - iron_delete_texture(context_raw.brush_output_node_inst.texpaint_pack); - let texpaint_pack_rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack"); - context_raw.brush_output_node_inst.texpaint_pack = texpaint_pack_rt._image = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y()); - - if (inpaint_node_image != null) { - iron_delete_texture(inpaint_node_image); - inpaint_node_image = null; - iron_delete_texture(inpaint_node_mask); - inpaint_node_mask = null; - inpaint_node_init(); - } - - if (photo_to_pbr_node_images != null) { - for (let i: i32 = 0; i < photo_to_pbr_node_images.length; ++i) { - let image: gpu_texture_t = photo_to_pbr_node_images[i]; - iron_delete_texture(image); - } - photo_to_pbr_node_images = null; - photo_to_pbr_node_init(); - } - - if (tiling_node_image != null) { - iron_delete_texture(tiling_node_image); - tiling_node_image = null; - tiling_node_init(); - } - - let texpaint_blend0_rt: render_target_t = map_get(render_path_render_targets, "texpaint_blend0"); - iron_delete_texture(texpaint_blend0_rt._image); - texpaint_blend0_rt._image = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8); - - let texpaint_blend1_rt: render_target_t = map_get(render_path_render_targets, "texpaint_blend1"); - iron_delete_texture(texpaint_blend1_rt._image); - texpaint_blend1_rt._image = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8); - - if (map_get(render_path_render_targets, "texpaint_node") != null) { - map_delete(render_path_render_targets, "texpaint_node"); - } - if (map_get(render_path_render_targets, "texpaint_node_target") != null) { - map_delete(render_path_render_targets, "texpaint_node_target"); - } - - sys_notify_on_next_frame(function () { - layers_init(); - }); - - render_path_raytrace_ready = false; -} diff --git a/lab/sources/make_material.ts b/lab/sources/make_material.ts deleted file mode 100644 index e97f8351..00000000 --- a/lab/sources/make_material.ts +++ /dev/null @@ -1,108 +0,0 @@ - -let make_material_default_scon: shader_context_t = null; -let make_material_default_mcon: material_context_t = null; -let make_material_height_used: bool = false; - -type parse_node_preview_result_t = { - scon: shader_context_t; - mcon: material_context_t; -}; - -function make_material_parse_mesh_material() { - let m: material_data_t = project_material_data; - - for (let i: i32 = 0; i < m._.shader.contexts.length; ++i) { - let c: shader_context_t = m._.shader.contexts[i]; - if (c.name == "mesh") { - array_remove(m._.shader.contexts, c); - make_material_delete_context(c); - break; - } - } - - let mm: material_t = { - name: "Material", - canvas: null - }; - - let con: node_shader_context_t = make_mesh_run(mm); - shader_context_load(con.data); - array_push(m._.shader.contexts, con.data); - - context_raw.ddirty = 2; - - ///if (arm_direct3d12 || arm_vulkan) - render_path_raytrace_dirty = 1; - ///end -} - -function make_material_parse_paint_material() { - let m: material_data_t = project_material_data; - for (let i: i32 = 0; i < m._.shader.contexts.length; ++i) { - let c: shader_context_t = m._.shader.contexts[i]; - if (c.name == "paint") { - array_remove(m._.shader.contexts, c); - if (c != make_material_default_scon) { - make_material_delete_context(c); - } - break; - } - } - for (let i: i32 = 0; i < m.contexts.length; ++i) { - let c: material_context_t = m.contexts[i]; - if (c.name == "paint") { - array_remove(m.contexts, c); - break; - } - } - - let sdata: material_t = { name: "Material", canvas: null }; - let mcon2: material_context_t = { name: "paint", bind_textures: [] }; - let con: node_shader_context_t = make_paint_run(sdata, mcon2); - - let compile_error: bool = false; - let scon2: shader_context_t; - shader_context_load(con.data); - if (con.data == null) { - compile_error = true; - } - scon2 = con.data; - - if (compile_error) { - return; - } - - material_context_load(mcon2); - - array_push(m._.shader.contexts, scon2); - array_push(m.contexts, mcon2); - - if (make_material_default_scon == null) { - make_material_default_scon = scon2; - } - if (make_material_default_mcon == null) { - make_material_default_mcon = mcon2; - } -} - -function make_material_get_displace_strength(): f32 { - let sc: vec4_t = context_main_object().base.transform.scale; - return config_raw.displace_strength * 0.02 * sc.x; -} - -function make_material_delete_context(c: shader_context_t) { - sys_notify_on_next_frame(function (c: shader_context_t) { // Ensure pipeline is no longer in use - shader_context_delete(c); - }, c); -} - -function make_material_parse_brush() { - // parser_logic_parse(context_raw.brush.canvas); -} - -function make_material_parse_mesh_preview_material(md: material_data_t = null) { -} - -function make_material_parse_node_preview_material(node: ui_node_t, group: ui_node_canvas_t = null, parents: ui_node_t[] = null): parse_node_preview_result_t { - return null; -} diff --git a/lab/sources/make_mesh.ts b/lab/sources/make_mesh.ts deleted file mode 100644 index f76caa9e..00000000 --- a/lab/sources/make_mesh.ts +++ /dev/null @@ -1,219 +0,0 @@ - -let make_mesh_layer_pass_count: i32 = 1; - -function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_context_t { - - let depth_write: bool = layer_pass == 0 ? true : false; - let compare_mode: string = layer_pass == 0 ? "less" : "equal"; - let cull_mode: string = (context_raw.cull_backfaces || layer_pass > 0) ? "clockwise" : "none"; - - let props: shader_context_t = { - name: "mesh", - depth_write: depth_write, - compare_mode: compare_mode, - cull_mode: cull_mode, - vertex_elements: [ - { - name: "pos", - data: "short4norm" - }, - { - name: "nor", - data: "short2norm" - }, - { - name: "tex", - data: "short2norm" - } - ], - color_attachments: [ - "RGBA64", - "RGBA64", - "RGBA64" - ], - depth_attachment: "D32" - }; - let con_mesh: node_shader_context_t = node_shader_context_create(data, props); - let kong: node_shader_t = node_shader_context_make_kong(con_mesh); - - node_shader_add_out(kong, "tex_coord: float2"); - kong.frag_wvpposition = true; - node_shader_add_constant(kong, "VP: float4x4", "_view_proj_matrix"); - kong.frag_wposition = true; - - let displace_strength: f32 = make_material_get_displace_strength(); - if (make_material_height_used && displace_strength > 0.0) { - kong.vert_n = true; - node_shader_write_vert(kong, "var height: float = 0.0;"); - let displace_3: string = displace_strength + ", " + displace_strength + ", " + displace_strength; - node_shader_write_vert(kong, "output.wposition += wnormal * float3(height, height, height) * float3(" + displace_3 + ");"); - } - - node_shader_write_vert(kong, "output.pos = constants.VP * float4(output.wposition.xyz, 1.0);"); - let brush_scale: f32 = context_raw.brush_scale; - node_shader_add_constant(kong, "tex_scale: float", "_tex_unpack"); - node_shader_write_vert(kong, "output.tex_coord = input.tex * float(" + brush_scale + ") * constants.tex_scale;"); - node_shader_write_attrib_frag(kong, "var tex_coord: float2 = input.tex_coord;"); - - kong.frag_out = "float4[3]"; - kong.frag_n = true; - node_shader_add_function(kong, str_pack_float_int16); - node_shader_add_function(kong, str_octahedron_wrap); - node_shader_add_function(kong, str_cotangent_frame); - - node_shader_write_frag(kong, "var basecol: float3 = float3(0.0, 0.0, 0.0);"); - node_shader_write_frag(kong, "var roughness: float = 0.0;"); - node_shader_write_frag(kong, "var metallic: float = 0.0;"); - node_shader_write_frag(kong, "var occlusion: float = 1.0;"); - node_shader_write_frag(kong, "var opacity: float = 1.0;"); - node_shader_write_frag(kong, "var matid: float = 0.0;"); - node_shader_write_frag(kong, "var ntex: float3 = float3(0.5, 0.5, 1.0);"); - node_shader_write_frag(kong, "var height: float = 0.0;"); - - node_shader_write_frag(kong, "var texpaint_sample: float4 = float4(0.0, 0.0, 0.0, 1.0);"); - node_shader_write_frag(kong, "var texpaint_nor_sample: float4;"); - node_shader_write_frag(kong, "var texpaint_pack_sample: float4;"); - node_shader_write_frag(kong, "var texpaint_opac: float;"); - - if (make_material_height_used) { - node_shader_write_frag(kong, "var height0: float = 0.0;"); - node_shader_write_frag(kong, "var height1: float = 0.0;"); - node_shader_write_frag(kong, "var height2: float = 0.0;"); - node_shader_write_frag(kong, "var height3: float = 0.0;"); - } - - if (context_raw.viewport_mode == viewport_mode_t.LIT && context_raw.render_mode == render_mode_t.FORWARD) { - node_shader_add_texture(kong, "senvmap_brdf", "$brdf.k"); - node_shader_add_texture(kong, "senvmap_radiance", "_envmap_radiance"); - node_shader_add_texture(kong, "senvmap_radiance0", "_envmap_radiance0"); - node_shader_add_texture(kong, "senvmap_radiance1", "_envmap_radiance1"); - node_shader_add_texture(kong, "senvmap_radiance2", "_envmap_radiance2"); - node_shader_add_texture(kong, "senvmap_radiance3", "_envmap_radiance3"); - node_shader_add_texture(kong, "senvmap_radiance4", "_envmap_radiance4"); - } - - node_shader_add_texture(kong, "texpaint"); - node_shader_write_frag(kong, "texpaint_sample = sample_lod(texpaint, sampler_linear, tex_coord, 0.0);"); - node_shader_write_frag(kong, "texpaint_opac = texpaint_sample.a;"); - - node_shader_write_frag(kong, "basecol = texpaint_sample.rgb * texpaint_opac;"); - node_shader_add_texture(kong, "texpaint_nor"); - node_shader_write_frag(kong, "texpaint_nor_sample = sample_lod(texpaint_nor, sampler_linear, tex_coord, 0.0);"); - node_shader_write_frag(kong, "ntex = lerp3(ntex, texpaint_nor_sample.rgb, texpaint_opac);"); - node_shader_add_texture(kong, "texpaint_pack"); - node_shader_write_frag(kong, "texpaint_pack_sample = sample_lod(texpaint_pack, sampler_linear, tex_coord, 0.0);"); - node_shader_write_frag(kong, "occlusion = lerp(occlusion, texpaint_pack_sample.r, texpaint_opac);"); - node_shader_write_frag(kong, "roughness = lerp(roughness, texpaint_pack_sample.g, texpaint_opac);"); - node_shader_write_frag(kong, "metallic = lerp(metallic, texpaint_pack_sample.b, texpaint_opac);"); - node_shader_write_frag(kong, "height = texpaint_pack_sample.a * texpaint_opac;"); - - if (make_material_height_used) { - node_shader_write_frag(kong, "if (height > 0.0) {"); - node_shader_write_frag(kong, "var height_dx: float = height0 - height1;"); - node_shader_write_frag(kong, "var height_dy: float = height2 - height3;"); - // Whiteout blend - node_shader_write_frag(kong, "var n1: float3 = ntex * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);"); - node_shader_write_frag(kong, "var n2: float3 = normalize(float3(height_dx * 16.0, height_dy * 16.0, 1.0));"); - node_shader_write_frag(kong, "ntex = normalize(float3(n1.xy + n2.xy, n1.z * n2.z)) * float3(0.5, 0.5, 0.5) + float3(0.5, 0.5, 0.5);"); - node_shader_write_frag(kong, "}"); - } - - kong.frag_vvec = true; - node_shader_write_frag(kong, "var TBN: float3x3 = cotangent_frame(n, vvec, tex_coord);"); - node_shader_write_frag(kong, "n = ntex * 2.0 - 1.0;"); - node_shader_write_frag(kong, "n.y = -n.y;"); - node_shader_write_frag(kong, "n = normalize(TBN * n);"); - - if (context_raw.viewport_mode == viewport_mode_t.LIT || context_raw.viewport_mode == viewport_mode_t.PATH_TRACE) { - - node_shader_write_frag(kong, "basecol = pow3(basecol, float3(2.2, 2.2, 2.2));"); - - if (context_raw.viewport_shader != null) { - node_shader_write_frag(kong, "output_color: float3;"); - js_call_ptr(context_raw.viewport_shader, kong); - node_shader_write_frag(kong, "output[1] = float4(output_color, 1.0);"); - } - else if (context_raw.render_mode == render_mode_t.FORWARD && context_raw.viewport_mode != viewport_mode_t.PATH_TRACE) { - kong.frag_wposition = true; - node_shader_write_frag(kong, "var albedo: float3 = lerp3(basecol, float3(0.0, 0.0, 0.0), metallic);"); - node_shader_write_frag(kong, "var f0: float3 = lerp3(float3(0.04, 0.04, 0.04), basecol, metallic);"); - kong.frag_vvec = true; - node_shader_write_frag(kong, "var dotnv: float = max(0.0, dot(n, vvec));"); - // node_shader_write_frag(kong, "var env_brdf: float2 = senvmap_brdf[uint2(float2(roughness, 1.0 - dotnv) * 256.0)].xy;"); - node_shader_write_frag(kong, "var env_brdf: float4 = senvmap_brdf[uint2(float2(roughness, 1.0 - dotnv) * 256.0)];"); - node_shader_add_constant(kong, "envmap_num_mipmaps: int", "_envmap_num_mipmaps"); - node_shader_add_constant(kong, "envmap_data: float4", "_envmap_data"); // angle, sin(angle), cos(angle), strength - node_shader_write_frag(kong, "var wreflect: float3 = reflect(-vvec, n);"); - - node_shader_add_function(kong, str_envmap_equirect); - // node_shader_write_frag(kong, "var envlod: float = roughness * float(constants.envmap_num_mipmaps);"); - // node_shader_write_frag(kong, "var prefiltered_color: float3 = sample_lod(senvmap_radiance, sampler_linear, envmap_equirect(wreflect, constants.envmap_data.x), envlod).rgb;"); - - node_shader_add_function(kong, str_envmap_sample); - node_shader_write_frag(kong, "var envlod: float = roughness * 5.0;"); - node_shader_write_frag(kong, "var lod0: float = floor(envlod);"); - node_shader_write_frag(kong, "var lod1: float = ceil(envlod);"); - node_shader_write_frag(kong, "var lodf: float = envlod - lod0;"); - node_shader_write_frag(kong, "var envmap_coord: float2 = envmap_equirect(wreflect, constants.envmap_data.x);"); - node_shader_write_frag(kong, "var lodc0: float3 = envmap_sample(lod0, envmap_coord);"); - node_shader_write_frag(kong, "var lodc1: float3 = envmap_sample(lod1, envmap_coord);"); - node_shader_write_frag(kong, "var prefiltered_color: float3 = lerp3(lodc0, lodc1, lodf);"); - - // node_shader_add_constant(kong, "shirr: float4[7]", "_envmap_irradiance"); - node_shader_add_constant(kong, "shirr0: float4", "_envmap_irradiance0"); - node_shader_add_constant(kong, "shirr1: float4", "_envmap_irradiance1"); - node_shader_add_constant(kong, "shirr2: float4", "_envmap_irradiance2"); - node_shader_add_constant(kong, "shirr3: float4", "_envmap_irradiance3"); - node_shader_add_constant(kong, "shirr4: float4", "_envmap_irradiance4"); - node_shader_add_constant(kong, "shirr5: float4", "_envmap_irradiance5"); - node_shader_add_constant(kong, "shirr6: float4", "_envmap_irradiance6"); - node_shader_add_function(kong, str_sh_irradiance); - node_shader_write_frag(kong, "var indirect: float3 = albedo * (sh_irradiance(float3(n.x * constants.envmap_data.z - n.y * constants.envmap_data.y, n.x * constants.envmap_data.y + n.y * constants.envmap_data.z, n.z)) / 3.14159265);"); - node_shader_write_frag(kong, "indirect += prefiltered_color * (f0 * env_brdf.x + env_brdf.y) * 1.5;"); - node_shader_write_frag(kong, "indirect *= constants.envmap_data.w * occlusion;"); - node_shader_write_frag(kong, "output[1] = float4(indirect, 1.0);"); - } - else { // Deferred, Pathtraced - node_shader_write_frag(kong, "output[1] = float4(basecol, occlusion);"); - } - } - else if (context_raw.viewport_mode == viewport_mode_t.BASE_COLOR) { - node_shader_write_frag(kong, "output[1] = float4(basecol, 1.0);"); - } - else if (context_raw.viewport_mode == viewport_mode_t.NORMAL_MAP) { - node_shader_write_frag(kong, "output[1] = float4(ntex.rgb, 1.0);"); - } - else if (context_raw.viewport_mode == viewport_mode_t.OCCLUSION) { - node_shader_write_frag(kong, "output[1] = float4(float3(occlusion, occlusion, occlusion), 1.0);"); - } - else if (context_raw.viewport_mode == viewport_mode_t.ROUGHNESS) { - node_shader_write_frag(kong, "output[1] = float4(float3(roughness, roughness, roughness), 1.0);"); - } - else if (context_raw.viewport_mode == viewport_mode_t.METALLIC) { - node_shader_write_frag(kong, "output[1] = float4(float3(metallic, metallic, metallic), 1.0);"); - } - else if (context_raw.viewport_mode == viewport_mode_t.OPACITY) { - node_shader_write_frag(kong, "output[1] = float4(float3(texpaint_sample.a, texpaint_sample.a, texpaint_sample.a), 1.0);"); - } - else if (context_raw.viewport_mode == viewport_mode_t.HEIGHT) { - node_shader_write_frag(kong, "output[1] = float4(float3(height, height, height), 1.0);"); - } - else { - node_shader_write_frag(kong, "output[1] = float4(1.0, 0.0, 1.0, 1.0);"); // Pink - } - - if (context_raw.viewport_mode != viewport_mode_t.LIT && context_raw.viewport_mode != viewport_mode_t.PATH_TRACE) { - node_shader_write_frag(kong, "output[1].rgb = pow3(output[1].rgb, float3(2.2, 2.2, 2.2));"); - } - - node_shader_write_frag(kong, "n = n / (abs(n.x) + abs(n.y) + abs(n.z));"); - // node_shader_write_frag(kong, "n.xy = n.z >= 0.0 ? n.xy : octahedron_wrap(n.xy);"); - node_shader_write_frag(kong, "if (n.z < 0.0) { n.xy = octahedron_wrap(n.xy); }"); - node_shader_write_frag(kong, "output[0] = float4(n.xy, roughness, pack_f32_i16(metallic, uint(float(int(matid * 255.0)) % float(3))));"); - node_shader_write_frag(kong, "output[2] = float4(0.0, 0.0, tex_coord.xy);"); - - parser_material_finalize(con_mesh); - con_mesh.data.shader_from_source = true; - gpu_create_shaders_from_kong(node_shader_get(kong), ADDRESS(con_mesh.data.vertex_shader), ADDRESS(con_mesh.data.fragment_shader), ADDRESS(con_mesh.data._.vertex_shader_size), ADDRESS(con_mesh.data._.fragment_shader_size)); - return con_mesh; -} diff --git a/lab/sources/make_paint.ts b/lab/sources/make_paint.ts deleted file mode 100644 index 0e10e202..00000000 --- a/lab/sources/make_paint.ts +++ /dev/null @@ -1,170 +0,0 @@ - -function make_paint_color_attachments(): string[] { - if (context_raw.tool == tool_type_t.PICKER) { - let res: string[] = ["RGBA32", "RGBA32", "RGBA32", "RGBA32"]; - return res; - } - let res: string[] = ["RGBA32", "RGBA32", "RGBA32", "R8"]; - return res; -} - -function make_paint_run(data: material_t, matcon: material_context_t): node_shader_context_t { - let props: shader_context_t = { - name: "paint", - depth_write: false, - compare_mode: "always", - cull_mode: "none", - vertex_elements: [ - { - name: "pos", - data: "short4norm" - }, - { - name: "nor", - data: "short2norm" - }, - { - name: "tex", - data: "short2norm" - } - ], - color_attachments: make_paint_color_attachments() - }; - let con_paint: node_shader_context_t = node_shader_context_create(data, props); - - con_paint.data.color_writes_red = [true, true, true, true]; - con_paint.data.color_writes_green = [true, true, true, true]; - con_paint.data.color_writes_blue = [true, true, true, true]; - con_paint.data.color_writes_alpha = [true, true, true, true]; - con_paint.allow_vcols = mesh_data_get_vertex_array(context_raw.paint_object.data, "col") != null; - - let kong: node_shader_t = node_shader_context_make_kong(con_paint); - - if (context_raw.tool == tool_type_t.PICKER) { - // Mangle vertices to form full screen triangle - node_shader_write_vert(kong, "output.pos = float4(-1.0 + float((vertex_id() & 1) << 2), -1.0 + float((vertex_id() & 2) << 1), 0.0, 1.0);"); - - node_shader_add_texture(kong, "gbuffer2"); - node_shader_add_constant(kong, "gbuffer_size: float2", "_gbuffer_size"); - node_shader_add_constant(kong, "inp: float4", "_input_brush"); - - // node_shader_write_frag(kong, "var tex_coord_inp: float2 = gbuffer2[uint2(constants.inp.x * constants.gbuffer_size.x, constants.inp.y * constants.gbuffer_size.y)].ba;"); - node_shader_write_frag(kong, "var tex_coord_inp4: float4 = gbuffer2[uint2(constants.inp.x * constants.gbuffer_size.x, constants.inp.y * constants.gbuffer_size.y)];"); - node_shader_write_frag(kong, "var tex_coord_inp: float2 = tex_coord_inp4.ba;"); - - kong.frag_out = "float4[4]"; - node_shader_add_texture(kong, "texpaint"); - node_shader_add_texture(kong, "texpaint_nor"); - node_shader_add_texture(kong, "texpaint_pack"); - node_shader_write_frag(kong, "output[0] = sample_lod(texpaint, sampler_linear, tex_coord_inp, 0.0);"); - node_shader_write_frag(kong, "output[1] = sample_lod(texpaint_nor, sampler_linear, tex_coord_inp, 0.0);"); - node_shader_write_frag(kong, "output[2] = sample_lod(texpaint_pack, sampler_linear, tex_coord_inp, 0.0);"); - node_shader_write_frag(kong, "output[3].rg = tex_coord_inp.xy;"); - con_paint.data.shader_from_source = true; - gpu_create_shaders_from_kong(node_shader_get(kong), ADDRESS(con_paint.data.vertex_shader), ADDRESS(con_paint.data.fragment_shader), ADDRESS(con_paint.data._.vertex_shader_size), ADDRESS(con_paint.data._.fragment_shader_size)); - return con_paint; - } - - node_shader_write_vert(kong, "var tpos: float2 = float2(input.tex.x * 2.0 - 1.0, (1.0 - input.tex.y) * 2.0 - 1.0);"); - - node_shader_write_vert(kong, "output.pos = float4(tpos, 0.0, 1.0);"); - - node_shader_add_constant(kong, "WVP: float4x4", "_world_view_proj_matrix"); - - node_shader_add_out(kong, "ndc: float4"); - node_shader_write_attrib_vert(kong, "output.ndc = constants.WVP * float4(input.pos.xyz, 1.0);"); - - node_shader_write_attrib_frag(kong, "var sp: float3 = (input.ndc.xyz / input.ndc.w) * 0.5 + 0.5;"); - node_shader_write_attrib_frag(kong, "sp.y = 1.0 - sp.y;"); - node_shader_write_attrib_frag(kong, "sp.z -= 0.0001;"); // small bias - - node_shader_add_constant(kong, "inp: float4", "_input_brush"); - node_shader_add_constant(kong, "inplast: float4", "_input_brush_last"); - node_shader_add_constant(kong, "aspect_ratio: float", "_aspect_ratio_window"); - node_shader_write_frag(kong, "var bsp: float2 = sp.xy * 2.0 - 1.0;"); - node_shader_write_frag(kong, "bsp.x *= constants.aspect_ratio;"); - node_shader_write_frag(kong, "bsp = bsp * 0.5 + 0.5;"); - - node_shader_add_texture(kong, "gbufferD"); - - kong.frag_out = "float4[4]"; - - node_shader_add_constant(kong, "brush_radius: float", "_brush_radius"); - node_shader_add_constant(kong, "brush_opacity: float", "_brush_opacity"); - node_shader_add_constant(kong, "brush_hardness: float", "_brush_hardness"); - - if (context_raw.tool == tool_type_t.ERASER || - context_raw.tool == tool_type_t.CLONE || - context_raw.tool == tool_type_t.BLUR || - context_raw.tool == tool_type_t.SMUDGE) { - - node_shader_write_frag(kong, "var dist: float = 0.0;"); - - node_shader_write_frag(kong, "var depth: float = sample_lod(gbufferD, sampler_linear, constants.inp.xy, 0.0).r;"); - - node_shader_add_constant(kong, "invVP: float4x4", "_inv_view_proj_matrix"); - node_shader_write_frag(kong, "var winp: float4 = float4(float2(constants.inp.x, 1.0 - constants.inp.y) * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);"); - node_shader_write_frag(kong, "winp = constants.invVP * winp;"); - node_shader_write_frag(kong, "winp.xyz = winp.xyz / winp.w;"); - kong.frag_wposition = true; - - node_shader_write_frag(kong, "var depthlast: float = sample_lod(gbufferD, sampler_linear, constants.inplast.xy, 0.0).r;"); - - node_shader_write_frag(kong, "var winplast: float4 = float4(float2(constants.inplast.x, 1.0 - constants.inplast.y) * 2.0 - 1.0, depthlast * 2.0 - 1.0, 1.0);"); - node_shader_write_frag(kong, "winplast = constants.invVP * winplast;"); - node_shader_write_frag(kong, "winplast.xyz = winplast.xyz / winplast.w;"); - - node_shader_write_frag(kong, "var pa: float3 = input.wposition - winp.xyz;"); - node_shader_write_frag(kong, "var ba: float3 = winplast.xyz - winp.xyz;"); - - // Capsule - node_shader_write_frag(kong, "var h: float = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);"); - node_shader_write_frag(kong, "dist = length(pa - ba * h);"); - - node_shader_write_frag(kong, "if (dist > constants.brush_radius) { discard; }"); - } - - if (context_raw.tool == tool_type_t.CLONE || context_raw.tool == tool_type_t.BLUR || context_raw.tool == tool_type_t.SMUDGE) { - node_shader_add_texture(kong, "gbuffer2"); - node_shader_add_constant(kong, "gbuffer_size: float2", "_gbuffer_size"); - node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo"); - node_shader_add_texture(kong, "texpaint_nor_undo", "_texpaint_nor_undo"); - node_shader_add_texture(kong, "texpaint_pack_undo", "_texpaint_pack_undo"); - - if (context_raw.tool == tool_type_t.CLONE) { - } - else { // Blur - } - } - - node_shader_write_frag(kong, "var opacity: float = 1.0;"); - node_shader_write_frag(kong, "if (opacity == 0.0) { discard; }"); - - node_shader_write_frag(kong, "var str: float = clamp((constants.brush_radius - dist) * constants.brush_hardness * 400.0, 0.0, 1.0) * opacity;"); - - // Manual blending to preserve memory - kong.frag_wvpposition = true; - node_shader_write_frag(kong, "var sample_tc: float2 = float2(input.wvpposition.x / input.wvpposition.w, input.wvpposition.y / input.wvpposition.w) * 0.5 + 0.5;"); - node_shader_write_frag(kong, "sample_tc.y = 1.0 - sample_tc.y;"); - node_shader_add_texture(kong, "paintmask"); - node_shader_write_frag(kong, "var sample_mask: float = sample_lod(paintmask, sampler_linear, sample_tc, 0.0).r;"); - node_shader_write_frag(kong, "str = max(str, sample_mask);"); - - node_shader_add_texture(kong, "texpaint_undo", "_texpaint_undo"); - node_shader_write_frag(kong, "var sample_undo: float4 = sample_lod(texpaint_undo, sampler_linear, sample_tc, 0.0);"); - - if (context_raw.tool == tool_type_t.ERASER) { - node_shader_write_frag(kong, "output[0] = float4(0.0, 0.0, 0.0, 0.0);"); - node_shader_write_frag(kong, "output[1] = float4(0.5, 0.5, 1.0, 0.0);"); - node_shader_write_frag(kong, "output[2] = float4(1.0, 0.0, 0.0, 0.0);"); - } - - node_shader_write_frag(kong, "output[3] = float4(str, 0.0, 0.0, 1.0);"); - - parser_material_finalize(con_paint); - parser_material_sample_keep_aspect = false; - con_paint.data.shader_from_source = true; - gpu_create_shaders_from_kong(node_shader_get(kong), ADDRESS(con_paint.data.vertex_shader), ADDRESS(con_paint.data.fragment_shader), ADDRESS(con_paint.data._.vertex_shader_size), ADDRESS(con_paint.data._.fragment_shader_size)); - - return con_paint; -} diff --git a/lab/sources/manifest.ts b/lab/sources/manifest.ts deleted file mode 100644 index 2e984bce..00000000 --- a/lab/sources/manifest.ts +++ /dev/null @@ -1,6 +0,0 @@ - -let manifest_title: string = "ArmorLab"; -let manifest_version: string = "0.2"; -let manifest_url: string = "https://armory3d.org/lab"; -let manifest_url_android: string = ""; -let manifest_url_ios: string = ""; diff --git a/lab/sources/nodes/brush_output_node_ext.ts b/lab/sources/nodes/brush_output_node_ext.ts deleted file mode 100644 index 0edd9037..00000000 --- a/lab/sources/nodes/brush_output_node_ext.ts +++ /dev/null @@ -1,186 +0,0 @@ - -type brush_output_node_t = { - base?: logic_node_t; - raw?: ui_node_t; - - id?: i32; - texpaint?: gpu_texture_t; - texpaint_nor?: gpu_texture_t; - texpaint_pack?: gpu_texture_t; - texpaint_nor_empty?: gpu_texture_t; - texpaint_pack_empty?: gpu_texture_t; -}; - -function brush_output_node_create_ext(n: brush_output_node_t) { - - n.base.get_as_image = brush_output_node_get_as_image; - - if (context_raw.brush_output_node_inst == null) { - { - let t: render_target_t = render_target_create(); - t.name = "texpaint"; - t.width = config_get_texture_res_x(); - t.height = config_get_texture_res_y(); - t.format = "RGBA32"; - n.texpaint = render_path_create_render_target(t)._image; - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_nor"; - t.width = config_get_texture_res_x(); - t.height = config_get_texture_res_y(); - t.format = "RGBA32"; - n.texpaint_nor = render_path_create_render_target(t)._image; - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_pack"; - t.width = config_get_texture_res_x(); - t.height = config_get_texture_res_y(); - t.format = "RGBA32"; - n.texpaint_pack = render_path_create_render_target(t)._image; - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_nor_empty"; - t.width = 1; - t.height = 1; - t.format = "RGBA32"; - n.texpaint_nor_empty = render_path_create_render_target(t)._image; - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_pack_empty"; - t.width = 1; - t.height = 1; - t.format = "RGBA32"; - n.texpaint_pack_empty = render_path_create_render_target(t)._image; - } - } - else { - n.texpaint = context_raw.brush_output_node_inst.texpaint; - n.texpaint_nor = context_raw.brush_output_node_inst.texpaint_nor; - n.texpaint_pack = context_raw.brush_output_node_inst.texpaint_pack; - } - - context_raw.brush_output_node_inst = n; -} - -function brush_output_node_get_as_image(self: brush_output_node_t, from: i32): gpu_texture_t { - return logic_node_input_get_as_image(self.base.inputs[from]); -} - -function brush_output_node_parse_inputs() { - if (!context_raw.registered) { - context_raw.registered = true; - sys_notify_on_update(brush_output_node_update); - } - - context_raw.paint_vec = context_raw.coords; -} - -function brush_output_node_run(from: i32) { - let left: f32 = 0.0; - let right: f32 = 1.0; - let top: f32 = 0.0; - let bottom: f32 = 1.0; - - // First time init - if (context_raw.last_paint_x < 0 || context_raw.last_paint_y < 0) { - context_raw.last_paint_vec_x = context_raw.paint_vec.x; - context_raw.last_paint_vec_y = context_raw.paint_vec.y; - } - - let nodes: ui_nodes_t = ui_nodes_get_nodes(); - let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true); - let inpaint: bool = nodes.nodes_selected_id.length > 0 && ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]).type == "inpaint_node"; - - // Paint bounds - if (inpaint && - context_raw.paint_vec.x > left && - context_raw.paint_vec.x < right && - context_raw.paint_vec.y > 0 && - context_raw.paint_vec.y < 1 && - !base_is_dragging && - !base_is_resizing && - !base_is_scrolling() && - !base_is_combo_selected()) { - - let down: bool = mouse_down() || pen_down(); - - // Prevent painting the same spot - let same_spot: bool = context_raw.paint_vec.x == context_raw.last_paint_x && context_raw.paint_vec.y == context_raw.last_paint_y; - if (down && same_spot) { - context_raw.painted++; - } - else { - context_raw.painted = 0; - } - context_raw.last_paint_x = context_raw.paint_vec.x; - context_raw.last_paint_y = context_raw.paint_vec.y; - - if (context_raw.painted == 0) { - brush_output_node_parse_inputs(); - } - - if (context_raw.painted <= 1) { - context_raw.pdirty = 1; - context_raw.rdirty = 2; - } - } -} - -function brush_output_node_update() { - let paint_x: f32 = mouse_view_x() / sys_w(); - let paint_y: f32 = mouse_view_y() / sys_h(); - if (mouse_started()) { - context_raw.start_x = mouse_view_x() / sys_w(); - context_raw.start_y = mouse_view_y() / sys_h(); - } - - if (pen_down()) { - paint_x = pen_view_x() / sys_w(); - paint_y = pen_view_y() / sys_h(); - } - if (pen_started()) { - context_raw.start_x = pen_view_x() / sys_w(); - context_raw.start_y = pen_view_y() / sys_h(); - } - - if (operator_shortcut(map_get(config_keymap, "brush_ruler") + "+" + map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN)) { - if (context_raw.lock_x) { - paint_x = context_raw.start_x; - } - if (context_raw.lock_y) { - paint_y = context_raw.start_y; - } - } - - context_raw.coords.x = paint_x; - context_raw.coords.y = paint_y; - - if (context_raw.lock_begin) { - let dx: i32 = math_abs(context_raw.lock_start_x - mouse_view_x()); - let dy: i32 = math_abs(context_raw.lock_start_y - mouse_view_y()); - if (dx > 1 || dy > 1) { - context_raw.lock_begin = false; - if (dx > dy) { - context_raw.lock_y = true; - } - else { - context_raw.lock_x = true; - } - } - } - - if (keyboard_started(map_get(config_keymap, "brush_ruler"))) { - context_raw.lock_start_x = mouse_view_x(); - context_raw.lock_start_y = mouse_view_y(); - context_raw.lock_begin = true; - } - else if (keyboard_released(map_get(config_keymap, "brush_ruler"))) { - context_raw.lock_x = context_raw.lock_y = context_raw.lock_begin = false; - } - - brush_output_node_parse_inputs(); -} diff --git a/lab/sources/nodes/image_texture_node.ts b/lab/sources/nodes/image_texture_node.ts deleted file mode 100644 index 437fbac4..00000000 --- a/lab/sources/nodes/image_texture_node.ts +++ /dev/null @@ -1,102 +0,0 @@ - -type image_texture_node_t = { - base?: logic_node_t; - raw?: ui_node_t; -}; - -function image_texture_node_create(raw: ui_node_t, args: f32_array_t): image_texture_node_t { - let n: image_texture_node_t = {}; - n.base = logic_node_create(n); - n.base.get_as_image = image_texture_node_get_as_image; - n.base.get_cached_image = image_texture_node_get_cached_image; - n.raw = raw; - return n; -} - -function image_texture_node_get_as_image(self: image_texture_node_t, from: i32): gpu_texture_t { - if (project_assets.length == 0) { - return null; - } - let index: i32 = self.raw.buttons[0].default_value[0]; - let asset: asset_t = project_assets[index]; - return project_get_image(asset); -} - -function image_texture_node_get_cached_image(self: image_texture_node_t): gpu_texture_t { - let image: gpu_texture_t = self.base.get_as_image(self, 0); - return image; -} - -let image_texture_node_def: ui_node_t = { - id: 0, - name: _tr("Image Texture"), - type: "image_texture_node", - x: 0, - y: 0, - color: 0xff4982a0, - inputs: [ - { - id: 0, - node_id: 0, - name: _tr("Vector"), - type: "VECTOR", - color: 0xff6363c7, - default_value: f32_array_create_xyz(0.0, 0.0, 0.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - outputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - }, - { - id: 0, - node_id: 0, - name: _tr("Alpha"), - type: "VALUE", - color: 0xffa1a1a1, - default_value: f32_array_create_x(1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - buttons: [ - { - name: _tr("file"), - type: "ENUM", - output: -1, - default_value: f32_array_create_x(0), - data: u8_array_create_from_string(""), - min: 0.0, - max: 1.0, - precision: 100, - height: 0 - }, - { - name: _tr("color_space"), - type: "ENUM", - output: -1, - default_value: f32_array_create_x(0), - data: u8_array_create_from_string("linear\nsrgb"), - min: 0.0, - max: 1.0, - precision: 100, - height: 0 - } - ], - width: 0 -}; diff --git a/lab/sources/nodes/inpaint_node.ts b/lab/sources/nodes/inpaint_node.ts deleted file mode 100644 index 97d99b63..00000000 --- a/lab/sources/nodes/inpaint_node.ts +++ /dev/null @@ -1,255 +0,0 @@ - -///include "../plugins/proc_texsynth/proc_texsynth.h" - -type inpaint_node_t = { - base?: logic_node_t; -}; - -let inpaint_node_image: gpu_texture_t = null; -let inpaint_node_mask: gpu_texture_t = null; -let inpaint_node_result: gpu_texture_t = null; - -let inpaint_node_temp: gpu_texture_t = null; -let inpaint_node_prompt: string = ""; -let inpaint_node_strength: f32 = 0.5; -let inpaint_node_auto: bool = true; - -function inpaint_node_create(raw: ui_node_t, args: f32_array_t): inpaint_node_t { - let n: inpaint_node_t = {}; - n.base = logic_node_create(n); - n.base.get_as_image = inpaint_node_get_as_image; - n.base.get_cached_image = inpaint_node_get_cached_image; - - inpaint_node_init(); - - return n; -} - -function inpaint_node_init() { - if (inpaint_node_image == null) { - inpaint_node_image = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y()); - } - - if (inpaint_node_mask == null) { - inpaint_node_mask = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8); - sys_notify_on_next_frame(function () { - _gpu_begin(inpaint_node_mask, null, null, clear_flag_t.COLOR, color_from_floats(1.0, 1.0, 1.0, 1.0)); - gpu_end(); - }); - } - - if (inpaint_node_temp == null) { - inpaint_node_temp = gpu_create_render_target(512, 512); - } - - if (inpaint_node_result == null) { - inpaint_node_result = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y()); - } -} - -function inpaint_node_button(node_id: i32) { - let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); - - inpaint_node_auto = node.buttons[0].default_value[0] == 0 ? false : true; - if (!inpaint_node_auto) { - - let inpaint_node_strength_handle: ui_handle_t = ui_handle(__ID__); - if (inpaint_node_strength_handle.init) { - inpaint_node_strength_handle.value = inpaint_node_strength; - } - - inpaint_node_strength = ui_slider(inpaint_node_strength_handle, tr("strength"), 0, 1, true); - inpaint_node_prompt = ui_text_area(ui_handle(__ID__), ui_align_t.LEFT, true, tr("prompt"), true); - node.buttons[1].height = 1 + string_split(inpaint_node_prompt, "\n").length; - } - else { - node.buttons[1].height = 0; - } -} - -function inpaint_node_get_as_image(self: inpaint_node_t, from: i32): gpu_texture_t { - let source: gpu_texture_t = logic_node_input_get_as_image(self.base.inputs[0]); - console_progress(tr("Processing") + " - " + tr("Inpaint")); - - draw_begin(inpaint_node_image); - draw_scaled_image(source, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - draw_end(); - - if (inpaint_node_auto) { - return inpaint_node_texsynth_inpaint(inpaint_node_image, false, inpaint_node_mask); - } - else { - return inpaint_node_sd_inpaint(inpaint_node_image, inpaint_node_mask); - } -} - -function inpaint_node_get_cached_image(self: inpaint_node_t): gpu_texture_t { - sys_notify_on_next_frame(function (self: inpaint_node_t) { - let source: gpu_texture_t = logic_node_input_get_as_image(self.base.inputs[0]); - _gpu_begin(inpaint_node_image); - gpu_set_pipeline(pipes_inpaint_preview); - gpu_set_texture(pipes_tex0_inpaint_preview, source); - gpu_set_texture(pipes_texa_inpaint_preview, inpaint_node_mask); - gpu_set_vertex_buffer(const_data_screen_aligned_vb); - gpu_set_index_buffer(const_data_screen_aligned_ib); - gpu_draw(); - gpu_end(); - }, self); - return inpaint_node_image; -} - -function inpaint_node_get_target(): gpu_texture_t { - return inpaint_node_mask; -} - -function inpaint_node_texsynth_inpaint(image: gpu_texture_t, tiling: bool, mask: gpu_texture_t): gpu_texture_t { - let w: i32 = config_get_texture_res_x(); - let h: i32 = config_get_texture_res_y(); - - let bytes_img: buffer_t = gpu_get_texture_pixels(image); - let bytes_mask: buffer_t = mask != null ? gpu_get_texture_pixels(mask) : buffer_create(w * h); - let bytes_out: buffer_t = buffer_create(w * h * 4); - texsynth_inpaint(w, h, bytes_out.buffer, bytes_img.buffer, bytes_mask.buffer, tiling); - - inpaint_node_result = gpu_create_texture_from_bytes(bytes_out, w, h); - return inpaint_node_result; -} - -function inpaint_node_sd_inpaint(image: gpu_texture_t, mask: gpu_texture_t): gpu_texture_t { - inpaint_node_init(); - - let bytes_img: buffer_t = gpu_get_texture_pixels(mask); - let u8_img: buffer_t = bytes_img; - let f32mask: f32_array_t = f32_array_create(4 * 64 * 64); - - let vae_encoder_blob: buffer_t = data_get_blob("models/sd_vae_encoder.quant.onnx"); - // for (let x: i32 = 0; x < math_floor(image.width / 512); ++x) { - // for (let y: i32 = 0; y < math_floor(image.height / 512); ++y) { - let x: i32 = 0; - let y: i32 = 0; - - for (let xx: i32 = 0; xx < 64; ++xx) { - for (let yy: i32 = 0; yy < 64; ++yy) { - // let step = math_floor(512 / 64); - // let j = (yy * step * mask.width + xx * step) + (y * 512 * mask.width + x * 512); - let step: i32 = math_floor(mask.width / 64); - let j: i32 = (yy * step * mask.width + xx * step); - let f: f32 = u8_img[j] / 255.0; - let i: i32 = yy * 64 + xx; - f32mask[i ] = f; - f32mask[i + 64 * 64 ] = f; - f32mask[i + 64 * 64 * 2] = f; - f32mask[i + 64 * 64 * 3] = f; - } - } - - draw_begin(inpaint_node_temp); - // g2_drawImage(image, -x * 512, -y * 512); - draw_scaled_image(image, 0, 0, 512, 512); - draw_end(); - - bytes_img = gpu_get_texture_pixels(inpaint_node_temp); - let u8a: buffer_t = bytes_img; - let f32a: f32_array_t = f32_array_create(3 * 512 * 512); - for (let i: i32 = 0; i < (512 * 512); ++i) { - f32a[i ] = (u8a[i * 4 ] / 255.0) * 2.0 - 1.0; - f32a[i + 512 * 512 ] = (u8a[i * 4 + 1] / 255.0) * 2.0 - 1.0; - f32a[i + 512 * 512 * 2] = (u8a[i * 4 + 2] / 255.0) * 2.0 - 1.0; - } - - let tensors: buffer_t[] = [buffer_create_from_raw(f32a.buffer, f32a.length * 4)]; - let input_shape: i32_array_t[] = []; - let input_shape0: i32[] = [1, 3, 512, 512]; - array_push(input_shape, input_shape0); - let output_shape: i32[] = [1, 4, 64, 64]; - let latents_buf: buffer_t = iron_ml_inference(vae_encoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference); - let latents: f32_array_t = f32_array_create_from_buffer(latents_buf); - for (let i: i32 = 0; i < latents.length; ++i) { - latents[i] = 0.18215 * latents[i]; - } - let latents_orig: f32_array_t = array_slice(latents, 0, latents.length); - - let noise: f32_array_t = f32_array_create(latents.length); - for (let i: i32 = 0; i < noise.length; ++i) { - noise[i] = math_cos(2.0 * 3.14 * random_node_get_float()) * math_sqrt(-2.0 * math_log(random_node_get_float())); - } - - let num_inference_steps: i32 = 50; - let init_timestep: i32 = math_floor(num_inference_steps * inpaint_node_strength); - let timestep: i32 = text_to_photo_node_timesteps[num_inference_steps - init_timestep]; - let alphas_cumprod: f32[] = text_to_photo_node_alphas_cumprod; - let sqrt_alpha_prod: f32 = math_pow(alphas_cumprod[timestep], 0.5); - let sqrt_one_minus_alpha_prod: f32 = math_pow(1.0 - alphas_cumprod[timestep], 0.5); - for (let i: i32 = 0; i < latents.length; ++i) { - latents[i] = sqrt_alpha_prod * latents[i] + sqrt_one_minus_alpha_prod * noise[i]; - } - - let start: i32 = num_inference_steps - init_timestep; - - inpaint_node_result = text_to_photo_node_stable_diffusion(inpaint_node_prompt, latents, start, true, f32mask, latents_orig); - return inpaint_node_result; - // } - // } -} - -let inpaint_node_def: ui_node_t = { - id: 0, - name: _tr("Inpaint"), - type: "inpaint_node", - x: 0, - y: 0, - color: 0xff4982a0, - inputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(1.0, 1.0, 1.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - outputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - buttons: [ - { - name: _tr("auto"), - type: "BOOL", - output: 0, - default_value: f32_array_create_x(1), - data: null, - min: 0.0, - max: 1.0, - precision: 100, - height: 0 - }, - { - name: "inpaint_node_button", - type: "CUSTOM", - output: -1, - default_value: f32_array_create_x(0), - data: null, - min: 0.0, - max: 1.0, - precision: 100, - height: 0 - } - ], - width: 0 -}; diff --git a/lab/sources/nodes/photo_to_pbr_node.ts b/lab/sources/nodes/photo_to_pbr_node.ts deleted file mode 100644 index d146f618..00000000 --- a/lab/sources/nodes/photo_to_pbr_node.ts +++ /dev/null @@ -1,275 +0,0 @@ - -type photo_to_pbr_node_t = { - base?: logic_node_t; -}; - -let photo_to_pbr_node_temp: gpu_texture_t = null; -let photo_to_pbr_node_images: gpu_texture_t[] = null; -let photo_to_pbr_node_model_names: string[] = ["base", "occlusion", "roughness", "metallic", "normal", "height"]; - -let photo_to_pbr_node_cached_source: gpu_texture_t = null; -let photo_to_pbr_node_border_w: i32 = 64; -let photo_to_pbr_node_tile_w: i32 = 2048; -let photo_to_pbr_node_tile_with_border_w: i32 = photo_to_pbr_node_tile_w + photo_to_pbr_node_border_w * 2; - -function photo_to_pbr_node_create(raw: ui_node_t, args: f32_array_t): photo_to_pbr_node_t { - let n: photo_to_pbr_node_t = {}; - n.base = logic_node_create(n); - n.base.get_as_image = photo_to_pbr_node_get_as_image; - - if (photo_to_pbr_node_temp == null) { - photo_to_pbr_node_temp = gpu_create_render_target(photo_to_pbr_node_tile_with_border_w, photo_to_pbr_node_tile_with_border_w); - } - - photo_to_pbr_node_init(); - - return n; -} - -function photo_to_pbr_node_init() { - if (photo_to_pbr_node_images == null) { - photo_to_pbr_node_images = []; - for (let i: i32 = 0; i < photo_to_pbr_node_model_names.length; ++i) { - array_push(photo_to_pbr_node_images, gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y())); - } - } -} - -function photo_to_pbr_node_get_as_image(self: photo_to_pbr_node_t, from: i32): gpu_texture_t { - - let source: gpu_texture_t; - if (photo_to_pbr_node_cached_source != null) { - source = photo_to_pbr_node_cached_source; - } - else { - source = logic_node_input_get_as_image(self.base.inputs[0]); - } - - photo_to_pbr_node_cached_source = source; - - console_progress(tr("Processing") + " - " + tr("Photo to PBR")); - - let tile_floats: f32_array_t[] = []; - let tiles_x: i32 = math_floor(config_get_texture_res_x() / photo_to_pbr_node_tile_w); - let tiles_y: i32 = math_floor(config_get_texture_res_y() / photo_to_pbr_node_tile_w); - let num_tiles: i32 = tiles_x * tiles_y; - for (let i: i32 = 0; i < num_tiles; ++i) { - let x: i32 = i % tiles_x; - let y: i32 = math_floor(i / tiles_x); - - draw_begin(photo_to_pbr_node_temp); - draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w, -config_get_texture_res_x(), config_get_texture_res_y()); - draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w, config_get_texture_res_x(), -config_get_texture_res_y()); - draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w, -config_get_texture_res_x(), -config_get_texture_res_y()); - draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, config_get_texture_res_x(), config_get_texture_res_y()); - draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, -config_get_texture_res_x(), config_get_texture_res_y()); - draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w + photo_to_pbr_node_tile_w, config_get_texture_res_x(), -config_get_texture_res_y()); - draw_scaled_image(source, photo_to_pbr_node_border_w - x * photo_to_pbr_node_tile_w, photo_to_pbr_node_border_w - y * photo_to_pbr_node_tile_w, config_get_texture_res_x(), config_get_texture_res_y()); - draw_end(); - - let bytes_img: buffer_t = gpu_get_texture_pixels(photo_to_pbr_node_temp); - let u8a: buffer_t = bytes_img; - let f32a: f32_array_t = f32_array_create(3 * photo_to_pbr_node_tile_with_border_w * photo_to_pbr_node_tile_with_border_w); - for (let i: i32 = 0; i < (photo_to_pbr_node_tile_with_border_w * photo_to_pbr_node_tile_with_border_w); ++i) { - f32a[i] = (u8a[i * 4] / 255 - 0.5) / 0.5; - f32a[i + photo_to_pbr_node_tile_with_border_w * photo_to_pbr_node_tile_with_border_w ] = (u8a[i * 4 + 1] / 255 - 0.5) / 0.5; - f32a[i + photo_to_pbr_node_tile_with_border_w * photo_to_pbr_node_tile_with_border_w * 2] = (u8a[i * 4 + 2] / 255 - 0.5) / 0.5; - } - - let model_blob: buffer_t = data_get_blob("models/photo_to_" + photo_to_pbr_node_model_names[from] + ".quant.onnx"); - let tensors: buffer_t[] = [buffer_create_from_raw(f32a.buffer, f32a.length * 4)]; - let buf: buffer_t = iron_ml_inference(model_blob, tensors, null, null, config_raw.gpu_inference); - let ar: f32_array_t = f32_array_create_from_buffer(buf); - u8a = u8_array_create(4 * photo_to_pbr_node_tile_w * photo_to_pbr_node_tile_w); - let offset_g: i32 = (from == channel_type_t.BASE_COLOR || from == channel_type_t.NORMAL_MAP) ? photo_to_pbr_node_tile_with_border_w * photo_to_pbr_node_tile_with_border_w : 0; - let offset_b: i32 = (from == channel_type_t.BASE_COLOR || from == channel_type_t.NORMAL_MAP) ? photo_to_pbr_node_tile_with_border_w * photo_to_pbr_node_tile_with_border_w * 2 : 0; - for (let i: i32 = 0; i < (photo_to_pbr_node_tile_w * photo_to_pbr_node_tile_w); ++i) { - let x: i32 = photo_to_pbr_node_border_w + i % photo_to_pbr_node_tile_w; - let y: i32 = photo_to_pbr_node_border_w + math_floor(i / photo_to_pbr_node_tile_w); - u8a[i * 4 ] = math_floor((ar[y * photo_to_pbr_node_tile_with_border_w + x ] * 0.5 + 0.5) * 255); - u8a[i * 4 + 1] = math_floor((ar[y * photo_to_pbr_node_tile_with_border_w + x + offset_g] * 0.5 + 0.5) * 255); - u8a[i * 4 + 2] = math_floor((ar[y * photo_to_pbr_node_tile_with_border_w + x + offset_b] * 0.5 + 0.5) * 255); - u8a[i * 4 + 3] = 255; - } - array_push(tile_floats, ar); - - // Use border pixels to blend seams - if (i > 0) { - if (x > 0) { - let ar: f32_array_t = tile_floats[i - 1]; - for (let yy: i32 = 0; yy < photo_to_pbr_node_tile_w; ++yy) { - for (let xx: i32 = 0; xx < photo_to_pbr_node_border_w; ++xx) { - let i: i32 = yy * photo_to_pbr_node_tile_w + xx; - let a: i32 = u8a[i * 4]; - let b: i32 = u8a[i * 4 + 1]; - let c: i32 = u8a[i * 4 + 2]; - - let aa: i32 = math_floor((ar[(photo_to_pbr_node_border_w + yy) * photo_to_pbr_node_tile_with_border_w + photo_to_pbr_node_border_w + photo_to_pbr_node_tile_w + xx ] * 0.5 + 0.5) * 255); - let bb: i32 = math_floor((ar[(photo_to_pbr_node_border_w + yy) * photo_to_pbr_node_tile_with_border_w + photo_to_pbr_node_border_w + photo_to_pbr_node_tile_w + xx + offset_g] * 0.5 + 0.5) * 255); - let cc: i32 = math_floor((ar[(photo_to_pbr_node_border_w + yy) * photo_to_pbr_node_tile_with_border_w + photo_to_pbr_node_border_w + photo_to_pbr_node_tile_w + xx + offset_b] * 0.5 + 0.5) * 255); - - let f: f32 = xx / photo_to_pbr_node_border_w; - let invf: f32 = 1.0 - f; - a = math_floor(a * f + aa * invf); - b = math_floor(b * f + bb * invf); - c = math_floor(c * f + cc * invf); - - u8a[i * 4 ] = a; - u8a[i * 4 + 1] = b; - u8a[i * 4 + 2] = c; - } - } - } - if (y > 0) { - let ar: f32_array_t = tile_floats[i - tiles_x]; - for (let xx: i32 = 0; xx < photo_to_pbr_node_tile_w; ++xx) { - for (let yy: i32 = 0; yy < photo_to_pbr_node_border_w; ++yy) { - let i: i32 = yy * photo_to_pbr_node_tile_w + xx; - let a: i32 = u8a[i * 4]; - let b: i32 = u8a[i * 4 + 1]; - let c: i32 = u8a[i * 4 + 2]; - - let aa: i32 = math_floor((ar[(photo_to_pbr_node_border_w + photo_to_pbr_node_tile_w + yy) * photo_to_pbr_node_tile_with_border_w + photo_to_pbr_node_border_w + xx ] * 0.5 + 0.5) * 255); - let bb: i32 = math_floor((ar[(photo_to_pbr_node_border_w + photo_to_pbr_node_tile_w + yy) * photo_to_pbr_node_tile_with_border_w + photo_to_pbr_node_border_w + xx + offset_g] * 0.5 + 0.5) * 255); - let cc: i32 = math_floor((ar[(photo_to_pbr_node_border_w + photo_to_pbr_node_tile_w + yy) * photo_to_pbr_node_tile_with_border_w + photo_to_pbr_node_border_w + xx + offset_b] * 0.5 + 0.5) * 255); - - let f: f32 = yy / photo_to_pbr_node_border_w; - let invf: f32 = 1.0 - f; - a = math_floor(a * f + aa * invf); - b = math_floor(b * f + bb * invf); - c = math_floor(c * f + cc * invf); - - u8a[i * 4 ] = a; - u8a[i * 4 + 1] = b; - u8a[i * 4 + 2] = c; - } - } - } - } - - ///if IRON_BGRA - if (from == channel_type_t.BASE_COLOR) { - photo_to_pbr_node_bgra_swap(u8a); - } - ///end - - let temp2: gpu_texture_t = gpu_create_texture_from_bytes(u8a, photo_to_pbr_node_tile_w, photo_to_pbr_node_tile_w); - draw_begin(photo_to_pbr_node_images[from]); - draw_image(temp2, x * photo_to_pbr_node_tile_w, y * photo_to_pbr_node_tile_w); - draw_end(); - iron_delete_texture(temp2); - } - - return photo_to_pbr_node_images[from]; -} - -///if IRON_BGRA -function photo_to_pbr_node_bgra_swap(buffer: buffer_t): buffer_t { - let u8a: buffer_t = buffer; - for (let i: i32 = 0; i < math_floor(buffer.length / 4); ++i) { - let r: i32 = u8a[i * 4]; - u8a[i * 4] = u8a[i * 4 + 2]; - u8a[i * 4 + 2] = r; - } - return buffer; -} -///end - -let photo_to_pbr_node_def: ui_node_t = { - id: 0, - name: _tr("Photo to PBR"), - type: "photo_to_pbr_node", - x: 0, - y: 0, - color: 0xff4982a0, - inputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - outputs: [ - { - id: 0, - node_id: 0, - name: _tr("Base Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - }, - { - id: 0, - node_id: 0, - name: _tr("Occlusion"), - type: "VALUE", - color: 0xffa1a1a1, - default_value: f32_array_create_x(1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - }, - { - id: 0, - node_id: 0, - name: _tr("Roughness"), - type: "VALUE", - color: 0xffa1a1a1, - default_value: f32_array_create_x(1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - }, - { - id: 0, - node_id: 0, - name: _tr("Metallic"), - type: "VALUE", - color: 0xffa1a1a1, - default_value: f32_array_create_x(0.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - }, - { - id: 0, - node_id: 0, - name: _tr("Normal Map"), - type: "VECTOR", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - }, - { - id: 0, - node_id: 0, - name: _tr("Height"), - type: "VALUE", - color: 0xffa1a1a1, - default_value: f32_array_create_x(1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - buttons: [], - width: 0 -}; diff --git a/lab/sources/nodes/rgb_node.ts b/lab/sources/nodes/rgb_node.ts deleted file mode 100644 index 14eafbb8..00000000 --- a/lab/sources/nodes/rgb_node.ts +++ /dev/null @@ -1,75 +0,0 @@ - -type rgb_node_t = { - base?: logic_node_t; - image?: gpu_texture_t; - raw?: ui_node_t; -}; - -function rgb_node_create(raw: ui_node_t, args: f32_array_t): rgb_node_t { - let n: rgb_node_t = {}; - n.raw = raw; - n.base = logic_node_create(n); - n.base.get_as_image = rgb_node_get_as_image; - n.base.get_cached_image = rgb_node_get_cached_image; - return n; -} - -function rgb_node_get_as_image(self: rgb_node_t, from: i32): gpu_texture_t { - if (self.image != null) { - iron_delete_texture(self.image); - } - - let f32a: f32_array_t = f32_array_create(4); - let raw: ui_node_t = self.raw; - let default_value: f32_array_t = raw.outputs[0].default_value; - f32a[0] = default_value[0]; - f32a[1] = default_value[1]; - f32a[2] = default_value[2]; - f32a[3] = default_value[3]; - let buf: buffer_t = buffer_create_from_raw(f32a.buffer, f32a.length * 4); - self.image = gpu_create_texture_from_bytes(buf, 1, 1, tex_format_t.RGBA128); - return self.image; -} - -function rgb_node_get_cached_image(self: rgb_node_t): gpu_texture_t { - self.base.get_as_image(self, 0); - return self.image; -} - -let rgb_node_def: ui_node_t = { - id: 0, - name: _tr("RGB"), - type: "rgb_node", - x: 0, - y: 0, - color: 0xffb34f5a, - inputs: [], - outputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - buttons: [ - { - name: _tr("default_value"), - type: "RGBA", - output: 0, - default_value: f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0), - data: null, - min: 0.0, - max: 1.0, - precision: 100, - height: 0 - } - ], - width: 0 -}; diff --git a/lab/sources/nodes/text_to_photo_node.ts b/lab/sources/nodes/text_to_photo_node.ts deleted file mode 100644 index 5f9cab4a..00000000 --- a/lab/sources/nodes/text_to_photo_node.ts +++ /dev/null @@ -1,534 +0,0 @@ - -type text_to_photo_node_t = { - base?: logic_node_t; -}; - -let text_to_photo_node_prompt: string = ""; -let text_to_photo_node_image: gpu_texture_t = null; -let text_to_photo_node_tiling: bool = false; -let text_to_photo_node_text_encoder_blob: buffer_t; -let text_to_photo_node_unet_blob: buffer_t; -let text_to_photo_node_vae_decoder_blob: buffer_t; - -function text_to_photo_node_create(raw: ui_node_t, args: f32_array_t): text_to_photo_node_t { - let n: text_to_photo_node_t = {}; - n.base = logic_node_create(n); - n.base.get_as_image = text_to_photo_node_get_as_image; - n.base.get_cached_image = text_to_photo_node_get_cached_image; - return n; -} - -function text_to_photo_node_get_as_image(self: text_to_photo_node_t, from: i32): gpu_texture_t { - text_to_photo_node_image = text_to_photo_node_stable_diffusion(text_to_photo_node_prompt); - return text_to_photo_node_image; -} - -function text_to_photo_node_get_cached_image(self: text_to_photo_node_t): gpu_texture_t { - return text_to_photo_node_image; -} - -function text_to_photo_node_button(node_id: i32) { - let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); - - text_to_photo_node_tiling = node.buttons[0].default_value[0] == 0 ? false : true; - text_to_photo_node_prompt = ui_text_area(ui_handle(__ID__), ui_align_t.LEFT, true, tr("prompt"), true); - node.buttons[1].height = string_split(text_to_photo_node_prompt, "\n").length; -} - -function text_to_photo_node_stable_diffusion(prompt: string, inpaint_latents: f32_array_t = null, offset: i32 = 0, upscale: bool = true, mask: f32_array_t = null, latents_orig: f32_array_t = null): gpu_texture_t { - let _text_encoder_blob: buffer_t = data_get_blob("models/sd_text_encoder.quant.onnx"); - let _unet_blob: buffer_t = data_get_blob("models/sd_unet.quant.onnx"); - let _vae_decoder_blob: buffer_t = data_get_blob("models/sd_vae_decoder.quant.onnx"); - text_to_photo_node_text_encoder_blob = _text_encoder_blob; - text_to_photo_node_unet_blob = _unet_blob; - text_to_photo_node_vae_decoder_blob = _vae_decoder_blob; - let enc: text_encoder_result_t = text_to_photo_node_text_encoder(prompt, inpaint_latents); - let latents: f32_array_t = text_to_photo_node_unet(enc.latents, enc.text_embeddings, mask, latents_orig, offset); - return text_to_photo_node_vae_decoder(latents, upscale); -} - -type text_encoder_result_t = { - latents?: f32_array_t; - text_embeddings?: f32_array_t; -}; - -function text_to_photo_node_text_encoder(prompt: string, inpaint_latents: f32_array_t): text_encoder_result_t { - console_progress(tr("Processing") + " - " + tr("Text to Photo")); - - let words: string[] = string_split( - trim_end(string_replace_all(string_replace_all(string_replace_all(prompt, "\n", " "), ",", " , "), " ", " ")), " " - ); - - if (text_to_photo_node_vocab == null) { - let vocab_buffer: buffer_t = data_get_blob("models/vocab.json"); - let vocab_json: string = sys_buffer_to_string(vocab_buffer); - text_to_photo_node_vocab = json_parse_to_map(vocab_json); - } - - for (let i: i32 = 0; i < words.length; ++i) { - let word: string = to_lower_case(words[i]) + ""; - let value_string: string = map_get(text_to_photo_node_vocab, word); - let value: i32 = parse_int(value_string); - text_to_photo_node_text_input_ids[i + 1] = value; - } - for (let i: i32 = words.length; i < (text_to_photo_node_text_input_ids.length - 1); ++i) { - text_to_photo_node_text_input_ids[i + 1] = 49407; // <|endoftext|> - } - - let i32a: i32_array_t = i32_array_create_from_array(text_to_photo_node_text_input_ids); - let tensors: buffer_t[] = [buffer_create_from_raw(i32a.buffer, i32a.length * 4)]; - let input_shape: i32_array_t[] = []; - let input_shape0: i32[] = [1, 77]; - array_push(input_shape, input_shape0); - let output_shape: i32[] = [1, 77, 768]; - let text_embeddings_buf: buffer_t = iron_ml_inference(text_to_photo_node_text_encoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference); - let text_embeddings: f32_array_t = f32_array_create_from_buffer(text_embeddings_buf); - - i32a = i32_array_create_from_array(text_to_photo_node_uncond_input_ids); - tensors = [buffer_create_from_raw(i32a.buffer, i32a.length * 4)]; - let uncond_embeddings_buf: buffer_t = iron_ml_inference(text_to_photo_node_text_encoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference); - let uncond_embeddings: f32_array_t = f32_array_create_from_buffer(uncond_embeddings_buf); - - let f32a: f32_array_t = f32_array_create(uncond_embeddings.length + text_embeddings.length); - for (let i: i32 = 0; i < uncond_embeddings.length; ++i) f32a[i] = uncond_embeddings[i]; - for (let i: i32 = 0; i < text_embeddings.length; ++i) f32a[i + uncond_embeddings.length] = text_embeddings[i]; - text_embeddings = f32a; - - let width: i32 = 512; - let height: i32 = 512; - let latents: f32_array_t = f32_array_create(1 * 4 * math_floor(height / 8) * math_floor(width / 8)); - if (inpaint_latents == null) { - for (let i: i32 = 0; i < latents.length; ++i) latents[i] = math_cos(2.0 * 3.14 * random_node_get_float()) * math_sqrt(-2.0 * math_log(random_node_get_float())); - } - else { - for (let i: i32 = 0; i < latents.length; ++i) latents[i] = inpaint_latents[i]; - } - - let res: text_encoder_result_t = { - latents: latents, - text_embeddings: text_embeddings - }; - return res; -} - -function text_to_photo_node_unet(latents: f32_array_t, text_embeddings: f32_array_t, mask: f32_array_t, latents_orig: f32_array_t, offset: i32): f32_array_t { - let latent_model_input: f32_array_t = f32_array_create(latents.length * 2); - let noise_pred_uncond: f32_array_t = f32_array_create(latents.length); - let noise_pred_text: f32_array_t = f32_array_create(latents.length); - - let cur_latents: f32_array_t = null; - let num_train_timesteps: i32 = 1000; - let num_inference_steps: i32 = 50; - let ets: f32_array_t[] = []; - let counter: i32 = 0; - - while (true) { - let a: i32 = counter; - let b: i32 = 50 - offset; - console_progress(tr("Processing") + " - " + tr("Text to Photo") + " (" + a + "/" + b + ")"); - - let timestep: i32 = text_to_photo_node_timesteps[counter + offset]; - for (let i: i32 = 0; i < latents.length; ++i) latent_model_input[i] = latents[i]; - for (let i: i32 = 0; i < latents.length; ++i) latent_model_input[i + latents.length] = latents[i]; - - let t32: i32_array_t = i32_array_create(2); - t32[0] = timestep; - let tensors: buffer_t[] = [ - buffer_create_from_raw(latent_model_input.buffer, latent_model_input.length * 4), - buffer_create_from_raw(t32.buffer, t32.length * 4), - buffer_create_from_raw(text_embeddings.buffer, text_embeddings.length * 4), - ]; - let input_shape: i32_array_t[] = []; - let input_shape0: i32[] = [2, 4, 64, 64]; - let input_shape1: i32[] = [1]; - let input_shape2: i32[] = [2, 77, 768]; - array_push(input_shape, input_shape0); - array_push(input_shape, input_shape1); - array_push(input_shape, input_shape2); - let output_shape: i32[] = [2, 4, 64, 64]; - let noise_pred_buf: buffer_t = iron_ml_inference(text_to_photo_node_unet_blob, tensors, input_shape, output_shape, config_raw.gpu_inference); - let noise_pred: f32_array_t = f32_array_create_from_buffer(noise_pred_buf); - - for (let i: i32 = 0; i < noise_pred_uncond.length; ++i) noise_pred_uncond[i] = noise_pred[i]; - for (let i: i32 = 0; i < noise_pred_text.length; ++i) noise_pred_text[i] = noise_pred[noise_pred_uncond.length + i]; - - let guidance_scale: f32 = 7.5; - noise_pred = f32_array_create(noise_pred_uncond.length); - for (let i: i32 = 0; i < noise_pred_uncond.length; ++i) { - noise_pred[i] = noise_pred_uncond[i] + guidance_scale * (noise_pred_text[i] - noise_pred_uncond[i]); - } - - let prev_timestep: i32 = math_floor(math_max(timestep - math_floor(num_train_timesteps / num_inference_steps), 0)); - - if (counter != 1) { - array_push(ets, noise_pred); - } - else { - prev_timestep = timestep; - timestep = timestep + math_floor(num_train_timesteps / num_inference_steps); - } - - if (ets.length == 1 && counter == 0) { - cur_latents = latents; - } - else if (ets.length == 1 && counter == 1) { - let _noise_pred: f32_array_t = f32_array_create(noise_pred.length); - for (let i: i32 = 0; i < noise_pred.length; ++i) { - _noise_pred[i] = (noise_pred[i] + ets[ets.length - 1][i]) / 2; - } - noise_pred = _noise_pred; - latents = cur_latents; - cur_latents = null; - } - else if (ets.length == 2) { - let _noise_pred: f32_array_t = f32_array_create(noise_pred.length); - for (let i: i32 = 0; i < noise_pred.length; ++i) { - _noise_pred[i] = (3 * ets[ets.length - 1][i] - ets[ets.length - 2][i]) / 2; - } - noise_pred = _noise_pred; - } - else if (ets.length == 3) { - let _noise_pred: f32_array_t = f32_array_create(noise_pred.length); - for (let i: i32 = 0; i < noise_pred.length; ++i) { - _noise_pred[i] = (23 * ets[ets.length - 1][i] - 16 * ets[ets.length - 2][i] + 5 * ets[ets.length - 3][i]) / 12; - } - noise_pred = _noise_pred; - } - else { - let _noise_pred: f32_array_t = f32_array_create(noise_pred.length); - for (let i: i32 = 0; i < noise_pred.length; ++i) { - _noise_pred[i] = (1 / 24) * (55 * ets[ets.length - 1][i] - 59 * ets[ets.length - 2][i] + 37 * ets[ets.length - 3][i] - 9 * ets[ets.length - 4][i]); - } - noise_pred = _noise_pred; - } - - let alpha_prod_t: f32 = text_to_photo_node_alphas_cumprod[timestep + 1]; - let alpha_prod_t_prev: f32 = text_to_photo_node_alphas_cumprod[prev_timestep + 1]; - let beta_prod_t: f32 = 1 - alpha_prod_t; - let beta_prod_t_prev: f32 = 1 - alpha_prod_t_prev; - let latents_coeff: f32 = math_pow(alpha_prod_t_prev / alpha_prod_t, (0.5)); - let noise_pred_denom_coeff: f32 = alpha_prod_t * math_pow(beta_prod_t_prev, (0.5)) + math_pow(alpha_prod_t * beta_prod_t * alpha_prod_t_prev, (0.5)); - for (let i: i32 = 0; i < latents.length; ++i) { - latents[i] = (latents_coeff * latents[i] - (alpha_prod_t_prev - alpha_prod_t) * noise_pred[i] / noise_pred_denom_coeff); - } - counter += 1; - - if (mask != null) { - let noise: f32_array_t = f32_array_create(latents.length); - for (let i: i32 = 0; i < noise.length; ++i) { - noise[i] = math_cos(2.0 * 3.14 * random_node_get_float()) * math_sqrt(-2.0 * math_log(random_node_get_float())); - } - let sqrt_alpha_prod: f32 = math_pow(text_to_photo_node_alphas_cumprod[timestep], 0.5); - let sqrt_one_minus_alpha_prod: f32 = math_pow(1.0 - text_to_photo_node_alphas_cumprod[timestep], 0.5); - - let init_latents_proper: f32_array_t = f32_array_create(latents.length); - for (let i: i32 = 0; i < init_latents_proper.length; ++i) { - init_latents_proper[i] = sqrt_alpha_prod * latents_orig[i] + sqrt_one_minus_alpha_prod * noise[i]; - } - - for (let i: i32 = 0; i < latents.length; ++i) { - latents[i] = (init_latents_proper[i] * mask[i]) + (latents[i] * (1.0 - mask[i])); - } - } - - if (counter == (51 - offset)) { - break; - } - } - - return latents; -} - -function text_to_photo_node_vae_decoder(latents: f32_array_t, upscale: bool): gpu_texture_t { - console_progress(tr("Processing") + " - " + tr("Text to Photo")); - - for (let i: i32 = 0; i < latents.length; ++i) { - latents[i] = 1.0 / 0.18215 * latents[i]; - } - - let tensors: buffer_t[] = [buffer_create_from_raw(latents.buffer, latents.length * 4)]; - let input_shape: i32_array_t[] = []; - let input_shape0: i32[] = [1, 4, 64, 64]; - array_push(input_shape, input_shape0); - let output_shape: i32[] = [1, 3, 512, 512]; - let pyimage_buf: buffer_t = iron_ml_inference(text_to_photo_node_vae_decoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference); - let pyimage: f32_array_t = f32_array_create_from_buffer(pyimage_buf); - - for (let i: i32 = 0; i < pyimage.length; ++i) { - pyimage[i] = pyimage[i] / 2.0 + 0.5; - if (pyimage[i] < 0) pyimage[i] = 0; - else if (pyimage[i] > 1) pyimage[i] = 1; - } - - let u8a: u8_array_t = u8_array_create(4 * 512 * 512); - for (let i: i32 = 0; i < (512 * 512); ++i) { - u8a[i * 4 ] = math_floor(pyimage[i ] * 255); - u8a[i * 4 + 1] = math_floor(pyimage[i + 512 * 512 ] * 255); - u8a[i * 4 + 2] = math_floor(pyimage[i + 512 * 512 * 2] * 255); - u8a[i * 4 + 3] = 255; - } - let image: gpu_texture_t = gpu_create_texture_from_bytes(u8a, 512, 512); - - if (text_to_photo_node_tiling) { - tiling_node_prompt = text_to_photo_node_prompt; - let seed: i32 = random_node_get_seed(); - return tiling_node_sd_tiling(image, seed); - } - else { - if (upscale) { - upscale_node_load_blob(); - while (image.width < config_get_texture_res_x()) { - let last_image: gpu_texture_t = image; - image = upscale_node_esrgan(image); - iron_delete_texture(last_image); - } - return image; - } - else { - return image; - } - } -} - -let text_to_photo_node_def: ui_node_t = { - id: 0, - name: _tr("Text to Photo"), - type: "text_to_photo_node", - x: 0, - y: 0, - color: 0xff4982a0, - inputs: [], - outputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - buttons: [ - { - name: _tr("tiling"), - type: "BOOL", - output: 0, - default_value: f32_array_create_x(0), - data: null, - min: 0.0, - max: 1.0, - precision: 100, - height: 0 - }, - { - name: "text_to_photo_node_button", - type: "CUSTOM", - output: -1, - default_value: f32_array_create_x(0), - data: null, - min: 0.0, - max: 1.0, - precision: 100, - height: 1 - } - ], - width: 0 -}; - -let text_to_photo_node_text_input_ids: i32[] = [49406, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407]; - -let text_to_photo_node_uncond_input_ids: i32[] = [49406, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, 49407, - 49407, 49407, 49407, 49407, 49407]; - -let text_to_photo_node_alphas_cumprod: f32[] = [0.99915, 0.998296, 0.9974381, 0.99657613, 0.99571025, 0.9948404, - 0.9939665, 0.99308866, 0.9922069, 0.9913211, 0.9904313, 0.98953754, - 0.9886398, 0.9877381, 0.9868324, 0.9859227, 0.985009, 0.98409134, - 0.9831697, 0.982244, 0.98131436, 0.9803807, 0.97944313, 0.97850156, - 0.977556, 0.9766064, 0.9756529, 0.9746954, 0.9737339, 0.9727684, - 0.97179896, 0.97082555, 0.96984816, 0.96886677, 0.9678814, 0.96689206, - 0.9658988, 0.96490157, 0.9639003, 0.96289515, 0.961886, 0.9608729, - 0.9598558, 0.9588347, 0.9578097, 0.95678073, 0.95574784, 0.95471096, - 0.95367014, 0.9526254, 0.95157677, 0.9505242, 0.9494677, 0.9484073, - 0.94734293, 0.94627464, 0.9452024, 0.9441263, 0.9430463, 0.94196236, - 0.9408745, 0.9397828, 0.9386872, 0.93758774, 0.93648434, 0.93537706, - 0.9342659, 0.9331509, 0.93203205, 0.93090934, 0.9297828, 0.92865235, - 0.92751807, 0.92638, 0.9252381, 0.9240923, 0.9229427, 0.92178935, - 0.9206321, 0.9194711, 0.9183063, 0.9171377, 0.9159653, 0.91478914, - 0.9136092, 0.9124255, 0.9112381, 0.9100469, 0.908852, 0.90765333, - 0.90645087, 0.9052447, 0.90403485, 0.9028213, 0.90160406, 0.9003831, - 0.8991585, 0.89793015, 0.8966982, 0.8954625, 0.8942232, 0.8929803, - 0.8917337, 0.8904835, 0.88922966, 0.88797224, 0.8867112, 0.88544655, - 0.88417834, 0.88290656, 0.8816312, 0.8803523, 0.87906986, 0.8777839, - 0.87649435, 0.87520134, 0.8739048, 0.8726048, 0.8713013, 0.8699943, - 0.8686838, 0.86736983, 0.86605245, 0.8647316, 0.8634073, 0.8620797, - 0.86074865, 0.85941416, 0.85807633, 0.8567351, 0.85539055, 0.8540426, - 0.8526913, 0.8513367, 0.8499788, 0.8486176, 0.84725314, 0.84588534, - 0.8445143, 0.84314, 0.8417625, 0.84038174, 0.8389977, 0.83761054, - 0.83622015, 0.8348266, 0.8334298, 0.83202994, 0.8306269, 0.8292208, - 0.8278115, 0.8263991, 0.82498366, 0.8235651, 0.82214355, 0.8207189, - 0.8192912, 0.8178604, 0.8164267, 0.81499, 0.8135503, 0.8121076, - 0.810662, 0.8092134, 0.8077619, 0.80630755, 0.8048503, 0.80339015, - 0.80192715, 0.8004613, 0.7989926, 0.79752105, 0.79604673, 0.7945696, - 0.79308975, 0.79160714, 0.79012173, 0.78863364, 0.7871428, 0.7856493, - 0.78415316, 0.78265435, 0.78115284, 0.7796487, 0.778142, 0.77663267, - 0.77512074, 0.77360624, 0.7720892, 0.7705696, 0.7690475, 0.7675229, - 0.7659958, 0.7644662, 0.76293427, 0.76139987, 0.759863, 0.7583238, - 0.7567822, 0.7552382, 0.75369185, 0.7521432, 0.7505923, 0.74903905, - 0.74748355, 0.7459258, 0.74436575, 0.7428035, 0.7412391, 0.7396724, - 0.7381036, 0.7365327, 0.73495966, 0.7333845, 0.73180723, 0.7302279, - 0.7286465, 0.72706306, 0.7254776, 0.7238901, 0.72230065, 0.72070926, - 0.7191159, 0.71752065, 0.7159235, 0.7143244, 0.7127235, 0.7111207, - 0.7095161, 0.7079097, 0.7063015, 0.7046916, 0.7030799, 0.70146644, - 0.6998513, 0.69823444, 0.69661593, 0.69499576, 0.693374, 0.6917506, - 0.6901256, 0.68849903, 0.6868709, 0.6852412, 0.6836101, 0.6819774, - 0.6803433, 0.6787077, 0.67707074, 0.6754323, 0.67379254, 0.6721514, - 0.67050886, 0.668865, 0.6672199, 0.6655735, 0.6639258, 0.6622769, - 0.6606268, 0.6589755, 0.657323, 0.65566933, 0.6540145, 0.6523586, - 0.6507016, 0.6490435, 0.64738435, 0.6457242, 0.644063, 0.6424008, - 0.64073765, 0.63907355, 0.6374085, 0.63574255, 0.63407576, 0.6324081, - 0.63073957, 0.6290703, 0.6274002, 0.6257293, 0.6240577, 0.6223853, - 0.6207122, 0.61903846, 0.61736405, 0.615689, 0.6140133, 0.61233705, - 0.6106602, 0.6089828, 0.6073049, 0.6056264, 0.60394746, 0.60226804, - 0.6005882, 0.59890795, 0.5972273, 0.59554625, 0.59386486, 0.5921831, - 0.59050107, 0.5888187, 0.5871361, 0.5854532, 0.5837701, 0.5820868, - 0.5804033, 0.57871974, 0.57703596, 0.5753521, 0.57366806, 0.571984, - 0.5702999, 0.5686158, 0.56693166, 0.56524754, 0.56356347, 0.56187946, - 0.56019557, 0.55851173, 0.5568281, 0.55514455, 0.5534612, 0.551778, - 0.5500951, 0.5484124, 0.5467299, 0.54504776, 0.5433659, 0.5416844, - 0.5400032, 0.5383224, 0.536642, 0.534962, 0.53328246, 0.53160334, - 0.52992475, 0.52824664, 0.52656907, 0.52489203, 0.5232156, 0.5215397, - 0.51986444, 0.5181898, 0.51651585, 0.51484257, 0.51317, 0.51149815, - 0.509827, 0.50815666, 0.5064871, 0.5048183, 0.5031504, 0.5014833, - 0.49981716, 0.49815187, 0.4964875, 0.49482408, 0.49316162, 0.49150014, - 0.48983967, 0.48818022, 0.48652178, 0.48486444, 0.48320818, 0.48155302, - 0.479899, 0.47824612, 0.47659442, 0.4749439, 0.47329462, 0.47164655, - 0.46999976, 0.46835423, 0.46671, 0.4650671, 0.46342552, 0.46178532, - 0.46014652, 0.45850912, 0.45687312, 0.45523855, 0.45360544, 0.45197386, - 0.45034376, 0.44871515, 0.44708812, 0.44546264, 0.44383875, 0.44221646, - 0.4405958, 0.4389768, 0.43735942, 0.43574375, 0.43412977, 0.43251753, - 0.430907, 0.42929825, 0.42769128, 0.42608613, 0.4244828, 0.4228813, - 0.42128167, 0.4196839, 0.41808805, 0.4164941, 0.4149021, 0.41331202, - 0.41172394, 0.41013786, 0.40855378, 0.40697172, 0.40539172, 0.40381378, - 0.40223792, 0.40066415, 0.39909253, 0.39752305, 0.3959557, 0.39439055, - 0.3928276, 0.39126685, 0.38970834, 0.38815206, 0.38659805, 0.38504633, - 0.3834969, 0.3819498, 0.38040504, 0.37886262, 0.37732255, 0.37578487, - 0.3742496, 0.37271675, 0.37118635, 0.36965838, 0.3681329, 0.3666099, - 0.3650894, 0.3635714, 0.36205596, 0.36054307, 0.35903275, 0.35752502, - 0.35601988, 0.35451737, 0.35301748, 0.35152024, 0.35002568, 0.34853378, - 0.3470446, 0.34555808, 0.3440743, 0.34259328, 0.341115, 0.3396395, - 0.3381668, 0.3366969, 0.33522978, 0.3337655, 0.3323041, 0.3308455, - 0.3293898, 0.327937, 0.3264871, 0.3250401, 0.32359603, 0.3221549, - 0.32071674, 0.31928152, 0.3178493, 0.3164201, 0.3149939, 0.3135707, - 0.31215054, 0.31073344, 0.3093194, 0.30790845, 0.30650055, 0.30509576, - 0.3036941, 0.30229557, 0.30090016, 0.2995079, 0.29811877, 0.29673284, - 0.2953501, 0.29397056, 0.29259422, 0.2912211, 0.28985122, 0.28848457, - 0.28712118, 0.28576106, 0.28440422, 0.28305066, 0.2817004, 0.28035346, - 0.27900982, 0.27766952, 0.27633256, 0.27499893, 0.27366868, 0.2723418, - 0.27101827, 0.26969814, 0.26838142, 0.26706812, 0.26575825, 0.26445177, - 0.26314875, 0.26184916, 0.26055303, 0.25926036, 0.25797117, 0.25668547, - 0.25540325, 0.25412452, 0.2528493, 0.25157762, 0.25030944, 0.24904479, - 0.24778369, 0.24652614, 0.24527213, 0.2440217, 0.24277483, 0.24153154, - 0.24029182, 0.2390557, 0.23782317, 0.23659426, 0.23536895, 0.23414725, - 0.23292919, 0.23171476, 0.23050396, 0.2292968, 0.2280933, 0.22689344, - 0.22569725, 0.22450472, 0.22331588, 0.22213072, 0.22094923, 0.21977143, - 0.21859734, 0.21742693, 0.21626024, 0.21509725, 0.21393798, 0.21278243, - 0.2116306, 0.2104825, 0.20933813, 0.20819749, 0.2070606, 0.20592746, - 0.20479806, 0.20367241, 0.20255052, 0.20143238, 0.200318, 0.19920738, - 0.19810054, 0.19699748, 0.19589819, 0.19480269, 0.19371095, 0.192623, - 0.19153884, 0.19045846, 0.18938187, 0.18830907, 0.18724008, 0.18617487, - 0.18511346, 0.18405585, 0.18300205, 0.18195206, 0.18090586, 0.17986348, - 0.1788249, 0.17779014, 0.17675918, 0.17573205, 0.17470871, 0.17368919, - 0.17267348, 0.17166159, 0.1706535, 0.16964924, 0.1686488, 0.16765216, - 0.16665934, 0.16567034, 0.16468513, 0.16370374, 0.16272618, 0.16175242, - 0.16078247, 0.15981634, 0.15885401, 0.1578955, 0.1569408, 0.15598992, - 0.15504283, 0.15409954, 0.15316005, 0.15222436, 0.15129249, 0.15036441, - 0.14944012, 0.14851964, 0.14760293, 0.14669003, 0.1457809, 0.14487557, - 0.14397402, 0.14307626, 0.14218228, 0.14129207, 0.14040563, 0.13952295, - 0.13864405, 0.13776892, 0.13689755, 0.13602993, 0.13516606, 0.13430595, - 0.13344958, 0.13259697, 0.1317481, 0.13090296, 0.13006155, 0.12922388, - 0.12838994, 0.1275597, 0.1267332, 0.1259104, 0.12509131, 0.12427593, - 0.12346424, 0.12265625, 0.12185195, 0.12105133, 0.1202544, 0.11946114, - 0.11867155, 0.11788563, 0.11710336, 0.11632475, 0.11554979, 0.11477847, - 0.1140108, 0.11324675, 0.11248633, 0.11172953, 0.11097635, 0.11022678, - 0.10948081, 0.10873844, 0.10799967, 0.10726449, 0.10653288, 0.10580485, - 0.10508038, 0.10435947, 0.10364211, 0.1029283, 0.10221803, 0.1015113, - 0.10080809, 0.10010841, 0.09941223, 0.09871957, 0.0980304, 0.09734473, - 0.09666254, 0.09598383, 0.09530859, 0.09463682, 0.0939685, 0.09330362, - 0.09264219, 0.09198419, 0.09132962, 0.09067846, 0.09003071, 0.08938637, - 0.08874542, 0.08810785, 0.08747366, 0.08684284, 0.08621538, 0.08559129, - 0.08497053, 0.0843531, 0.08373901, 0.08312824, 0.08252078, 0.08191663, - 0.08131576, 0.08071819, 0.08012389, 0.07953286, 0.07894509, 0.07836057, - 0.07777929, 0.07720125, 0.07662643, 0.07605482, 0.07548642, 0.07492122, - 0.07435921, 0.07380038, 0.07324471, 0.07269221, 0.07214285, 0.07159664, - 0.07105356, 0.07051361, 0.06997676, 0.06944302, 0.06891238, 0.06838482, - 0.06786034, 0.06733891, 0.06682055, 0.06630524, 0.06579296, 0.06528371, - 0.06477747, 0.06427424, 0.06377401, 0.06327677, 0.0627825, 0.06229121, - 0.06180287, 0.06131747, 0.06083502, 0.06035549, 0.05987888, 0.05940517, - 0.05893436, 0.05846644, 0.05800139, 0.05753921, 0.05707989, 0.05662341, - 0.05616977, 0.05571895, 0.05527094, 0.05482575, 0.05438334, 0.05394372, - 0.05350687, 0.05307278, 0.05264145, 0.05221286, 0.05178699, 0.05136385, - 0.05094342, 0.05052568, 0.05011064, 0.04969827, 0.04928857, 0.04888153, - 0.04847714, 0.04807537, 0.04767624, 0.04727972, 0.0468858, 0.04649448, - 0.04610574, 0.04571956, 0.04533596, 0.0449549, 0.04457638, 0.04420039, - 0.04382691, 0.04345594, 0.04308747, 0.04272148, 0.04235797, 0.04199693, - 0.04163833, 0.04128218, 0.04092846, 0.04057716, 0.04022827, 0.03988178, - 0.03953768, 0.03919596, 0.0388566, 0.0385196, 0.03818495, 0.03785263, - 0.03752263, 0.03719494, 0.03686956, 0.03654647, 0.03622566, 0.03590712, - 0.03559083, 0.0352768, 0.034965, 0.03465543, 0.03434808, 0.03404293, - 0.03373997, 0.0334392, 0.0331406, 0.03284416, 0.03254988, 0.03225773, - 0.03196772, 0.03167982, 0.03139404, 0.03111035, 0.03082875, 0.03054923, - 0.03027177, 0.02999637, 0.02972301, 0.02945168, 0.02918238, 0.0289151, - 0.02864981, 0.02838652, 0.02812521, 0.02786587, 0.02760849, 0.02735306, - 0.02709957, 0.02684801, 0.02659837, 0.02635064, 0.0261048, 0.02586086, - 0.02561878, 0.02537858, 0.02514023, 0.02490373, 0.02466906, 0.02443622, - 0.0242052, 0.02397598, 0.02374856, 0.02352292, 0.02329905, 0.02307695, - 0.02285661, 0.02263801, 0.02242114, 0.022206, 0.02199257, 0.02178084, - 0.02157081, 0.02136246, 0.02115579, 0.02095079, 0.02074743, 0.02054573, - 0.02034565, 0.0201472, 0.01995037, 0.01975514, 0.01956151, 0.01936947, - 0.019179, 0.0189901, 0.01880275, 0.01861695, 0.01843269, 0.01824996, - 0.01806875, 0.01788905, 0.01771084, 0.01753413, 0.0173589, 0.01718514, - 0.01701284, 0.016842, 0.0166726, 0.01650463, 0.0163381, 0.01617297, - 0.01600925, 0.01584694, 0.01568601, 0.01552646, 0.01536828, 0.01521146, - 0.015056, 0.01490187, 0.01474909, 0.01459763, 0.01444749, 0.01429865, - 0.01415112, 0.01400487, 0.01385991, 0.01371622, 0.0135738, 0.01343263, - 0.01329271, 0.01315403, 0.01301658, 0.01288035, 0.01274534, 0.01261153, - 0.01247892, 0.01234749, 0.01221725, 0.01208818, 0.01196027, 0.01183351, - 0.01170791, 0.01158344, 0.0114601, 0.01133789, 0.01121679, 0.0110968, - 0.01097791, 0.01086011, 0.01074339, 0.01062774, 0.01051317, 0.01039965, - 0.01028718, 0.01017576, 0.01006538, 0.00995602, 0.00984768, 0.00974036, - 0.00963405, 0.00952873, 0.0094244, 0.00932106, 0.00921869, 0.00911729, - 0.00901685, 0.00891737, 0.00881884, 0.00872124, 0.00862457, 0.00852883, - 0.00843401, 0.0083401, 0.0082471, 0.00815499, 0.00806377, 0.00797343, - 0.00788397, 0.00779538, 0.00770765, 0.00762078, 0.00753476, 0.00744958, - 0.00736523, 0.00728171, 0.00719902, 0.00711714, 0.00703607, 0.0069558, - 0.00687633, 0.00679765, 0.00671975, 0.00664263, 0.00656627, 0.00649069, - 0.00641586, 0.00634178, 0.00626845, 0.00619586, 0.006124, 0.00605286, - 0.00598245, 0.00591276, 0.00584377, 0.00577549, 0.0057079, 0.00564101, - 0.0055748, 0.00550927, 0.00544442, 0.00538023, 0.00531671, 0.00525384, - 0.00519163, 0.00513006, 0.00506913, 0.00500883, 0.00494917, 0.00489013, - 0.0048317, 0.00477389, 0.00471669, 0.00466009]; - -let text_to_photo_node_timesteps: i32[] = [981, 961, 961, 941, 921, 901, 881, 861, 841, 821, 801, 781, 761, 741, 721, 701, 681, 661, - 641, 621, 601, 581, 561, 541, 521, 501, 481, 461, 441, 421, 401, 381, 361, 341, 321, 301, - 281, 261, 241, 221, 201, 181, 161, 141, 121, 101, 81, 61, 41, 21, 1]; - -let text_to_photo_node_vocab: map_t = null; diff --git a/lab/sources/nodes/tiling_node.ts b/lab/sources/nodes/tiling_node.ts deleted file mode 100644 index 9f0f0606..00000000 --- a/lab/sources/nodes/tiling_node.ts +++ /dev/null @@ -1,165 +0,0 @@ - -type tiling_node_t = { - base?: logic_node_t; - result?: gpu_texture_t; -}; - -let tiling_node_image: gpu_texture_t = null; -let tiling_node_prompt: string = ""; -let tiling_node_strength: f32 = 0.5; -let tiling_node_auto: bool = true; - -function tiling_node_create(raw: ui_node_t, args: f32_array_t): tiling_node_t { - let n: float_node_t = {}; - n.base = logic_node_create(n); - n.base.get_as_image = tiling_node_get_as_image; - n.base.get_cached_image = tiling_node_get_cached_image; - tiling_node_init(); - return n; -} - -function tiling_node_init() { - if (tiling_node_image == null) { - tiling_node_image = gpu_create_render_target(config_get_texture_res_x(), config_get_texture_res_y()); - } -} - -function tiling_node_button(node_id: i32) { - let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); - - tiling_node_auto = node.buttons[0].default_value[0] == 0 ? false : true; - if (!tiling_node_auto) { - let tiling_node_strength_handle: ui_handle_t = ui_handle(__ID__); - if (tiling_node_strength_handle.init) { - tiling_node_strength_handle.value = tiling_node_strength; - } - - tiling_node_strength = ui_slider(tiling_node_strength_handle, tr("strength"), 0, 1, true); - tiling_node_prompt = ui_text_area(ui_handle(__ID__), ui_align_t.LEFT, true, tr("prompt"), true); - node.buttons[1].height = 1 + string_split(tiling_node_prompt, "\n").length; - } - else { - node.buttons[1].height = 0; - } -} - -function tiling_node_get_as_image(self: tiling_node_t, from: i32): gpu_texture_t { - let source: gpu_texture_t = logic_node_input_get_as_image(self.base.inputs[0]); - draw_begin(tiling_node_image); - draw_scaled_image(source, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - draw_end(); - - console_progress(tr("Processing") + " - " + tr("Tiling")); - - if (tiling_node_auto){ - self.result = inpaint_node_texsynth_inpaint(tiling_node_image, true, null); - } - else { - self.result = tiling_node_sd_tiling(tiling_node_image, -1); - } - return self.result; -} - -function tiling_node_get_cached_image(self: tiling_node_t): gpu_texture_t { - return self.result; -} - -function tiling_node_sd_tiling(image: gpu_texture_t, seed: i32): gpu_texture_t { - text_to_photo_node_tiling = false; - let tile: gpu_texture_t = gpu_create_render_target(512, 512); - draw_begin(tile); - draw_scaled_image(image, -256, -256, 512, 512); - draw_scaled_image(image, 256, -256, 512, 512); - draw_scaled_image(image, -256, 256, 512, 512); - draw_scaled_image(image, 256, 256, 512, 512); - draw_end(); - - let u8a: u8_array_t = u8_array_create(512 * 512); - for (let i: i32 = 0; i < 512 * 512; ++i) { - let x: i32 = i % 512; - let y: i32 = math_floor(i / 512); - let l: i32 = y < 256 ? y : (511 - y); - u8a[i] = (x > 256 - l && x < 256 + l) ? 0 : 255; - } - // for (let i: i32 = 0; i < 512 * 512; ++i) u8a[i] = 255; - // for (let x: i32 = (256 - 32); x < (256 + 32); ++x) { - // for (let y: i32 = 0; y < 512; ++y) { - // u8a[y * 512 + x] = 0; - // } - // } - // for (let x: i32 = 0; x < 512; ++x) { - // for (let y: i32 = (256 - 32); y < 256 + 32); ++y) { - // u8a[y * 512 + x] = 0; - // } - // } - let mask: gpu_texture_t = gpu_create_texture_from_bytes(u8a, 512, 512, tex_format_t.R8); - - inpaint_node_prompt = tiling_node_prompt; - inpaint_node_strength = tiling_node_strength; - if (seed >= 0) { - random_node_set_seed(seed); - } - return inpaint_node_sd_inpaint(tile, mask); -} - -let tiling_node_def: ui_node_t = { - id: 0, - name: _tr("Tiling"), - type: "tiling_node", - x: 0, - y: 0, - color: 0xff4982a0, - inputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - outputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - buttons: [ - { - name: _tr("auto"), - type: "BOOL", - output: 0, - default_value: f32_array_create_x(1), - data: null, - min: 0.0, - max: 1.0, - precision: 100, - height: 0 - }, - { - name: "tiling_node_button", - type: "CUSTOM", - output: -1, - default_value: f32_array_create_x(0), - data: null, - min: 0.0, - max: 1.0, - precision: 100, - height: 0 - } - ], - width: 0 -}; diff --git a/lab/sources/nodes/upscale_node.ts b/lab/sources/nodes/upscale_node.ts deleted file mode 100644 index a0ac196d..00000000 --- a/lab/sources/nodes/upscale_node.ts +++ /dev/null @@ -1,169 +0,0 @@ - -type upscale_node_t = { - base?: logic_node_t; -}; - -let upscale_node_temp: gpu_texture_t = null; -let upscale_node_image: gpu_texture_t = null; -let upscale_node_esrgan_blob: buffer_t; - -function upscale_node_create(raw: ui_node_t, args: f32_array_t): upscale_node_t { - let n: float_node_t = {}; - n.base = logic_node_create(n); - n.base.get_as_image = upscale_node_get_as_image; - n.base.get_cached_image = upscale_node_get_cached_image; - return n; -} - -function upscale_node_get_as_image(self: upscale_node_t, from: i32): gpu_texture_t { - upscale_node_image = logic_node_input_get_as_image(self.base.inputs[0]); - - console_progress(tr("Processing") + " - " + tr("Upscale")); - - upscale_node_load_blob(); - if (upscale_node_image.width < config_get_texture_res_x()) { - upscale_node_image = upscale_node_esrgan(upscale_node_image); - while (upscale_node_image.width < config_get_texture_res_x()) { - let last_image: gpu_texture_t = upscale_node_image; - upscale_node_image = upscale_node_esrgan(upscale_node_image); - iron_delete_texture(last_image); - } - } - return upscale_node_image; -} - -function upscale_node_load_blob() { - upscale_node_esrgan_blob = data_get_blob("models/esrgan.quant.onnx"); -} - -function upscale_node_get_cached_image(self: upscale_node_t): gpu_texture_t { - return upscale_node_image; -} - -function upscale_node_do_tile(source: gpu_texture_t): gpu_texture_t { - let result: gpu_texture_t = null; - let size1w: i32 = source.width; - let size1h: i32 = source.height; - let size2w: i32 = math_floor(size1w * 2); - let size2h: i32 = math_floor(size1h * 2); - if (upscale_node_temp != null) { - iron_delete_texture(upscale_node_temp); - } - upscale_node_temp = gpu_create_render_target(size1w, size1h); - draw_begin(upscale_node_temp); - draw_scaled_image(source, 0, 0, size1w, size1h); - draw_end(); - - let bytes_img: buffer_t = gpu_get_texture_pixels(upscale_node_temp); - let u8a: u8_array_t = bytes_img; - let f32a: f32_array_t = f32_array_create(3 * size1w * size1h); - for (let i: i32 = 0; i < (size1w * size1h); ++i) { - f32a[i ] = (u8a[i * 4 ] / 255); - f32a[i + size1w * size1w ] = (u8a[i * 4 + 1] / 255); - f32a[i + size1w * size1w * 2] = (u8a[i * 4 + 2] / 255); - } - - let tensors: buffer_t[] = [buffer_create_from_raw(f32a.buffer, f32a.length * 4)]; - let input_shape: i32_array_t[] = []; - let input_shape0: i32[] = [1, 3, size1w, size1h]; - array_push(input_shape, input_shape0); - let output_shape: i32[] = [1, 3, size2w, size2h]; - let esrgan2x_buf: buffer_t = iron_ml_inference(upscale_node_esrgan_blob, tensors, input_shape, output_shape, config_raw.gpu_inference); - let esrgan2x: f32_array_t = f32_array_create_from_buffer(esrgan2x_buf); - for (let i: i32 = 0; i < esrgan2x.length; ++i) { - if (esrgan2x[i] < 0) { - esrgan2x[i] = 0; - } - else if (esrgan2x[i] > 1) { - esrgan2x[i] = 1; - } - } - - u8a = u8_array_create(4 * size2w * size2h); - for (let i: i32 = 0; i < (size2w * size2h); ++i) { - u8a[i * 4 ] = math_floor(esrgan2x[i ] * 255); - u8a[i * 4 + 1] = math_floor(esrgan2x[i + size2w * size2w ] * 255); - u8a[i * 4 + 2] = math_floor(esrgan2x[i + size2w * size2w * 2] * 255); - u8a[i * 4 + 3] = 255; - } - - result = gpu_create_texture_from_bytes(u8a, size2w, size2h); - return result; -} - -function upscale_node_esrgan(source: gpu_texture_t): gpu_texture_t { - let result: gpu_texture_t = null; - let size1w: i32 = source.width; - let size1h: i32 = source.height; - let tile_size: i32 = 512; - let tile_size2x: i32 = math_floor(tile_size * 2); - - if (size1w >= tile_size2x || size1h >= tile_size2x) { // Split into tiles - let size2w: i32 = math_floor(size1w * 2); - let size2h: i32 = math_floor(size1h * 2); - result = gpu_create_render_target(size2w, size2h); - let tile_source: gpu_texture_t = gpu_create_render_target(tile_size + 32 * 2, tile_size + 32 * 2); - for (let x: i32 = 0; x < math_floor(size1w / tile_size); ++x) { - for (let y: i32 = 0; y < math_floor(size1h / tile_size); ++y) { - draw_begin(tile_source); - draw_scaled_image(source, 32 - x * tile_size, 32 - y * tile_size, -source.width, source.height); - draw_scaled_image(source, 32 - x * tile_size, 32 - y * tile_size, source.width, -source.height); - draw_scaled_image(source, 32 - x * tile_size, 32 - y * tile_size, -source.width, -source.height); - draw_scaled_image(source, 32 - x * tile_size + tile_size, 32 - y * tile_size + tile_size, source.width, source.height); - draw_scaled_image(source, 32 - x * tile_size + tile_size, 32 - y * tile_size + tile_size, -source.width, source.height); - draw_scaled_image(source, 32 - x * tile_size + tile_size, 32 - y * tile_size + tile_size, source.width, -source.height); - draw_scaled_image(source, 32 - x * tile_size, 32 - y * tile_size, source.width, source.height); - draw_end(); - let tile_result: gpu_texture_t = upscale_node_do_tile(tile_source); - draw_begin(result); - draw_sub_image(tile_result, x * tile_size2x, y * tile_size2x, 64, 64, tile_size2x, tile_size2x); - draw_end(); - iron_delete_texture(tile_result); - } - } - iron_delete_texture(tile_source); - } - else { - result = upscale_node_do_tile(source); // Single tile - } - return result; -} - -let upscale_node_def: ui_node_t = { - id: 0, - name: _tr("Upscale"), - type: "upscale_node", - x: 0, - y: 0, - color: 0xff4982a0, - inputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - outputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - buttons: [], - width: 0 -}; diff --git a/lab/sources/nodes/variance_node.ts b/lab/sources/nodes/variance_node.ts deleted file mode 100644 index 3dc9ccca..00000000 --- a/lab/sources/nodes/variance_node.ts +++ /dev/null @@ -1,151 +0,0 @@ - -type variance_node_t = { - base?: logic_node_t; -}; - -let variance_node_temp: gpu_texture_t = null; -let variance_node_image: gpu_texture_t = null; -let variance_node_inst: variance_node_t = null; -let variance_node_prompt: string = ""; - -function variance_node_create(raw: ui_node_t, args: f32_array_t): variance_node_t { - let n: variance_node_t = {}; - n.base = logic_node_create(n); - n.base.get_as_image = variance_node_get_as_image; - n.base.get_cached_image = variance_node_get_cached_image; - - variance_node_inst = n; - variance_node_init(); - - return n; -} - -function variance_node_init() { - if (variance_node_temp == null) { - variance_node_temp = gpu_create_render_target(512, 512); - } -} - -function variance_node_button(node_id: i32) { - let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); - - variance_node_prompt = ui_text_area(ui_handle(__ID__), ui_align_t.LEFT, true, tr("prompt"), true); - node.buttons[0].height = string_split(variance_node_prompt, "\n").length; -} - -function variance_node_get_as_image(self: variance_node_t, from: i32): gpu_texture_t { - let node: float_node_t = variance_node_inst.base.inputs[1].node; - let strength: f32 = node.value; - - let source: gpu_texture_t = logic_node_input_get_as_image(variance_node_inst.base.inputs[0]); - draw_begin(variance_node_temp); - draw_scaled_image(source, 0, 0, 512, 512); - draw_end(); - - let bytes_img: buffer_t = gpu_get_texture_pixels(variance_node_temp); - let u8a: u8_array_t = bytes_img; - let f32a: f32_array_t = f32_array_create(3 * 512 * 512); - for (let i: i32 = 0; i < (512 * 512); ++i) { - f32a[i ] = (u8a[i * 4 ] / 255) * 2.0 - 1.0; - f32a[i + 512 * 512 ] = (u8a[i * 4 + 1] / 255) * 2.0 - 1.0; - f32a[i + 512 * 512 * 2] = (u8a[i * 4 + 2] / 255) * 2.0 - 1.0; - } - - console_progress(tr("Processing") + " - " + tr("Variance")); - - let vae_encoder_blob: buffer_t = data_get_blob("models/sd_vae_encoder.quant.onnx"); - let tensors: buffer_t[] = [buffer_create_from_raw(f32a.buffer, f32a.length * 4)]; - let input_shape: i32_array_t[] = []; - let input_shape0: i32[] = [1, 3, 512, 512]; - array_push(input_shape, input_shape0); - let output_shape: i32[] = [1, 4, 64, 64]; - let latents_buf: buffer_t = iron_ml_inference(vae_encoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference); - let latents: f32_array_t = f32_array_create_from_buffer(latents_buf); - for (let i: i32 = 0; i < latents.length; ++i) { - latents[i] = 0.18215 * latents[i]; - } - - let noise: f32_array_t = f32_array_create(latents.length); - for (let i: i32 = 0; i < noise.length; ++i) { - noise[i] = math_cos(2.0 * 3.14 * random_node_get_float()) * math_sqrt(-2.0 * math_log(random_node_get_float())); - } - let num_inference_steps: i32 = 50; - let init_timestep: i32 = math_floor(num_inference_steps * strength); - let timesteps: i32 = text_to_photo_node_timesteps[num_inference_steps - init_timestep]; - let alphas_cumprod: f32[] = text_to_photo_node_alphas_cumprod; - let sqrt_alpha_prod: f32 = math_pow(alphas_cumprod[timesteps], 0.5); - let sqrt_one_minus_alpha_prod: f32 = math_pow(1.0 - alphas_cumprod[timesteps], 0.5); - for (let i: i32 = 0; i < latents.length; ++i) { - latents[i] = sqrt_alpha_prod * latents[i] + sqrt_one_minus_alpha_prod * noise[i]; - } - let t_start: f32 = num_inference_steps - init_timestep; - variance_node_image = text_to_photo_node_stable_diffusion(variance_node_prompt, latents, t_start); - return variance_node_image; -} - -function variance_node_get_cached_image(self: variance_node_t): gpu_texture_t { - return variance_node_image; -} - -let variance_node_def: ui_node_t = { - id: 0, - name: _tr("Variance"), - type: "variance_node", - x: 0, - y: 0, - color: 0xff4982a0, - inputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - }, - { - id: 0, - node_id: 0, - name: _tr("Strength"), - type: "VALUE", - color: 0xffa1a1a1, - default_value: f32_array_create_x(0.5), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - outputs: [ - { - id: 0, - node_id: 0, - name: _tr("Color"), - type: "RGBA", - color: 0xffc7c729, - default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0), - min: 0.0, - max: 1.0, - precision: 100, - display: 0 - } - ], - buttons: [ - { - name: "variance_node_button", - type: "CUSTOM", - output: -1, - default_value: f32_array_create_x(0), - data: null, - min: 0.0, - max: 1.0, - precision: 100, - height: 1 - } - ], - width: 0 -}; diff --git a/lab/sources/nodes_brush.ts b/lab/sources/nodes_brush.ts deleted file mode 100644 index 4d4b2760..00000000 --- a/lab/sources/nodes_brush.ts +++ /dev/null @@ -1,77 +0,0 @@ - -let nodes_brush_categories: string[] = [ - _tr("Input"), - _tr("Model") -]; - -let nodes_brush_input: ui_node_t[]; -let nodes_brush_model: ui_node_t[]; -let nodes_brush_list: node_list_t[]; - -let nodes_brush_creates: map_tlogic_node_ext_t>; - -function nodes_brush_init() { - nodes_brush_creates = map_create(); - map_set(nodes_brush_creates, "brush_output_node", brush_output_node_create); - map_set(nodes_brush_creates, "image_texture_node", image_texture_node_create); - map_set(nodes_brush_creates, "rgb_node", rgb_node_create); - map_set(nodes_brush_creates, "inpaint_node", inpaint_node_create); - map_set(nodes_brush_creates, "photo_to_pbr_node", photo_to_pbr_node_create); - map_set(nodes_brush_creates, "text_to_photo_node", text_to_photo_node_create); - map_set(nodes_brush_creates, "tiling_node", tiling_node_create); - map_set(nodes_brush_creates, "upscale_node", upscale_node_create); - map_set(nodes_brush_creates, "variance_node", variance_node_create); - - map_set(nodes_brush_creates, "float_node", float_node_create); - map_set(nodes_brush_creates, "vector_node", vector_node_create); - map_set(nodes_brush_creates, "color_node", color_node_create); - - nodes_brush_list_init(); - - map_set(ui_nodes_custom_buttons, "inpaint_node_button", inpaint_node_button); - map_set(ui_nodes_custom_buttons, "text_to_photo_node_button", text_to_photo_node_button); - map_set(ui_nodes_custom_buttons, "tiling_node_button", tiling_node_button); - map_set(ui_nodes_custom_buttons, "variance_node_button", variance_node_button); -} - -function nodes_brush_list_init() { - if (nodes_brush_list != null) { - return; - } - - nodes_brush_input = [ - image_texture_node_def, - rgb_node_def, - ]; - - nodes_brush_model = [ - inpaint_node_def, - photo_to_pbr_node_def, - text_to_photo_node_def, - tiling_node_def, - upscale_node_def, - variance_node_def, - ]; - - nodes_brush_list = [ - nodes_brush_input, - nodes_brush_model - ]; -} - -function nodes_brush_create_node(node_type: string): ui_node_t { - for (let i: i32 = 0; i < nodes_brush_list.length; ++i) { - let c: ui_node_t[] = nodes_brush_list[i]; - for (let j: i32 = 0; j < c.length; ++j) { - let n: ui_node_t = c[j]; - if (n.type == node_type) { - let canvas: ui_node_canvas_t = project_canvas; - let nodes: ui_nodes_t = project_nodes; - let node: ui_node_t = ui_nodes_make_node(n, nodes, canvas); - array_push(canvas.nodes, node); - return node; - } - } - } - return null; -} diff --git a/lab/sources/render_path_paint.ts b/lab/sources/render_path_paint.ts deleted file mode 100644 index 41333e1b..00000000 --- a/lab/sources/render_path_paint.ts +++ /dev/null @@ -1,297 +0,0 @@ - -let render_path_paint_live_layer: slot_layer_t = null; -let render_path_paint_live_layer_locked: bool = false; -let render_path_paint_live_layer_drawn: i32 = 0; //// - -function render_path_paint_init() { - - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_blend0"; - t.width = config_get_texture_res_x(); - t.height = config_get_texture_res_y(); - t.format = "R8"; - render_path_create_render_target(t); - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_blend1"; - t.width = config_get_texture_res_x(); - t.height = config_get_texture_res_y(); - t.format = "R8"; - render_path_create_render_target(t); - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_picker"; - t.width = 1; - t.height = 1; - t.format = "RGBA32"; - render_path_create_render_target(t); - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_nor_picker"; - t.width = 1; - t.height = 1; - t.format = "RGBA32"; - render_path_create_render_target(t); - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_pack_picker"; - t.width = 1; - t.height = 1; - t.format = "RGBA32"; - render_path_create_render_target(t); - } - { - let t: render_target_t = render_target_create(); - t.name = "texpaint_uv_picker"; - t.width = 1; - t.height = 1; - t.format = "RGBA32"; - render_path_create_render_target(t); - } - - render_path_load_shader("shader_datas/copy_mrt3_pass/copy_mrt3_pass"); -} - -function render_path_paint_commands_paint(dilation: bool = true) { - let tid: string = ""; - - if (context_raw.pdirty > 0) { - - if (context_raw.tool == tool_type_t.PICKER) { - let additional: string[] = ["texpaint_nor_picker", "texpaint_pack_picker", "texpaint_uv_picker"]; - render_path_set_target("texpaint_picker", additional); - render_path_bind_target("gbuffer2", "gbuffer2"); - // tid = context_raw.layer.id; - render_path_bind_target("texpaint" + tid, "texpaint"); - render_path_bind_target("texpaint_nor" + tid, "texpaint_nor"); - render_path_bind_target("texpaint_pack" + tid, "texpaint_pack"); - render_path_draw_meshes("paint"); - ui_header_handle.redraws = 2; - - let texpaint_picker: render_target_t = map_get(render_path_render_targets, "texpaint_picker"); - let texpaint_nor_picker: render_target_t = map_get(render_path_render_targets, "texpaint_nor_picker"); - let texpaint_pack_picker: render_target_t = map_get(render_path_render_targets, "texpaint_pack_picker"); - let texpaint_uv_picker: render_target_t = map_get(render_path_render_targets, "texpaint_uv_picker"); - let a: buffer_t = gpu_get_texture_pixels(texpaint_picker._image); - let b: buffer_t = gpu_get_texture_pixels(texpaint_nor_picker._image); - let c: buffer_t = gpu_get_texture_pixels(texpaint_pack_picker._image); - let d: buffer_t = gpu_get_texture_pixels(texpaint_uv_picker._image); - - if (context_raw.color_picker_callback != null) { - context_raw.color_picker_callback(context_raw.picked_color); - } - - // Picked surface values - // ///if IRON_BGRA - // context_raw.picked_color.base.Rb = a.get(2); - // context_raw.picked_color.base.Gb = a.get(1); - // context_raw.picked_color.base.Bb = a.get(0); - // context_raw.picked_color.normal.Rb = b.get(2); - // context_raw.picked_color.normal.Gb = b.get(1); - // context_raw.picked_color.normal.Bb = b.get(0); - // context_raw.picked_color.occlusion = c.get(2) / 255; - // context_raw.picked_color.roughness = c.get(1) / 255; - // context_raw.picked_color.metallic = c.get(0) / 255; - // context_raw.picked_color.height = c.get(3) / 255; - // context_raw.picked_color.opacity = a.get(3) / 255; - // context_raw.uvx_picked = d.get(2) / 255; - // context_raw.uvy_picked = d.get(1) / 255; - // ///else - // context_raw.picked_color.base.Rb = a.get(0); - // context_raw.picked_color.base.Gb = a.get(1); - // context_raw.picked_color.base.Bb = a.get(2); - // context_raw.picked_color.normal.Rb = b.get(0); - // context_raw.picked_color.normal.Gb = b.get(1); - // context_raw.picked_color.normal.Bb = b.get(2); - // context_raw.picked_color.occlusion = c.get(0) / 255; - // context_raw.picked_color.roughness = c.get(1) / 255; - // context_raw.picked_color.metallic = c.get(2) / 255; - // context_raw.picked_color.height = c.get(3) / 255; - // context_raw.picked_color.opacity = a.get(3) / 255; - // context_raw.uvx_picked = d.get(0) / 255; - // context_raw.uvy_picked = d.get(1) / 255; - // ///end - } - else { - let texpaint: string = "texpaint_node_target"; - - render_path_set_target("texpaint_blend1"); - render_path_bind_target("texpaint_blend0", "tex"); - render_path_draw_shader("shader_datas/copy_pass/copyR8_pass"); - - let additional: string[] = ["texpaint_nor" + tid, "texpaint_pack" + tid, "texpaint_blend0"]; - render_path_set_target(texpaint, additional); - - render_path_bind_target("main", "gbufferD"); - - render_path_bind_target("texpaint_blend1", "paintmask"); - - // Read texcoords from gbuffer - let read_tc: bool = context_raw.tool == tool_type_t.CLONE || - context_raw.tool == tool_type_t.BLUR || - context_raw.tool == tool_type_t.SMUDGE; - if (read_tc) { - render_path_bind_target("gbuffer2", "gbuffer2"); - } - - render_path_draw_meshes("paint"); - } - } -} - -function render_path_paint_commands_cursor() { - let tool: tool_type_t = context_raw.tool; - if (tool != tool_type_t.ERASER && - tool != tool_type_t.CLONE && - tool != tool_type_t.BLUR && - tool != tool_type_t.SMUDGE) { - return; - } - - let nodes: ui_nodes_t = ui_nodes_get_nodes(); - let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true); - let inpaint: bool = nodes.nodes_selected_id.length > 0 && ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]).type == "inpaint_node"; - - if (!base_ui_enabled || base_is_dragging || !inpaint) { - return; - } - - let mx: f32 = context_raw.paint_vec.x; - let my: f32 = 1.0 - context_raw.paint_vec.y; - if (context_raw.brush_locked) { - mx = (context_raw.lock_started_x - sys_x()) / sys_w(); - my = 1.0 - (context_raw.lock_started_y - sys_y()) / sys_h(); - } - let radius: f32 = context_raw.brush_radius; - render_path_paint_draw_cursor(mx, my, radius / 3.4); -} - -function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f32 = 1.0, tint_g: f32 = 1.0, tint_b: f32 = 1.0) { - let plane: mesh_object_t = scene_get_child(".Plane").ext; - let geom: mesh_data_t = plane.data; - - render_path_set_target(""); - gpu_set_pipeline(pipes_cursor); - let rt: render_target_t = map_get(render_path_render_targets, "main"); - let main: gpu_texture_t = rt._image; - gpu_set_texture(pipes_cursor_gbufferd, main); - gpu_set_float2(pipes_cursor_mouse, mx, my); - gpu_set_float2(pipes_cursor_tex_step, 1 / main.width, 1 / main.height); - gpu_set_float(pipes_cursor_radius, radius); - let right: vec4_t = vec4_norm(camera_object_right_world(scene_camera)); - gpu_set_float3(pipes_cursor_camera_right, right.x, right.y, right.z); - gpu_set_float3(pipes_cursor_tint, tint_r, tint_g, tint_b); - gpu_set_matrix4(pipes_cursor_vp, scene_camera.vp); - let inv_vp: mat4_t = mat4_inv(scene_camera.vp); - gpu_set_matrix4(pipes_cursor_inv_vp, inv_vp); - gpu_set_vertex_buffer(geom._.vertex_buffer); - gpu_set_index_buffer(geom._.index_buffer); - gpu_draw(); - render_path_end(); -} - -function render_path_paint_paint_enabled(): bool { - return !context_raw.foreground_event; -} - -function render_path_paint_begin() { - if (!render_path_paint_paint_enabled()) { - return; - } -} - -function render_path_paint_end() { - context_raw.ddirty--; - context_raw.rdirty--; - - if (!render_path_paint_paint_enabled()) { - return; - } - context_raw.pdirty--; -} - -function render_path_paint_draw() { - if (!render_path_paint_paint_enabled()) { - return; - } - - render_path_paint_commands_paint(); - - if (context_raw.brush_blend_dirty) { - context_raw.brush_blend_dirty = false; - render_path_set_target("texpaint_blend0", null, null, clear_flag_t.COLOR, 0x00000000); - render_path_set_target("texpaint_blend1", null, null, clear_flag_t.COLOR, 0x00000000); - render_path_end(); - } -} - -function render_path_paint_bind_layers() { - let image: gpu_texture_t = null; - let nodes: ui_nodes_t = ui_nodes_get_nodes(); - let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true); - if (nodes.nodes_selected_id.length > 0) { - let node: ui_node_t = ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]); - let brush_node: logic_node_ext_t = parser_logic_get_logic_node(node); - if (brush_node != null) { - image = logic_node_get_cached_image(brush_node.base); - } - } - if (image != null) { - if (map_get(render_path_render_targets, "texpaint_node") == null) { - let t: render_target_t = render_target_create(); - t.name = "texpaint_node"; - t.width = config_get_texture_res_x(); - t.height = config_get_texture_res_y(); - t.format = "RGBA32"; - map_set(render_path_render_targets, t.name, t); - } - if (map_get(render_path_render_targets, "texpaint_node_target") == null) { - let t: render_target_t = render_target_create(); - t.name = "texpaint_node_target"; - t.width = config_get_texture_res_x(); - t.height = config_get_texture_res_y(); - t.format = "RGBA32"; - map_set(render_path_render_targets, t.name, t); - } - let texpaint_node_rt: render_target_t = map_get(render_path_render_targets, "texpaint_node"); - texpaint_node_rt._image = image; - render_path_bind_target("texpaint_node", "texpaint"); - render_path_bind_target("texpaint_nor_empty", "texpaint_nor"); - render_path_bind_target("texpaint_pack_empty", "texpaint_pack"); - - let nodes: ui_nodes_t = ui_nodes_get_nodes(); - let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true); - let node: ui_node_t = ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]); - let inpaint: bool = node.type == "inpaint_node"; - if (inpaint) { - let texpaint_node_target_rt: render_target_t = map_get(render_path_render_targets, "texpaint_node_target"); - texpaint_node_target_rt._image = inpaint_node_get_target(); - } - } - else { - render_path_bind_target("texpaint", "texpaint"); - render_path_bind_target("texpaint_nor", "texpaint_nor"); - render_path_bind_target("texpaint_pack", "texpaint_pack"); - } -} - -function render_path_paint_unbind_layers() { - -} - -function render_path_paint_use_live_layer(use: bool) { -} - -function render_path_paint_set_plane_mesh() { -} - -function render_path_paint_restore_plane_mesh() { -} - -function render_path_paint_dilate(base: bool, nor_pack: bool) { -} diff --git a/lab/sources/ui_base_ext.ts b/lab/sources/ui_base_ext.ts deleted file mode 100644 index d5973774..00000000 --- a/lab/sources/ui_base_ext.ts +++ /dev/null @@ -1,22 +0,0 @@ - -function ui_base_ext_init_hwnd_tabs(): tab_draw_array_t[] { - - let a0: tab_draw_array_t = []; - let a1: tab_draw_array_t = []; - let a2: tab_draw_array_t = [ - _draw_callback_create(tab_browser_draw), - _draw_callback_create(tab_meshes_draw), - _draw_callback_create(tab_textures_draw), - _draw_callback_create(tab_swatches_draw), - _draw_callback_create(tab_plugins_draw), - _draw_callback_create(tab_scripts_draw), - _draw_callback_create(tab_console_draw), - _draw_callback_create(ui_status_draw_version_tab) - ]; - - let r: tab_draw_array_t[] = []; - array_push(r, a0); - array_push(r, a1); - array_push(r, a2); - return r; -} diff --git a/lab/sources/ui_header_ext.ts b/lab/sources/ui_header_ext.ts deleted file mode 100644 index de0f064e..00000000 --- a/lab/sources/ui_header_ext.ts +++ /dev/null @@ -1,25 +0,0 @@ - -function ui_header_draw_tool_properties() { - if (context_raw.tool == tool_type_t.PICKER) { - - } - else if (context_raw.tool == tool_type_t.ERASER || - context_raw.tool == tool_type_t.CLONE || - context_raw.tool == tool_type_t.BLUR || - context_raw.tool == tool_type_t.SMUDGE) { - - let nodes: ui_nodes_t = ui_nodes_get_nodes(); - let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true); - let inpaint: bool = nodes.nodes_selected_id.length > 0 && ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]).type == "inpaint_node"; - if (inpaint) { - context_raw.brush_radius = ui_slider(context_raw.brush_radius_handle, tr("Radius"), 0.01, 2.0, true); - if (ui.is_hovered) { - let vars: map_t = map_create(); - map_set(vars, "brush_radius", map_get(config_keymap, "brush_radius")); - map_set(vars, "brush_radius_decrease", map_get(config_keymap, "brush_radius_decrease")); - map_set(vars, "brush_radius_increase", map_get(config_keymap, "brush_radius_increase")); - ui_tooltip(tr("Hold {brush_radius} and move mouse to the left or press {brush_radius_decrease} to decrease the radius\nHold {brush_radius} and move mouse to the right or press {brush_radius_increase} to increase the radius", vars)); - } - } - } -} diff --git a/lab/sources/ui_nodes_ext.ts b/lab/sources/ui_nodes_ext.ts deleted file mode 100644 index 6d21f48d..00000000 --- a/lab/sources/ui_nodes_ext.ts +++ /dev/null @@ -1,131 +0,0 @@ - -let ui_nodes_ext_last_vertices: buffer_t = null; // Before displacement - -function ui_nodes_ext_delay_idle_sleep() { - iron_delay_idle_sleep(); -} - -function ui_nodes_ext_draw_buttons(ew: f32, start_y: f32) { - if (ui_button(tr("Run"))) { - // sys_notify_on_next_frame(function() { - ui_nodes_ext_run(); - // }); - } - ui._x += ew + 3; - ui._y = 2 + start_y; - - ///if (arm_android || arm_ios) - let base_res_combo: string[] = ["128", "256", "512", "1K", "2K", "4K"]; - ui_combo(base_res_handle, base_res_combo, tr("Resolution")); - ///else - let base_res_combo: string[] = ["128", "256", "512", "1K", "2K", "4K", "8K", "16K"]; - ui_combo(base_res_handle, base_res_combo, tr("Resolution")); - ///end - - if (base_res_handle.changed) { - layers_on_resized(); - } - ui._x += ew + 3; - ui._y = 2 + start_y; -} - -function ui_nodes_ext_run() { - sys_notify_on_render(ui_nodes_ext_delay_idle_sleep); - - console_progress(tr("Processing")); - - let timer: f32 = sys_time(); - parser_logic_parse(project_canvas); - - photo_to_pbr_node_cached_source = null; - let texbase: gpu_texture_t = logic_node_get_as_image(context_raw.brush_output_node_inst.base, channel_type_t.BASE_COLOR); - let texocc: gpu_texture_t = logic_node_get_as_image(context_raw.brush_output_node_inst.base, channel_type_t.OCCLUSION); - let texrough: gpu_texture_t = logic_node_get_as_image(context_raw.brush_output_node_inst.base, channel_type_t.ROUGHNESS); - let texnor: gpu_texture_t = logic_node_get_as_image(context_raw.brush_output_node_inst.base, channel_type_t.NORMAL_MAP); - let texheight: gpu_texture_t = logic_node_get_as_image(context_raw.brush_output_node_inst.base, channel_type_t.HEIGHT); - - if (texbase != null) { - let texpaint: render_target_t = map_get(render_path_render_targets, "texpaint"); - draw_begin(texpaint._image); - draw_scaled_image(texbase, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - draw_end(); - } - - if (texnor != null) { - let texpaint_nor: render_target_t = map_get(render_path_render_targets, "texpaint_nor"); - draw_begin(texpaint_nor._image); - draw_scaled_image(texnor, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - draw_end(); - } - - let texpaint_pack: render_target_t = map_get(render_path_render_targets, "texpaint_pack"); - - if (texocc != null) { - draw_begin(texpaint_pack._image); - draw_set_pipeline(pipes_copy_r); - draw_scaled_image(texocc, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - draw_set_pipeline(null); - draw_end(); - } - - if (texrough != null) { - draw_begin(texpaint_pack._image); - draw_set_pipeline(pipes_copy_g); - draw_scaled_image(texrough, 0, 0, config_get_texture_res_x(), config_get_texture_res_y()); - draw_set_pipeline(null); - draw_end(); - } - - if (texheight != null) { - _gpu_begin(texpaint_pack._image); - gpu_set_pipeline(pipes_copy_a); - gpu_set_texture(pipes_copy_a_tex, texheight); - gpu_set_vertex_buffer(const_data_screen_aligned_vb); - gpu_set_index_buffer(const_data_screen_aligned_ib); - gpu_draw(); - gpu_end(); - - let is_float_node: bool = context_raw.brush_output_node_inst.base.inputs[channel_type_t.HEIGHT].node.base.get == float_node_get; - - if (ui_header_worktab.position == space_type_t.SPACE3D && !is_float_node) { - - // Make copy of vertices before displacement - //// - // let o: mesh_object_t = project_paint_objects[0]; - // let g: mesh_data_t = o.data; - // let vertices: buffer_t = gpu_lock_vertex_buffer(g._.vertex_buffer); - // if (ui_nodes_ext_last_vertices == null || ui_nodes_ext_last_vertices.length != vertices.length) { - // ui_nodes_ext_last_vertices = buffer_create(vertices.length); - // for (let i: i32 = 0; i < math_floor((vertices.length) / 2); ++i) { - // // buffer_set_i16(ui_nodes_ext_last_vertices, i * 2, buffer_get_i16(vertices, i * 2)); - // } - // } - // else { - // for (let i: i32 = 0; i < math_floor((vertices.length) / 2); ++i) { - // buffer_set_i16(vertices, i * 2, buffer_get_i16(ui_nodes_ext_last_vertices, i * 2)); - // } - // } - // gpu_vertex_buffer_unlock(g._.vertex_buffer); - //// - - // Apply displacement - if (config_raw.displace_strength > 0) { - console_progress(tr("Apply Displacement")); - - let uv_scale: f32 = scene_meshes[0].data.scale_tex * context_raw.brush_scale; - util_mesh_apply_displacement(texpaint_pack._image, 0.05 * config_raw.displace_strength, uv_scale); - util_mesh_calc_normals(); - } - } - } - - let t: f32 = sys_time() - timer; - console_log("Processing finished in " + t); - iron_ml_unload(); - - console_progress(null); - context_raw.ddirty = 2; - sys_remove_render_2d(ui_nodes_ext_delay_idle_sleep); - - render_path_raytrace_ready = false; -} diff --git a/lab/sources/ui_toolbar_ext.ts b/lab/sources/ui_toolbar_ext.ts deleted file mode 100644 index f5290a0b..00000000 --- a/lab/sources/ui_toolbar_ext.ts +++ /dev/null @@ -1,4 +0,0 @@ - -function ui_toolbar_ext_draw_tools(img: gpu_texture_t, icon_accent: i32, keys: string[]) { - -} diff --git a/readme.md b/readme.md index 99416401..12961a37 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,6 @@ armortools 3D content creation tools. [armorpaint/](https://github.com/armory3d/armortools/tree/main/paint)
-[armorlab/](https://github.com/armory3d/armortools/tree/main/lab) **Generating a locale file** ```bash