From def54026c25dbd9f8110beb7c66ba068aac098db Mon Sep 17 00:00:00 2001 From: Viraj Malia Date: Thu, 12 Dec 2024 11:56:50 -0800 Subject: [PATCH] Remove deprecated scripts and BLAS list files (#620) --- .github/CODEOWNERS | 1 - docs/create_new_backend.rst | 62 +++------- scripts/blas_list.txt | 178 ----------------------------- scripts/func_parser.py | 190 ------------------------------- scripts/generate_backend_api.py | 122 -------------------- scripts/generate_cmake.py | 129 --------------------- scripts/generate_ct_instant.py | 134 ---------------------- scripts/generate_ct_templates.py | 122 -------------------- scripts/generate_wrappers.py | 172 ---------------------------- 9 files changed, 13 insertions(+), 1097 deletions(-) delete mode 100644 scripts/blas_list.txt delete mode 100755 scripts/func_parser.py delete mode 100755 scripts/generate_backend_api.py delete mode 100644 scripts/generate_cmake.py delete mode 100755 scripts/generate_ct_instant.py delete mode 100755 scripts/generate_ct_templates.py delete mode 100755 scripts/generate_wrappers.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5fb7c42d6..94f4aaf81 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -11,7 +11,6 @@ /include/oneapi/math/detail/ @uxlfoundation/onemath-arch-write /include/oneapi/mkl.hpp @uxlfoundation/onemath-arch-write /include/oneapi/mkl/namespace_alias.hpp @uxlfoundation/onemath-arch-write -/scripts/ @uxlfoundation/onemath-arch-write /src/include/ @uxlfoundation/onemath-arch-write /src/CMakeLists.txt @uxlfoundation/onemath-arch-write /src/config.hpp.in @uxlfoundation/onemath-arch-write diff --git a/docs/create_new_backend.rst b/docs/create_new_backend.rst index 374debc3b..a3e3c3c4a 100644 --- a/docs/create_new_backend.rst +++ b/docs/create_new_backend.rst @@ -30,7 +30,7 @@ If there is no need for multiple wrappers only ```` and ``<3rd-party lib `5. Update the Test System`_ -.. _generate_header_files: +.. _create_header_files: 1. Create Header Files ---------------------- @@ -40,15 +40,7 @@ For each new backend library, you should create the following two header files: * Header file with a declaration of entry points to the new third-party library wrappers * Compiler-time dispatching interface (see `oneMath Usage Models <../README.md#supported-usage-models>`_) for new third-party libraries -**Header File Example**: command to generate the header file with a declaration of BLAS entry points in the oneapi::math::newlib namespace - -.. code-block:: bash - - python scripts/generate_backend_api.py include/oneapi/math/blas.hpp \ # Base header file - include/oneapi/math/blas/detail/newlib/onemath_blas_newlib.hpp \ # Output header file - oneapi::math::newlib # Wrappers namespace - -Code snippet of the generated header file ``include/oneapi/math/blas/detail/newlib/onemath_blas_newlib.hpp`` +Example header file ``include/oneapi/math/blas/detail/newlib/onemath_blas_newlib.hpp`` .. code-block:: cpp @@ -61,18 +53,9 @@ Code snippet of the generated header file ``include/oneapi/math/blas/detail/newl -**Compile-time Dispatching Interface Example**: command to generate the compile-time dispatching interface template instantiations for ``newlib`` and supported device ``newdevice`` - -.. code-block:: bash - - python scripts/generate_ct_instant.py include/oneapi/math/blas/detail/blas_ct_templates.hpp \ # Base header file - include/oneapi/math/blas/detail/newlib/blas_ct.hpp \ # Output header file - include/oneapi/math/blas/detail/newlib/onemath_blas_newlib.hpp \ # Header file with declaration of entry points to wrappers - newlib \ # Library name - newdevice \ # Backend name - oneapi::math::newlib # Wrappers namespace +**Compile-time Dispatching Interface Example**: -Code snippet of the generated header file ``include/oneapi/math/blas/detail/newlib/blas_ct.hpp`` +Example of the compile-time dispatching interface template instantiations for ``newlib`` and supported device ``newdevice`` in ``include/oneapi/math/blas/detail/newlib/blas_ct.hpp``. .. code-block:: cpp @@ -179,9 +162,9 @@ To integrate the new third-party library to a oneMath header-based part, followi + if (queue.is_host()) + device_id=device::newdevice; -* ``include/oneapi/math/blas.hpp``: include the generated header file for the compile-time dispatching interface (see `oneMath Usage Models <../README.md#supported-usage-models>`_) +* ``include/oneapi/math/blas.hpp``: include the created header file for the compile-time dispatching interface (see `oneMath Usage Models <../README.md#supported-usage-models>`_) - **Example**: add ``include/oneapi/math/blas/detail/newlib/blas_ct.hpp`` generated at the `1. Create Header Files`_ step + **Example**: add ``include/oneapi/math/blas/detail/newlib/blas_ct.hpp`` created at the `1. Create Header Files`_ step .. code-block:: diff @@ -190,7 +173,7 @@ To integrate the new third-party library to a oneMath header-based part, followi + #include "oneapi/math/blas/detail/newlib/blas_ct.hpp" -The new files generated at the `1. Create Header Files`_ step result in the following updated structure of the BLAS domain header files. +The new files created at the `1. Create Header Files`_ step result in the following updated structure of the BLAS domain header files. .. code-block:: diff @@ -215,7 +198,7 @@ The new files generated at the `1. Create Header Files`_ step result in the foll / / -.. _generate_wrappers_and_cmake: +.. _create_wrappers_and_cmake: 3. Create Wrappers ------------------ @@ -240,24 +223,13 @@ All wrappers and dispatcher library implementations are in the ``src`` directory Each backend library should contain a table of all functions from the chosen domain. -``scripts/generate_wrappers.py`` can help to generate wrappers with the "Not implemented" exception for all functions based on the provided header file. +**Example**: Create wrappers for ``newlib`` based on the header files created and integrated previously, and enable only one ``asum`` function -You can modify wrappers generated with this script to enable third-party library functionality. - -**Example**: generate wrappers for ``newlib`` based on the header files generated and integrated previously, and enable only one ``asum`` function - -The command below generates two new files: +Create two new files: * ``src/blas/backends/newlib/newlib_wrappers.cpp`` - DPC++ wrappers for all functions from ``include/oneapi/math/blas/detail/newlib/onemath_blas_newlib.hpp`` * ``src/blas/backends/newlib/newlib_wrappers_table_dyn.cpp`` - structure of symbols for run-time dispatcher (in the same location as wrappers), suffix ``_dyn`` indicates that this file is required for dynamic library only. -.. code-block:: bash - - python scripts/generate_wrappers.py include/oneapi/math/blas/detail/newlib/onemath_blas_newlib.hpp \ # Base header file - src/blas/function_table.hpp \ # Declaration for structure of symbols - src/blas/backends/newlib/newlib_wrappers.cpp \ # Output wrappers - newlib # Library name - You can then modify ``src/blas/backends/newlib/newlib_wrappers.cpp`` to enable the C function ``newlib_sasum`` from the third-party library ``libnewlib.so``. To enable this function: @@ -374,19 +346,11 @@ Here is the list of files that should be created/updated to integrate the new wr * Create the ``src//backends//CMakeList.txt`` cmake config file to specify how to build the backend layer for the new third-party library. - ``scripts/generate_cmake.py`` can help to generate the initial ``src//backends//CMakeList.txt`` config file automatically for all files in the directory. - Note: all source files with the ``_dyn`` suffix are added to build if the target is a dynamic library only. - - **Example**: command to generate the cmake config file for the ``src/blas/backends/newlib`` directory - - .. code-block:: bash + Check existing backends as a reference to create ``cmake/FindXXX.cmake`` file. - python scripts/generate_cmake.py src/blas/backends/newlib \ # Full path to the directory - newlib # Library name + You should update the config file with information about the new ``cmake/FindXXX.cmake`` file and instructions about how to link with the third-party library. - You should manually update the generated config file with information about the new ``cmake/FindXXX.cmake`` file and instructions about how to link with the third-party library. - - **Example**: update the generated ``src/blas/backends/newlib/CMakeLists.txt`` file + **Example**: update the ``src/blas/backends/newlib/CMakeLists.txt`` file .. code-block:: diff diff --git a/scripts/blas_list.txt b/scripts/blas_list.txt deleted file mode 100644 index cc7f0a05a..000000000 --- a/scripts/blas_list.txt +++ /dev/null @@ -1,178 +0,0 @@ -asum -asum -asum -asum -axpy -axpy -axpy -axpy -copy -copy -copy -copy -dot -dot -dot -dotc -dotc -dotu -dotu -iamin -iamin -iamin -iamin -iamax -iamax -iamax -iamax -nrm2 -nrm2 -nrm2 -nrm2 -rot -rot -rot -rot -rotg -rotg -rotg -rotg -rotm -rotm -rotmg -rotmg -scal -scal -scal -scal -scal -scal -sdsdot -swap -swap -swap -swap -gbmv -gbmv -gbmv -gbmv -gemv -gemv -gemv -gemv -ger -ger -gerc -gerc -geru -geru -hbmv -hbmv -hemv -hemv -her -her -her2 -her2 -hpmv -hpmv -hpr -hpr -hpr2 -hpr2 -sbmv -sbmv -spmv -spmv -spr -spr -spr2 -spr2 -symv -symv -syr -syr -syr2 -syr2 -tbmv -tbmv -tbmv -tbmv -tbsv -tbsv -tbsv -tbsv -tpmv -tpmv -tpmv -tpmv -tpsv -tpsv -tpsv -tpsv -trmv -trmv -trmv -trmv -trsv -trsv -trsv -trsv -gemm -gemm -gemm -gemm -gemm -hemm -hemm -herk -herk -her2k -her2k -symm -symm -symm -symm -syrk -syrk -syrk -syrk -syr2k -syr2k -syr2k -syr2k -trmm -trmm -trmm -trmm -trsm -trsm -trsm -trsm -gemm_batch -gemm_batch -gemm_batch -gemm_batch -gemm_batch -gemm_batch -gemm_batch -gemm_batch -trsm_batch -trsm_batch -trsm_batch -trsm_batch -trsm_batch -trsm_batch -trsm_batch -trsm_batch -gemmt -gemmt -gemmt -gemmt -gemm_ext -gemm_ext -gemm_ext -gemm_ext -gemm_ext -gemm_ext -gemm_ext diff --git a/scripts/func_parser.py b/scripts/func_parser.py deleted file mode 100755 index cbaa26142..000000000 --- a/scripts/func_parser.py +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env python -#=============================================================================== -# Copyright 2020-2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# -# SPDX-License-Identifier: Apache-2.0 -#=============================================================================== - -from sys import argv, exit, stdin -from collections import defaultdict -import re - -def parse_item(item): - func_type_and_name, par_str = item.split('(', 1) - ret_type, func_name = func_type_and_name.strip().rsplit(' ', 1) - """remove macros callback""" - ret_type = re.sub('^[A-Z_]+ ','',ret_type) - """remove macros calling convention""" - ret_type = re.sub(' [A-Z_]+$','',ret_type.strip()) - """remove templates""" - ret_type = re.sub('template\s+<[a-zA-Z, _*:]*>','',ret_type.strip()) - if func_name[0] == '*': - ret_type += ' *' - func_name = func_name[1:] - - par_str = re.sub('^\s*(void)\s*$', '', par_str.strip(');')) - - """Extract callback calls from parameter list and replace them by temp 'cllbck' param""" - clbck_type = None - clbck_param = None - if par_str.find('(') != -1: - par_str = re.sub('[)]\s*[(]', ')(', par_str) - clbck_re = re.compile(r'\w*\s*[(]\s*[A-Z_]*\s*[*]\s*\w*\s*[)]\s*[(][\w*,\[\]\s]*[)]') - clbck_list = clbck_re.findall(par_str) - clbck_type = [ re.sub('[*]\s*\w*', '*', x.split(')(')[0]) for x in clbck_list] - clbck_param = [ x.split(')(')[1] for x in clbck_list] - - par_str = re.sub('[)]\s*[(][\w*,\[\]\s]*[)]', '', par_str) - par_str = re.sub('\w*\s*[(]\s*[A-Z_]*\s*[\w]*\s*[*]\s*', 'cllbck ', par_str) - par_str_ = re.sub('[,]+(?![^<]+>)', '@', par_str) - par_list = [x.strip() for x in par_str_.split('@') \ - if len(x.strip()) > 0 ] - """Split list of parameters to types and names""" - if len(par_list) > 0: - """Add parameter names (param1, param2, etc) if the declaration includes only types""" - if re.search('(,|^)+\s*(const)*\s*[\w:]+\s*[*]*\s*(,|$)+', re.sub('<[\s\w\d,]*>', '', par_str)) is not None: - par_list = [(x + ' param' + str(idx)).replace(" * ", " *" \ - ).replace("[] param" + str(idx), "param" + str(idx) + "[]") \ - for idx, x in enumerate(par_list)] - - """Extract names to call_list""" - call_list = [x.split('=', 1)[0].strip().rsplit(' ', 1)[1].strip(' *').strip('\[\]').strip('&') \ - for x in par_list] - - """Extract types to sig_list""" - par_list_wo_st_arrays = [(x.rsplit(' ', 1)[0] + \ - (lambda x: '* ' if x.find('[]') != -1 else ' ')(x.rsplit(' ', 1)[1]) + \ - (x.rsplit(' ', 1)[1]).strip('\[\]')) for x in par_list] - sig_list = [(x.rsplit(' ', 1)[0] + \ - (x.rsplit(' ', 1)[1].startswith('*') \ - and (' ' + x.rsplit(' ', 1)[1].count('*') * '*') or '')) \ - for x in par_list_wo_st_arrays] - else: - call_list = list() - sig_list = list() - par_str = '(' + ', '.join(par_list) + ')' - call_str = '(' + ', '.join(call_list) + ')' - sig_str = '(' + ', '.join(sig_list) + ')' - - """Put real callback call types back to the param_list and sig_str """ - if clbck_param is not None: - for idx, x in enumerate(clbck_param): - par_str = re.sub(r'(cllbck\s*\w*)[,]', r'\1(' + x + ',', par_str, idx) - sig_str = re.sub(r'(cllbck\s*\w*)[,]', r'\1(' + x + ',', sig_str, idx) - - if clbck_type is not None: - for idx, x in enumerate(clbck_type): - par_str = re.sub(r'cllbck(\s*\w*)', x + r'\1)', par_str, idx) - sig_str = re.sub(r'cllbck(\s*\w*)', x + r'\1)', sig_str, idx) - return func_name, ret_type, func_name, par_str, call_str, sig_str, call_list, sig_list - - -def to_dict(func_data): - """ convert (ret_type, 'name', par_str, call_str, sig_str, call_list, sig_list) tuple to - dict with corresponding keys """ - return dict(zip(('ret_type', 'name', 'par_str', 'call_str', 'sig_str', 'call_list', 'sig_list'), func_data)) - -is_comment = 0 -is_wrapperbody = 0 -def strip_line(l): - """ remove global variables""" - if re.search('^\s*\w+\s*\w+[;]', l) is not None: - l = '' - """ remove namespaces""" - if re.search('^\s*namespace\s*\w+\s*[{]', l) is not None: - l = '' - """ remove declaration keywords """ - l = re.sub("^extern ", "", l) - l = re.sub("^static ", "", l) - l = re.sub("^inline ", "", l) - """ remove extra whitespace and comments from input line """ - l = re.sub("[)][A-Za-z0-9\s_]*[;]", ");", l) - - """ remove simple wrapper function body""" - global is_wrapperbody - if is_wrapperbody == 1: - if re.search('^\s*}', l) is not None: - l = l.split('}', 1)[1].strip() - is_wrapperbody = 0 - else: - return "" - - m = re.search(r'[)]\s*\n*\s*[{]', l) - if m is not None: - l = l[:m.end()].strip('{').strip() + ";" - is_wrapperbody = 1 - - global is_comment - if is_comment == 1: - if re.search('\*/', l) is not None: - l = l.split('*/', 1)[1].strip() - is_comment = 0 - else: - return "" - """ Delete comments """ - l1 = l.split('#', 1)[0].strip() - l2 = l1.split('//', 1)[0].strip() - l3 = l2.split('/*', 1)[0].strip() - if re.search('/\*', l2) is not None: - is_comment = 1 - if re.search('\*/', l2) is not None: - is_comment = 0 - l4 = l2.split('*/', 1)[1].strip() - l3 += l4 - """ Delete comments if there are several of them in one line """ - l3 = re.sub("[/][*][\w\s]*[*][/]", "", l3); - """Delete all tabs""" - return re.sub(' +',' ', l3) - -def create_func_db(filename): - with open(filename, 'r') as f: - data = f.readlines() - funcs_db = defaultdict(list) - whole_line = "" - idx = 0 - for l in data: - stripped = strip_line(l) - if not stripped: - continue - """ Check if function contains 1 line """ - whole_line += stripped + ' ' - """ Check if there is function """ - if re.search('[(][\w\s\*/\&,_\[\]():<>={}]*[)]\s*[;]', whole_line) is None: - """ Check if there is some other staff before the function """ - if re.search('[;{}]\s*$', whole_line) is not None: - whole_line = "" - continue - else: - stripped = whole_line.strip() - whole_line = "" - parsed = parse_item(stripped) - func_name, func_data = parsed[0], parsed[1:] - funcs_db[func_name].append(to_dict(func_data)) - idx = idx + 1 - return funcs_db - -def get_namespaces(filename): - with open(filename, 'r') as f: - data = f.readlines() - namespace_list = list() - for l in data: - stripped = strip_line(l) - if re.search('^\s*namespace\s*\w+\s*[{]', l) is not None: - l = l.split("namespace", 1)[1] - l = l.split("{", 1)[0] - namespace_list.append(l.strip()) - return namespace_list - diff --git a/scripts/generate_backend_api.py b/scripts/generate_backend_api.py deleted file mode 100755 index 3fde4a8b3..000000000 --- a/scripts/generate_backend_api.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python -#=============================================================================== -# Copyright 2020-2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# -# SPDX-License-Identifier: Apache-2.0 -#=============================================================================== - -from sys import argv, exit, stdin -from subprocess import call -from pprint import pprint -from collections import defaultdict -import errno -import re -import os - -from func_parser import create_func_db, get_namespaces - -def usage(err = None): - if err: - print('error: %s' % err) - print('''\ -Script to generate backend library header based on base_header.h -Note: requires clang-format tool to be installed -Usage: - - {script} - -Example: -The command below will generate: -"onemath_blas_mklgpu.hpp" header with declaration of all backend library APIs. -API from backend library will be called from "oneapi::math::mklgpu::blas" namespace. - -{script} include/oneapi/math/blas.hpp include/oneapi/math/blas/detail/mklgpu/onemath_blas_mklgpu.hpp oneapi::math::mklgpu::blas -'''.format(script = argv[0])) - -if len(argv) < 3: - usage() - exit(0) - -if re.search(r'[-]*\b[h]([e][l][p])?\b' ,argv[1]): - usage() - exit(0) - -in_filename = argv[1] -out_headername = argv[2] -namespace = argv[3] - -namespace_list=namespace.split("::") - -header_db = create_func_db(in_filename) - -print("Generate " + out_headername) - -def print_declaration(func_list): - code="" - for data in func_list: - code +=""" -{ret_type} {name}{par_str}; - -""".format(**data) - return code - -try: - os.makedirs(os.path.dirname(out_headername)) -except OSError as exc: - if exc.errno != errno.EEXIST: - raise - -out_file = open(out_headername, "w+") -out_file.write("""// -// Generated based on {in_filename} -// - -#pragma once - -#if __has_include() -#include -#else -#include -#endif - -#include -#include - -#include "oneapi/math/types.hpp" -""".format(in_filename=in_filename)) - -for nmsp in namespace_list: - out_file.write("""namespace {name} {{ -""".format(name=nmsp)) - -for func_name, func_list in header_db.items(): - out_file.write(""" -{funcs}""".format(funcs=print_declaration(func_list))) - -for nmsp in reversed(namespace_list): - out_file.write("""}} // namespace {name} {{ -""".format(name=nmsp)) - -out_file.close() - -print("Formatting with clang-format " + out_headername) -try: - lc = ["clang-format", "-style=file", "-i", out_headername] - call(lc) -except OSError as exc: - if exc.errno == errno.ENOENT: - print("Error: clang-format is not found") - diff --git a/scripts/generate_cmake.py b/scripts/generate_cmake.py deleted file mode 100644 index 506cf3529..000000000 --- a/scripts/generate_cmake.py +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env python -#=============================================================================== -# Copyright 2020-2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# -# SPDX-License-Identifier: Apache-2.0 -#=============================================================================== - -from sys import argv, exit, stdin -from subprocess import call -from pprint import pprint -from collections import defaultdict -import re -import os - -from func_parser import create_func_db, get_namespaces - -def usage(err = None): - if err: - print('error: %s' % err) - print('''\ -Script to generate CMakeLists.txt for all files in the specified directory -Usage: - - {script} - -Example: - - {script} include/oneapi/math/blas/detail/mklgpu mklgpu -'''.format(script = argv[0])) - -if len(argv) <= 2: - usage() - exit(0) - -if re.search(r'[-]*\b[h]([e][l][p])?\b' ,argv[1]): - usage() - exit(0) - -in_dir = argv[1] -libname = argv[2] - -if not os.path.exists(in_dir): - print("Error: directory " + in_dir + " doesn't exist\n") - exit(1) - -cmake_file = in_dir + "/CMakeLists.txt" - -if os.path.exists(cmake_file): - print("Error: file " + cmake_file + " already exists\n") - exit(1) -else: - print("Generate " + cmake_file) - -file_list = os.listdir(in_dir) - -out_file = open(cmake_file, "w+") - -out_file.write("""# -# generated file -# - -set(LIB_NAME onemath_blas_{libname}) -set(LIB_OBJ ${{LIB_NAME}}_obj) - -# Add third-party library -# find_package(XXX REQUIRED) - -add_library(${{LIB_NAME}}) -add_library(${{LIB_OBJ}} OBJECT -""".format(libname=libname)) - -for f in file_list: - if re.search('_dyn.c', f): - out_file.write(""" $<$: {filename}> -""".format(filename=f)) - else: - out_file.write(""" {filename} -""".format(filename=f)) - -out_file.write(""" -) - -target_include_directories(${{LIB_OBJ}} - PRIVATE ${{PROJECT_SOURCE_DIR}}/include - ${{PROJECT_SOURCE_DIR}}/src -) - -target_link_libraries(${{LIB_OBJ}} - PUBLIC ONEMATH::SYCL::SYCL - # Add third party library to link with here -) - -target_compile_features(${{LIB_OBJ}} PUBLIC cxx_std_14) -set_target_properties(${{LIB_OBJ}} PROPERTIES - POSITION_INDEPENDENT_CODE ON -) -target_link_libraries(${{LIB_NAME}} PUBLIC ${{LIB_OBJ}}) - -# Add major version to the library -set_target_properties(${{LIB_NAME}} PROPERTIES - SOVERSION ${{PROJECT_VERSION_MAJOR}} -) - -# Add dependencies rpath to the library -list(APPEND CMAKE_BUILD_RPATH $) - -# Add the library to install package -install(TARGETS ${{LIB_OBJ}} EXPORT oneMathTargets) -install(TARGETS ${{LIB_NAME}} EXPORT oneMathTargets - RUNTIME DESTINATION bin - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib -) -""".format()) - -out_file.close() diff --git a/scripts/generate_ct_instant.py b/scripts/generate_ct_instant.py deleted file mode 100755 index 7ed4b12b9..000000000 --- a/scripts/generate_ct_instant.py +++ /dev/null @@ -1,134 +0,0 @@ -#!/usr/bin/env python -#=============================================================================== -# Copyright 2020-2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# -# SPDX-License-Identifier: Apache-2.0 -#=============================================================================== - -from sys import argv, exit, stdin -from subprocess import call -from pprint import pprint -from collections import defaultdict -import errno -import re -import os - -from func_parser import create_func_db, get_namespaces - -def usage(err = None): - if err: - print('error: %s' % err) - print('''\ -Script to generate CT API instantiations for backend based on general_ct_templates.hpp -Note: requires clang-format tool to be installed -Usage: - - {script} - -Example: -The command below will generate: -"blas_ct.hpp" header with compile-time BLAS API based on "blas_ct_templates.hpp" for "mklgpu" backend. -API from the backend library will be called from "oneapi::math::mklgpu::blas" namespace. - -{script} include/oneapi/math/blas/detail/blas_ct_templates.hpp include/oneapi/math/blas/detail/mklgpu/blas_ct.hpp include/oneapi/math/blas/detail/mklgpu/onemath_blas_mklgpu.hpp mklgpu oneapi::math::mklgpu::blas -'''.format(script = argv[0])) - -if len(argv) < 6: - usage() - exit(0) - -if re.search(r'[-]*\b[h]([e][l][p])?\b' ,argv[1]): - usage() - exit(0) - -in_filename = argv[1] -out_filename = argv[2] -include = argv[3] -backend = argv[4] -namespace = argv[5] - -namespace_list=namespace.split("::") - -header_db = create_func_db(in_filename) -external_namespace_list=get_namespaces(in_filename) - -print("Generate " + out_filename) - -def print_funcs(func_list): - code="" - for data in func_list: - code +=""" -template<> -{ret_type} {name}{par_str} {{ - {name}_precondition{call_str}; - {namespace}::{name}{call_str}; - {name}_postcondition{call_str}; -}} -""".format(namespace=namespace, backend=backend, **data) - return code - -try: - os.makedirs(os.path.dirname(out_filename)) -except OSError as exc: - if exc.errno != errno.EEXIST: - raise - -out_file = open(out_filename, "w+") -out_file.write("""// -// Generated based on {in_header} -// - -#pragma once - -#if __has_include() -#include -#else -#include -#endif -#include -#include - -#include "oneapi/math/types.hpp" -#include "oneapi/math/detail/backends.hpp" -#include "{internal_api}" -#include "{ct_teplates}" - -""".format(in_header=in_filename, ct_teplates=in_filename.strip("include/"), internal_api=include.strip("include/"))) - - -for nmsp in external_namespace_list: - out_file.write("""namespace {name} {{ -""".format(name=nmsp)) - -for func_name, func_list in header_db.items(): - out_file.write(""" -{funcs}""".format(funcs=print_funcs(func_list))) - - -for nmsp in reversed(external_namespace_list): - out_file.write("""}} // namespace {name} {{ -""".format(name=nmsp)) - -out_file.close() - -print("Formatting with clang-format " + out_filename) -try: - lc = ["clang-format", "-style=file", "-i", out_filename] - call(lc) -except OSError as exc: - if exc.errno == errno.ENOENT: - print("Error: clang-format is not found") - diff --git a/scripts/generate_ct_templates.py b/scripts/generate_ct_templates.py deleted file mode 100755 index 815991866..000000000 --- a/scripts/generate_ct_templates.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python -#=============================================================================== -# Copyright 2020-2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# -# SPDX-License-Identifier: Apache-2.0 -#=============================================================================== - -from sys import argv, exit, stdin -from subprocess import call -from pprint import pprint -from collections import defaultdict -import errno -import re -import os - -from func_parser import create_func_db, get_namespaces - -def usage(err = None): - if err: - print('error: %s' % err) - print('''\ -Script to generate header file for templated compile-time API based on base_header.h -Note: requires clang-format tool to be installed -Usage: - - {script} - -Example: -The command below will generate: -"blas_ct_templates.hpp" header with general templates for compile-time BLAS API based on "blas.hpp". - - {script} include/oneapi/math/blas.hpp include/oneapi/math/blas/detail/blas_ct_templates.hpp -'''.format(script = argv[0])) - -if len(argv) < 2: - usage() - exit(0) - -if re.search(r'[-]*\b[h]([e][l][p])?\b' ,argv[1]): - usage() - exit(0) - -in_filename = argv[1] -out_filename = argv[2] - -header_db = create_func_db(in_filename) -external_namespace_list=get_namespaces(in_filename) - -print("Generate " + out_filename) - -def print_funcs(func_list): - code="" - for data in func_list: - code +=""" -template static inline {ret_type} {name}{par_str}; -""".format(**data) - return code - -try: - os.makedirs(os.path.dirname(out_filename)) -except OSError as exc: - if exc.errno != errno.EEXIST: - raise - -out_file = open(out_filename, "w+") -out_file.write("""// -// Generated based on {in_header} -// - -#pragma once - -#if __has_include() -#include -#else -#include -#endif -#include -#include - -#include "oneapi/math/types.hpp" -#include "oneapi/math/detail/backends.hpp" - -""".format(in_header=in_filename)) - - -for nmsp in external_namespace_list: - out_file.write("""namespace {name} {{ -""".format(name=nmsp)) - -for func_name, func_list in header_db.items(): - out_file.write(""" -{funcs}""".format(funcs=print_funcs(func_list))) - - -for nmsp in reversed(external_namespace_list): - out_file.write("""}} // namespace {name} {{ -""".format(name=nmsp)) - -out_file.close() - -print("Formatting with clang-format " + out_filename) -retcode = 1 -try: - lc = ["clang-format", "-style=file", "-i", out_filename] - retcode=call(lc) -except OSError as exc: - if exc.errno == errno.ENOENT: - print("Error: clang-format is not found") - diff --git a/scripts/generate_wrappers.py b/scripts/generate_wrappers.py deleted file mode 100755 index 110768f4e..000000000 --- a/scripts/generate_wrappers.py +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env python -#=============================================================================== -# Copyright 2020-2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# -# SPDX-License-Identifier: Apache-2.0 -#=============================================================================== - -from sys import argv, exit, stdin -from subprocess import call -from pprint import pprint -from collections import defaultdict -import errno -import re -import os - -from func_parser import create_func_db, get_namespaces - -def usage(err = None): - if err: - print('error: %s' % err) - print('''\ -Script to generate blank wrappers and pointers table based on header.hpp -Note: requires clang-format tool -Usage: - - {script} - -Example: - - {script} include/oneapi/math/blas/detail/mklgpu/onemath_blas_mklgpu.hpp src/blas/function_table.hpp src/blas/backend/mklgpu/wrappers.cpp mklgpu -'''.format(script = argv[0])) - -if len(argv) <= 4: - usage() - exit(0) - -if re.search(r'[-]*\b[h]([e][l][p])?\b' ,argv[1]): - usage() - exit(0) - -in_filename = argv[1] -in_table = argv[2] -out_filename = argv[3] -libname = argv[4] - -table_list = argv[0].rsplit('/', 1)[0] + "/blas_list.txt" -table_file = out_filename.rsplit('/', 1)[0] + "/" + libname + "_wrappers_table_dyn.cpp" - -cmake_file = out_filename.rsplit('/', 1)[0] + "/CMakeLists.txt" - -header_db = create_func_db(in_filename) -namespace_list = get_namespaces(in_filename) - -# Generate wrappers -print("Generate " + out_filename) - -def print_funcs(func_list): - code="" - for data in func_list: - code +=""" -{ret_type} {name}{par_str} {{ - throw std::runtime_error("Not implemented for {libname}"); -}} -""".format(libname=libname, **data) - return code - -try: - os.makedirs(os.path.dirname(out_filename)) -except OSError as exc: - if exc.errno != errno.EEXIST: - raise - -out_file = open(out_filename, "w+") -out_file.write("""// -// generated file -// - -#if __has_include() -#include -#else -#include -#endif - -#include "oneapi/math/types.hpp" - -#include "{header}" - -""".format(header=in_filename.strip("include/"))) - -for nmsp in namespace_list: - out_file.write("""namespace {name} {{ -""".format(name=nmsp)) - -for func_name, func_list in header_db.items(): - out_file.write(""" -{funcs}""".format(funcs=print_funcs(func_list))) - -out_file.write("\n") -for nmsp in reversed(namespace_list): - out_file.write("""}} // namespace {name} {{ -""".format(name=nmsp)) - -out_file.close() - -print("Formatting with clang-format " + out_filename) -try: - lc = ["clang-format", "-style=file", "-i", out_filename] - call(lc) -except OSError as exc: - if exc.errno == errno.ENOENT: - print("Error: clang-format is not found") - else: - raise - -# Generate table -print("Generate " + table_file) - -try: - os.makedirs(os.path.dirname(table_file)) -except OSError as exc: - if exc.errno != errno.EEXIST: - raise - -out_file = open(table_file, "w+") -out_file.write("""// -// generated file -// - -#include "{header}" -#include "{table}" - -#define WRAPPER_VERSION 1 - -extern "C" function_table_t onemath_blas_table = {{ - WRAPPER_VERSION, -""".format(table=in_table.strip('src/'), header=in_filename.strip('include/'))) - -namespace = "" -for nmsp in namespace_list: - namespace = namespace + nmsp.strip() + "::" -with open(table_list, "r") as f: - table = f.readlines() - -for t in table: - out_file.write(" " + namespace + t.strip() + ",\n") - - -out_file.write("\n};\n") -out_file.close() - -print("Formatting with clang-format " + table_file) -try: - lc = ["clang-format", "-style=file", "-i", table_file] - call(lc) -except OSError as exc: - if exc.errno == errno.ENOENT: - print("Error: clang-format is not found") - else: - raise