Files
blis/build/blis_ref_kernel_mirror.py
Smyth, Edward a2905f7240 Merge commit 'db3134ed6d239a7962a2b7470d8c46611b9d17ef' into AOCL-5.2-RC
* commit 'db3134ed6d239a7962a2b7470d8c46611b9d17ef':
  Disabled no post-ops path in lpgemm f32 kernels for few gcc versions
  DTL Log update
  Add external PR integration process and flowchart to CONTRIBUTING.md
  Enabled disable-sba-pools feature in AOCL-BLAS (#101)
  Fix for F32 to BF16 Conversion and AVX512 ISA Support Checks
  Fixed Integer Overflow Issue in TPSV
  Add AI Code Review workflow (#211)
  Add AI Code Review Self-enablement file (#209)
  Re-tuned GEMV thresholds (#210)
  Adding bli_print_msg before bli_abort() for bli_thrinfo_sup_create_for_cntl
  Add missing license text
  Modified AVPY kernel to ensure consistency of numerical results (#188)
  Fix memory leak in DGEMV kernel (#187)
  Tuned DGEMV no-transpose thresholds #193
  Set Security flags default enable (#194)
  Standardize Zen kernel names (2)
  Compiler warnings fixes (2)
  coverity issue fix for ztrsm (#176)
  Fixes Coverity static analysis issue in the DTRSM (#181)
  Add files via upload (#197)
  Initialize mem_t structures safely and handle NULL communicator in threading
  Tidying code
  Compiler warnings fixes
  Fixing the coverity issues with CID: 23269 and CID: 137049 (#180)
  Fixed high priority coverity issues in LPGEMM. (#178)
  GCC 15 SUP kernel workaround (2)
  Disable small_gemm for zen4/5 and added single thread check for tiny path (#167)
  Optimal rerouting of GEMV inputs to avoid packing
  Updated Guards in s8s8s32of32_sym_quant Framework
  Fixed out-of-bound access in F32 matrix add/mul ops (#168)
2025-09-22 13:20:13 +01:00

260 lines
12 KiB
Python

#!/usr/bin/env python3
#
# BLIS
# An object-based framework for developing high-performance BLAS-like
# libraries.
#
# Copyright (C) 2021 - 2025, Advanced Micro Devices, Inc. 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.
# - Neither the name(s) of the copyright holder(s) 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.
#
#
################################################################################
# This file is used to mirroring the refkernels folder data into to zen, zen2, #
# zen3, zen4 and generic folder. #
# Rename all .c files by adding zen, zen2, zen3, zen4 and generic for the #
# corresponding folder .c files and update the corresponding CMakeLists.txt #
# file for amdzen (dynamic dispatcher) config option. #
# #
# Usage: #
# python blis_ref_kernel_mirror.py <project build directory name> #
# #
# Author: Chandrashekara K R <chandrkr@amd.com> #
# #
################################################################################
import os
import shutil
import subprocess
import sys
def create_folder(path):
""" Function to create the folder in an given path.
Args:
path:- Folder path to create.
"""
try:
os.makedirs(path)
except FileExistsError:
pass
def remove_folder(path):
""" Function to delete folder in a given path.
Args:
path:- Folder path to delete.
"""
try:
shutil.rmtree(path)
except FileNotFoundError:
pass
def execute_and_check(cmd):
""" Function to run power shell command in windows and bash command
in linux.
Arg:
cmd:- Power shell/ bash command.
Return:
Returns command output on success and terminates the execution
on failure.
"""
print('********************************************************')
print('Started execution of {} command...\n'.format(cmd))
print('********************************************************')
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, err = proc.communicate()
if not proc.returncode:
print('********************************************************')
print('Execution of command : {} - was successful'.format(cmd))
print('command {} output: {}'.format(cmd,
output.decode('ASCII')))
print('********************************************************')
return output.decode('ASCII')
else:
print('########################################################')
print('Execution of command : {} - was failed'.format(cmd))
print('command {} output: {}\n{}\n'.format(cmd, output.decode(
'ASCII'), err.decode('ASCII')))
exit(1)
def remove_lines_in_file(filename):
with open(filename, 'r') as fd:
file_content = fd.read()
file_content = file_content.replace(
'if(${TARGET_ARCH} STREQUAL amdzen)\n'
'add_subdirectory(${CMAKE_BINARY_DIR}/ref_kernels/generic '
'${CMAKE_BINARY_DIR}/ref_kernels/generic)\n'
'add_subdirectory(${CMAKE_BINARY_DIR}/ref_kernels/zen '
'${CMAKE_BINARY_DIR}/ref_kernels/zen)\n'
'add_subdirectory(${CMAKE_BINARY_DIR}/ref_kernels/zen2 '
'${CMAKE_BINARY_DIR}/ref_kernels/zen2)\n'
'add_subdirectory(${CMAKE_BINARY_DIR}/ref_kernels/zen3 '
'${CMAKE_BINARY_DIR}/ref_kernels/zen3)\n'
'add_subdirectory(${CMAKE_BINARY_DIR}/ref_kernels/zen4 '
'${CMAKE_BINARY_DIR}/ref_kernels/zen4)\nelse()', '\n')
data = file_content.replace('endif()', '\n')
with open(filename, 'w') as fd:
fd.write(data + '\n')
def write_to_file(filename, data):
with open(filename, 'r') as fd:
file_content = fd.read()
file_content = file_content.split('#include "blis.h"')
data = '\n'.join([file_content[0], '#include "blis.h"', data] +
file_content[1:])
with open(filename, 'w') as fd:
fd.write(data + '\n')
def update_cmakelists_contents(cmakefiles, replacement_str):
for cmakefile in cmakefiles:
if os.path.exists(cmakefile):
# Updating the modified .c files name in CMakeLists.txt
with open(cmakefile, 'r') as fd:
file_content = fd.read()
file_content = file_content.replace(
'ref.c', replacement_str + '_ref.c')
with open(cmakefile, 'w') as fd:
fd.write(file_content)
def add_macro_to_cfiles(cfiles, macro):
for cfile in cfiles:
if os.path.exists(cfile):
write_to_file(cfile, macro)
# Renaming the .c files name to incorporate with linux
os.rename(cfile, cfile.split('ref.c')[0] + macro.split(' ')[
-1].split('\n')[0][1:] + '_ref.c')
if __name__ == '__main__':
cwd = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
source_path = os.path.join(cwd, 'ref_kernels')
build_path = sys.argv[1].replace('/', '\\')
dest_path = os.path.join(build_path, 'ref_kernels')
if os.path.exists(dest_path):
remove_folder(dest_path)
# Creating all the required folders
temp = os.path.join(cwd, 'temp')
create_folder(temp)
execute_and_check('XCOPY {} {} /E'.format(source_path, temp))
create_folder(os.path.join(dest_path, 'zen'))
create_folder(os.path.join(dest_path, 'zen2'))
create_folder(os.path.join(dest_path, 'zen3'))
create_folder(os.path.join(dest_path, 'zen4'))
create_folder(os.path.join(dest_path, 'generic'))
# Mirroring refkernels folder data to zen, zen2, zen3, zen4 and generic folder
execute_and_check('XCOPY {} {} /E'.format(
temp, os.path.join(dest_path, 'zen')))
execute_and_check('XCOPY {} {} /E'.format(
temp, os.path.join(dest_path, 'zen2')))
execute_and_check('XCOPY {} {} /E'.format(
temp, os.path.join(dest_path, 'zen3')))
execute_and_check('XCOPY {} {} /E'.format(
temp, os.path.join(dest_path, 'zen4')))
execute_and_check('XCOPY {} {} /E'.format(
temp, os.path.join(dest_path, 'generic')))
remove_folder(temp)
remove_lines_in_file(os.path.join(
dest_path, 'generic', 'CMakeLists.txt'))
remove_lines_in_file(os.path.join(
dest_path, 'zen', 'CMakeLists.txt'))
remove_lines_in_file(os.path.join(
dest_path, 'zen2', 'CMakeLists.txt'))
remove_lines_in_file(os.path.join(
dest_path, 'zen3', 'CMakeLists.txt'))
remove_lines_in_file(os.path.join(
dest_path, 'zen4', 'CMakeLists.txt'))
cfiles_in_generic = execute_and_check('cd {} && dir / s / b / o: gn *.c'
.format(os.path.join(dest_path,
'generic')))
cfiles_in_generic = cfiles_in_generic.split('\r\n')
add_macro_to_cfiles(cfiles_in_generic,
'\n#define BLIS_CNAME_INFIX _generic\n')
# Listing all CMakelists.txt file from generic folder and updating them.
cmake_files_in_generic = execute_and_check(
'cd {} && dir / s / b / o: gn CMakeLists.txt'.format(
os.path.join(dest_path, 'generic')))
cmake_files_in_generic = cmake_files_in_generic.split('\r\n')
update_cmakelists_contents(cmake_files_in_generic, 'generic')
cfiles_in_zen = execute_and_check('cd {} && dir / s / b / o: gn *.c'
.format(os.path.join(dest_path, 'zen')))
cfiles_in_zen = cfiles_in_zen.split('\r\n')
add_macro_to_cfiles(cfiles_in_zen,
'\n#define BLIS_CNAME_INFIX _zen\n')
# Listing all CMakelists.txt file from zen folder and updating them.
cmake_files_in_zen = execute_and_check(
'cd {} && dir / s / b / o: gn CMakeLists.txt'.format(
os.path.join(dest_path, 'zen')))
cmake_files_in_zen = cmake_files_in_zen.split('\r\n')
update_cmakelists_contents(cmake_files_in_zen, 'zen')
cfiles_in_zen2 = execute_and_check('cd {} && dir / s / b / o: gn *.c'
.format(os.path.join(dest_path, 'zen2')))
cfiles_in_zen2 = cfiles_in_zen2.split('\r\n')
add_macro_to_cfiles(cfiles_in_zen2,
'\n#define BLIS_CNAME_INFIX _zen2\n')
# Listing all CMakelists.txt file from zen2 folder and updating them.
cmake_files_in_zen2 = execute_and_check(
'cd {} && dir / s / b / o: gn CMakeLists.txt'.format(
os.path.join(dest_path, 'zen2')))
cmake_files_in_zen2 = cmake_files_in_zen2.split('\r\n')
update_cmakelists_contents(cmake_files_in_zen2, 'zen2')
cfiles_in_zen3 = execute_and_check('cd {} && dir / s / b / o: gn *.c'
.format(os.path.join(dest_path, 'zen3')))
cfiles_in_zen3 = cfiles_in_zen3.split('\r\n')
add_macro_to_cfiles(cfiles_in_zen3,
'\n#define BLIS_CNAME_INFIX _zen3\n')
# Listing all CMakelists.txt file from zen3 folder and updating them.
cmake_files_in_zen3 = execute_and_check(
'cd {} && dir / s / b / o: gn CMakeLists.txt'.format(
os.path.join(dest_path, 'zen3')))
cmake_files_in_zen3 = cmake_files_in_zen3.split('\r\n')
update_cmakelists_contents(cmake_files_in_zen3, 'zen3')
cfiles_in_zen4 = execute_and_check('cd {} && dir / s / b / o: gn *.c'
.format(os.path.join(dest_path, 'zen4')))
cfiles_in_zen4 = cfiles_in_zen4.split('\r\n')
add_macro_to_cfiles(cfiles_in_zen4,
'\n#define BLIS_CNAME_INFIX _zen4\n')
# Listing all CMakelists.txt file from zen4 folder and updating them.
cmake_files_in_zen4 = execute_and_check(
'cd {} && dir / s / b / o: gn CMakeLists.txt'.format(
os.path.join(dest_path, 'zen4')))
cmake_files_in_zen4 = cmake_files_in_zen4.split('\r\n')
update_cmakelists_contents(cmake_files_in_zen4, 'zen4')