1 /* 2 * Copyright (c) 2019, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 /** 23 * Runtime interface of CM Fast Compposite Linker. 24 */ 25 26 #pragma once 27 28 #ifndef _CM_FC_LD_H_ 29 #define _CM_FC_LD_H_ 30 31 #include <stddef.h> 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /** 38 * @defgroup CM Fast Composite Runtime Linking/Combining interfaces 39 * 40 * @{ 41 */ 42 43 /** 44 * @brief Return value of CM fast composite linking interface. 45 */ 46 enum cm_fc_error { 47 CM_FC_OK = 0, /**< The operation succeeds. */ 48 CM_FC_FAILURE = -1, /**< The operation fails. */ 49 CM_FC_NOBUFS = -2 /**< The operation fails due to insufficient 50 buffer space. */ 51 }; 52 53 /** 54 * @brief Link type of a given fast composite kernel. 55 */ 56 enum cm_fc_link_type { 57 CM_FC_LINK_TYPE_NONE = 0, /**< The kernel doesn't call anything. */ 58 CM_FC_LINK_TYPE_CALLER = 1, /**< The kernel calles a caller kernel. */ 59 CM_FC_LINK_TYPE_CALLEE = 2 /**< The kernel is called, i.e. a callable 60 kernel. */ 61 }; 62 63 /** 64 * @brief Return the callee name from the specified patch info. 65 * 66 * @param buf The buffer containing CM patch info. 67 * @param size The size of @p buf. 68 * @param out_name The buffer to be filled with caller's name string. 69 * @param out_size Specifies the size in bytes of @p out_name. If CM_FC_OK or 70 * CM_FC_INVALID_VALUE is returned, it's also set to the real 71 * size size in bytes used or required for @p out_name. 72 */ 73 int cm_fc_get_callee_info(const char *buf, size_t size, 74 void *C, 75 cm_fc_link_type *out_link_type); 76 77 /** 78 * @brief The structure holding patch info and binary of a kernel to be linked. 79 */ 80 typedef struct { 81 const char *patch_buf; /**< The buffer containing patch info. */ 82 size_t patch_size; /**< The size of that patch info. */ 83 const char *binary_buf; /**< The buffer contain binary. */ 84 size_t binary_size; /**< The sizeo of that binary. */ 85 } cm_fc_kernel_t; 86 87 /** 88 * @brief Combine the given kernels. 89 * 90 * @param num_kernels The number of kernels to be combined/linked. 91 * @param kernels The array of kernels to be combined/linked. 92 * @param out_buf The buffer to be filled with the combined binary. 93 * @param out_size Specifies the size in bytes of @p out_buf. If CM_FC_OK 94 * or CM_FC_INVALID_VALUE is returned, it's also set to 95 * the real size in bytes used or required for @p out_buf. 96 * @param options The additional linking options which is organized as 97 * space-separated string terminated by null character. 98 */ 99 int cm_fc_combine_kernels(size_t num_kernels, cm_fc_kernel_t *kernels, 100 char *out_buf, size_t *out_size, 101 const char *options); 102 103 #ifdef __cplusplus 104 } 105 #endif 106 107 #endif /* _CM_FC_LD_H_ */ 108