From a5ac9e7f1af2fd1572644b865b8c9bacfdb154fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Sok=C3=B3=C5=82?= Date: Mon, 22 Jul 2024 17:59:51 +0200 Subject: [PATCH] BLD: Generate config.h file --- driver/level2/meson.build | 2 +- driver/level3/meson.build | 2 +- driver/others/meson.build | 2 +- getarch_2nd.c | 7 ++++ interface/meson.build | 4 +- join_files.py | 21 +++++++++++ kernel/meson.build | 2 +- lapack-netlib/meson.build | 7 ++-- meson.build | 79 ++++++++++++++++++++++++++------------- 9 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 join_files.py diff --git a/driver/level2/meson.build b/driver/level2/meson.build index 062acdb85..5b7aef856 100644 --- a/driver/level2/meson.build +++ b/driver/level2/meson.build @@ -540,7 +540,7 @@ foreach conf : kernel_confs # message(conf) _kern_libs += [static_library( conf['name'], - conf['src'], + [conf['src'], config_h], include_directories: _inc, c_args: conf['c_args'], )] diff --git a/driver/level3/meson.build b/driver/level3/meson.build index 419a0b847..a4415899d 100644 --- a/driver/level3/meson.build +++ b/driver/level3/meson.build @@ -454,7 +454,7 @@ foreach conf : kernel_confs # message(conf) _kern_libs += [static_library( conf['name'], - conf['src'], + [conf['src'], config_h], include_directories: _inc, c_args: conf['c_args'], )] diff --git a/driver/others/meson.build b/driver/others/meson.build index a04a36988..954bdf708 100644 --- a/driver/others/meson.build +++ b/driver/others/meson.build @@ -75,7 +75,7 @@ others_libs = [] foreach conf : others_confs others_libs += [static_library( conf['name'], - conf['src'], + [conf['src'], config_h], include_directories: _inc, c_args: conf['c_args'] )] diff --git a/getarch_2nd.c b/getarch_2nd.c index dd1f83089..038434d4a 100644 --- a/getarch_2nd.c +++ b/getarch_2nd.c @@ -1,9 +1,16 @@ #include #ifndef BUILD_KERNEL + +#ifdef BUILD_WITH_MESON +#include "_config_for_getarch_2nd.h" +#else #include "config.h" +#endif + #else #include "config_kernel.h" #endif + #if (defined(__WIN32__) || defined(__WIN64__) || defined(__CYGWIN32__) || defined(__CYGWIN64__) || defined(_WIN32) || defined(_WIN64)) && defined(__64BIT__) typedef long long BLASLONG; typedef unsigned long long BLASULONG; diff --git a/interface/meson.build b/interface/meson.build index 866ab1e16..c37818de7 100644 --- a/interface/meson.build +++ b/interface/meson.build @@ -621,7 +621,7 @@ foreach conf : _blas_roots # Create the static library for each symbol lib = static_library( sym_name, - sources: conf['fname'], + sources: [conf['fname'], config_h], include_directories: _inc, c_args: compiler_args + [ f'-DASMNAME=@sym_name@', @@ -643,7 +643,7 @@ foreach conf : _blas_roots endif cblas_lib = static_library( cblas_sym_name, - sources: conf['fname'], + sources: [conf['fname'], config_h], include_directories: _inc, c_args: compiler_args + [ '-DCBLAS', diff --git a/join_files.py b/join_files.py new file mode 100644 index 000000000..8e9d21ddb --- /dev/null +++ b/join_files.py @@ -0,0 +1,21 @@ +import argparse + + +def merge_files(file1_path: str, file2_path: str) -> str: + # Open files in read mode + with open(file1_path, 'r') as file1, open(file2_path, 'r') as file2: + content1 = file1.read() + content2 = file2.read() + merged_content = content1 + "\n" + content2 + return merged_content + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Merge and print content from two text files.") + parser.add_argument("file1", help="Path to the first text file.") + parser.add_argument("file2", help="Path to the second text file.") + + args = parser.parse_args() + + output = merge_files(args.file1, args.file2) + print(output) diff --git a/kernel/meson.build b/kernel/meson.build index e93f63cad..2b465d6cb 100644 --- a/kernel/meson.build +++ b/kernel/meson.build @@ -1274,7 +1274,7 @@ _is_asm = false foreach conf: kernel_confs _kern_libs += static_library( conf['name'], - conf['src'], + [conf['src'], config_h], include_directories: _inc, c_args: conf['c_args'], # See gh discussion 13374 for why, basically .S are coded as fortran.. diff --git a/lapack-netlib/meson.build b/lapack-netlib/meson.build index cc34ee6d0..28472cca8 100644 --- a/lapack-netlib/meson.build +++ b/lapack-netlib/meson.build @@ -1,8 +1,9 @@ add_languages('fortran', native: false) ff = meson.get_compiler('fortran') -if ff.has_argument('-Wno-conversion') - add_project_arguments('-Wno-conversion', language: 'fortran') -endif +# TODO(mtsokol): make it a local setting +# if ff.has_argument('-Wno-conversion') +# add_project_arguments('-Wno-conversion', language: 'fortran') +# endif lapack_major_version = 3 # soversion lapack_minor_version = 12 diff --git a/meson.build b/meson.build index 91b22bd94..4efab7e43 100644 --- a/meson.build +++ b/meson.build @@ -11,7 +11,7 @@ # # NOTE: This is still a work in progress, the Makefiles are canonical project('OpenBLAS', ['c', 'fortran'], - default_options: ['c_std=c99', 'pkg.relocatable=true'], + default_options: ['c_std=c99', 'pkgconfig.relocatable=true'], version: '0.3.26.dev') openblas_major_version = 0 # soversion @@ -22,6 +22,7 @@ openblas_version = f'@openblas_major_version@.@openblas_minor_version@.@openblas # Skip the check for valid CC cc = meson.get_compiler('c') fc = meson.get_compiler('fortran') +cc_id = cc.get_id() fc_id = fc.get_id() # Common args @@ -67,18 +68,6 @@ else no_affinity = false endif -# Makefile.prebuild stuff -# TODO: Handle cpuidemu, and the target flags -# getarch = executable('getarch', -# ['getarch.c', 'cpuid.S']) -# getarch_two = executable('getarch_2nd', -# ['getarch_2nd.c']) -# config_h = custom_target('gen_config_h', -# # input: ['getarch.c'], -# output: ['config.h'], -# command: [getarch, '3'] -# ) - _check_prefix = [] conf_data = configuration_data() is_win = host_machine.system() == 'windows' or host_machine.system() == 'cygwin' @@ -115,18 +104,6 @@ endforeach configure_file(output : 'getarch_conf.h', configuration : conf_data) -# run_target('generate_config_h', -# command: [meson.current_build_dir() + '/getarch', '1'], -# depends: getarch) - -# gch = run_command(meson.current_build_dir() + '/getarch', '1') -# outp = gch.stdout().strip() - -# conf_data = configuration_data() -# configure_file(input : meson.current_build_dir() + '/config.h', -# output : 'config.h', -# configuration : conf_data) - # Makefile.system cpu_fam = target_machine.cpu_family() @@ -437,6 +414,58 @@ symb_defs = { 'cblas_?dotc_sub': {'def': ['CBLAS', 'FORCE_USE_STACK', 'CONJ']}, } +# config.h file generation + +_config_1_path = meson.current_build_dir() / '_config_1.h' +_join_files_py = '../join_files.py' +run_command('./c_check', 'Makefile.conf', _config_1_path, cc_id, check: true) +run_command('./f_check', 'Makefile.conf', _config_1_path, fc_id, check: true) + +getarch = executable('getarch', ['getarch.c', 'cpuid.S']) + +_config_2h = custom_target('_config_2h', + output: '_config_2.h', + command: [getarch, '1'], + depends: [getarch], + capture: true, + ) + +_config_for_getarch_2nd_h = custom_target('_config_for_getarch_2nd_h', + output: '_config_for_getarch_2nd.h', + command: [ + find_program('python'), + _join_files_py, + _config_1_path, + _config_2h, + ], + depends: [_config_2h], + capture: true, + ) + +getarch_2nd = executable('getarch_2nd', + ['getarch_2nd.c', _config_for_getarch_2nd_h], + c_args: ['-DGEMM_MULTITHREAD_THRESHOLD=4', '-DBUILD_WITH_MESON'] + ) + +_config_3h = custom_target('_config_3h', + output: '_config_3.h', + command: [getarch_2nd, '1'], + depends: [getarch_2nd], + capture: true, + ) + +config_h = custom_target('config_h', + output: 'config.h', + command: [ + find_program('python'), + _join_files_py, + _config_for_getarch_2nd_h, + _config_3h, + ], + depends: [_config_3h], + capture: true, + ) + # Ignoring other hostarch checks and conflicts for arch in BSD for now _inc = [include_directories('.')] subdir('lapack-netlib')