SetCompileConfig
Applicability
Product |
Supported |
|---|---|
√ |
|
√ |
|
x |
|
x |
|
x |
Function Description
Sets the name and path of the JSON configuration file of FunctionPp. The configuration file is used to map FunctionPp to UDF.
FunctionPp with GraphPp added
Prototype
1 | FunctionPp &SetCompileConfig(const char_t *json_file_path) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
json_file_path |
Input |
Name and path of the JSON configuration file of FunctionPp. The configuration file is used to describe and compile UDFs. |
- JSON configuration file example of FunctionPp
{"func_list":[{"func_name":"Add", "inputs_index":[1,0], "outputs_index":[0]}],"input_num":2,"output_num":1,"target_bin":"libadd.so","workspace":"./","cmakelist_path":"CMakeLists.txt","compiler": "./cpu_compile.json","running_resources_info":[{"type":"cpu","num":2},{"type":"memory","num":100}],"heavy_load":false}
Configuration Item |
Optional/Mandatory |
Description |
|---|---|---|
workspace |
Mandatory |
UDF workspace path. The value is a string. |
target_bin |
Mandatory |
Name of the .so file, which is a string compiled by the UDF project. To prevent the string from being tampered with, the string must be named with lib***.so. The string can contain only uppercase and lowercase letters, digits, underscores (_), and hyphens (-). |
input_num |
Mandatory |
Number of UDF outputs, that is, the number of FunctionPp outputs. |
output_num |
Mandatory |
Number of UDF outputs, that is, the number of FunctionPp outputs. |
func_list |
Mandatory |
List of function descriptions. Currently, the list can contain descriptions of only one function. |
func_list.func_name |
Mandatory |
Function name, which is a string and must be consistent with that defined in the UDF. In the multi-function scenario, func_name must be unique. |
func_list.inputs_index |
Optional |
List of input indexes of FunctionPp. This parameter is invalid if only one function is involved. This field is mandatory if multiple functions are involved. Input indexes of multiple processing functions are not shared and cannot be repeated. |
func_list.outputs_index |
Optional |
List of output indexes of FunctionPp. This parameter is invalid if only one function is involved. If multiple functions are involved, output indexes can be shared. |
cmakelist_path |
Optional |
Path of the compiled CMakeLists file relative to the workspace, which is a string. If this parameter is not specified, the default CMakeLists file in the workspace will be used. |
compiler |
Optional |
Path configuration file of the compiler for compiling the source code in a heterogeneous environment, which is a string. If this parameter is not specified, the default compiler of the corresponding resource type will be used. |
running_resources_info |
Optional |
Resource information required for running the current .so file. The list element is the description of a single resource. |
running_resources_info.type |
Optional |
This parameter is mandatory if running_resources_info is set. Type of resources required for running the current .so file, which is a string. The options are cpu and memory. If the memory value is used, the unit is MB. |
running_resources_info.num |
Optional |
This parameter is mandatory if running_resources_info is set. Number of resources required for running the current .so file. |
heavy_load |
Optional |
Compute power requirements of a node.
The default value is false. If this parameter is set to true, the UDF deployment position will be affected. |
buf_cfg |
Optional |
Users can customize the memory pool tiers to improve memory allocation efficiency and reduce memory fragments. If this parameter is not set, the memory module will be initialized with the default tier configuration. The default tier configuration supports up to 64 tiers. An error will be reported during compilation if more than 64 tiers are configured. |
- JSON configuration of the compilerThe file content example and parameters in the file are as follows:
{"compiler":[{"resource_type":"X86","toolchain":"/usr/bin/g++"},{"resource_type":"Aarch","toolchain":"/usr/bin/g++"},{"resource_type":"Ascend","toolchain":"/usr/local/Ascend/hcc"}]}Table 2 compiler JSON configuration description Configuration Item
Optional/Mandatory
Description
compiler
Mandatory
The value is a list. The elements of the list are the description of the compilation tool of a single resource type.
compiler.resource_type
Mandatory
Supported resource type, which is a string.
compiler.toolchain
Mandatory
Compiler path corresponding to the resource type, which is a string.
- JSON configuration of buf_cfgTable 3 describes the file content example and parameters in the file.
"buf_cfg":[{"total_size":2097152,"blk_size":256,"max_buf_size":8192,"page_type":"normal"}, // 1.total:2M max:8K {"total_size":10485760,"blk_size":4096,"max_buf_size":8388608,"page_type":"normal"}, // 2.total:10M max:8M {"total_size":2097152,"blk_size":256,"max_buf_size":8192,"page_type":"huge"}, // 3.total:2M max:8K {"total_size":10485760,"blk_size":8192,"max_buf_size":8388608,"page_type":"huge"}, // 4.total:10M max:8M {"total_size":69206016,"blk_size":8192,"max_buf_size":67108864,"page_type":"huge"}] // 5.total:66M max:64MIn the preceding example, five memory levels are set. The first two levels are for common memory, and the last three levels are for hugepage memory.
After the memory management module is initialized with this configuration, if a process applies for 8 MB hugepage memory, the driver generates and manages a 10 MB memory pool based on the fourth configuration item and allocates 8 MB memory from the pool.
If the process needs to apply for 1 MB hugepage memory again, the memory pool corresponding to the fourth configuration item is still used because the maximum size of the third configuration item is 8 KB. In this case, only 8 MB memory is used in the 10 MB memory pool, and the remaining memory is still greater than 1 MB. Therefore, 1 MB memory is allocated from the 10 MB memory pool generated last time.
The default tiers are as follows:
ID
total_size
blk_size
max_buf_size
page_type
0
2M
256B
8K
normal
1
32M
8K
8M
normal
3
2M
256B
8K
huge
4
66M
8K
64M
huge
Table 3 buf_cfg JSON configuration description Configuration Item
Optional/Mandatory
Description
total_size
Mandatory
Size of the memory pool at the current level, in bytes.
Constraints: For common memory, the value of total_size is a multiple of 4 KB. For hugepage memory, the value of total_size is a multiple of 2 MB and a multiple of blk_size.
blk_size
Mandatory
Minimum memory that can be allocated at a time at the current level, in bytes.
Constraints: The value of blk_size must be 2n ranging from 0 MB to 2 MB, and less than the value of max_buf_size.
max_buf_size
Mandatory
Maximum memory that can be allocated at a time at the current level, in bytes.
Constraints: The value of max_buf_size must be less than that of total_size and must be in an ascending order for the same page_type.
page_type
Mandatory
Memory type corresponding to the current tier. The options are as follows:
- huge: hugepage memory
- normal: common memory
- CMakeLists file
The UDF compilation module of DataFlow parses the resource.json and cpu_compiler.json file in the heterogeneous environment, and matches cross compilers specified in cpu_compiler.json based on resource types configured in resource.json. If no cpu_compiler.json is specified or no compiler is configured for the resource type in cpu_compiler.json, the default compiler in the environment will be used for compilation. The names and paths of compilers for different resource types are as follows: Replace ${INSTALL_DIR} with the CANN component directory. For example, if the installation is performed by the root user, the default file storage path is /usr/local/Ascend/cann.
- x86 and AArch: g++
- Ascend: ${INSTALL_DIR}/toolkit/toolchain/hcc/bin/aarch64-target-linux-gnu-g++
The source code project must comply with the following rules:- The source code project directory provided by the user must contain all execution code and dependency library source code.
- You need to configure the FunctionPp execution code and the compilation script of the dependency library.
- The compilation script needs to use the RELEASE_DIR variable as the final output directory. If there are dependent .so files, you need to copy them to this directory.
- The compilation script needs to use the RESOURCE_TYPE variable to determine the resource type. If the current UDF does not support a resource type, you need to remove the corresponding comments.
- The CMakeLists sample is as follows:
cmake_minimum_required(VERSION 3.5) PROJECT(UDF) if ("x${RESOURCE_TYPE}" STREQUAL "xAscend") message(STATUS "ascend compiler enter") # if unsupport current resource type, please uncomment the next line. # message(FATAL_ERROR "Unsupport compile Ascend target!") elseif("x${RESOURCE_TYPE}" STREQUAL "xAarch") message(STATUS "aarch64 compiler enter") # if unsupport current resource type, please uncomment the next line. # message(FATAL_ERROR "Unsupport compile Aarch64 target!") else() message(STATUS "x86 compiler enter") # if unsupport current resource type, please uncomment the next line. # message(FATAL_ERROR "Unsupport compile X86 target!") endif() if (DEFINED ENV{ASCEND_HOME_PATH}) set(ASCEND_HOME_PATH $ENV{ASCEND_HOME_PATH}) message(STATUS "Read ASCEND_HOME_PATH from ENV: ${ASCEND_HOME_PATH}") else () message(FATAL_ERROR "ASCEND_HOME_PATH is not set, please export ASCEND_HOME_PATH based on actual installation path.") endif () # set dynamic library output path set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${RELEASE_DIR}) # set static library output path set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${RELEASE_DIR}) message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY= ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") set(INC_DIR "${ASCEND_HOME_PATH}/include") file(GLOB SRC_LIST "*.cpp") # Specify cross compiler add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) # set c++ compiler set(CMAKE_CXX_COMPILER ${TOOLCHAIN}) # =========================UDF so compile============================ # check if SRC_LIST is exist if("x${SRC_LIST}" STREQUAL "x") message(UDF "=========no source file=============") add_custom_target(${UDF_TARGET_LIB} COMMAND echo "no source to make lib${UDF_TARGET_LIB}.so") return(0) endif() add_library(${UDF_TARGET_LIB} SHARED ${SRC_LIST} ) target_include_directories(${UDF_TARGET_LIB} PRIVATE ${INC_DIR} ) target_compile_options(${UDF_TARGET_LIB} PRIVATE -O2 -std=c++11 -ftrapv -fstack-protector-all -fPIC ) if ("x${RESOURCE_TYPE}" STREQUAL "xAscend") target_link_libraries(${UDF_TARGET_LIB} PRIVATE -Wl,--whole-archive ${ASCEND_HOME_PATH}/devlib/device/libflow_func.so -Wl,--no-whole-archive ) # If there have any dependent so, please release the following comments and copy dependent so to ${PROJECT_BINARY_DIR}/${RELEASE_DIR} # [[execute_process( COMMAND cp libdepend_xxx.so ${PROJECT_BINARY_DIR}/${RELEASE_DIR} )]] elseif("x${RESOURCE_TYPE}" STREQUAL "xAarch") target_link_libraries(${UDF_TARGET_LIB} PRIVATE -Wl,--whole-archive ${ASCEND_HOME_PATH}/devlib/linux/aarch64/libflow_func.so -Wl,--no-whole-archive ) # If there have any dependent so, please release the following comments and copy dependent so to ${PROJECT_BINARY_DIR}/${RELEASE_DIR} # [[execute_process( COMMAND cp libdepend_xxx.so ${PROJECT_BINARY_DIR}/${RELEASE_DIR} )]] else() target_link_libraries(${UDF_TARGET_LIB} PRIVATE -Wl,--whole-archive ${ASCEND_HOME_PATH}/devlib/linux/x86_64/libflow_func.so -Wl,--no-whole-archive ) # If there have any dependent so, please release the following comments and copy dependent so to ${PROJECT_BINARY_DIR}/${RELEASE_DIR} # [[execute_process( COMMAND cp libdepend_xxx.so ${PROJECT_BINARY_DIR}/${RELEASE_DIR} )]] endif()
Returns
FunctionPp with GraphPp added
Exception Handling
None
Constraints
None