ENH,BLD: Finalize interface meson.build

This commit is contained in:
Rohit Goswami 2024-04-18 01:09:01 +00:00 committed by Mateusz Sokół
parent 998602062a
commit ea55287038
2 changed files with 74 additions and 92 deletions

View File

@ -1,29 +1,3 @@
_kinds = []
real_kinds = ['s', 'd']
if get_option('exprecision')
real_kinds += 'q'
endif
complex_kinds = ['c', 'z', 'x']
extended_kinds = ['dx', 'bf16']
blas_roots = []
blas1_roots = [
# These don't exist as roots.
# ismax amax isamax amin ismin isamin
# TODO: Why is dsdot in sblas1objs!?
'axpy', 'swap', 'copy', 'scal', 'dot', 'dsdot', 'asum', 'sum', 'nrm2', 'max',
'rot'#, 'rotg', 'rotm', 'rotmg', 'axpby',
]
blas2_roots = [
'gemv', 'ger', 'trsv', 'trmv', 'symv', 'syr', 'syr2', 'gbmv', 'sbmv',
'spmv', 'spr', 'spr2', 'tbsv', 'tbmv', 'tpsv', 'tpmv',
]
blas3_roots = [
# TODO: trmm is trsm with a flag
'gemm', 'symm', 'trsm', 'syrk', 'syr2k', 'omatcopy', 'imatcopy', 'geadd',
'gemmt'
]
_blas_roots = [
# NOTE: q, qx, x, xq do not have cblas_ rules in the Makefile
# NOTE: https://developer.arm.com/documentation/101004/2310/BLAS-Basic-Linear-Algebra-Subprograms/CBLAS-functions?lang=en
@ -377,72 +351,72 @@ _blas_roots = [
},
]
# addl_srcs = {
# 'symm': '-DHEMM'
# }
# Generated
# NOTE: Remember to check sourcesets as a simpler mechanism
# TODO: Generated the imax and max via use_abs use_min
interface_confs = []
blas_roots += blas1_roots
blas_roots += blas2_roots
blas_roots += blas3_roots
_kinds += real_kinds
foreach root : blas1_roots
fname = root + '.c'
defs = []
# if root in addl_srcs
# defs += addl_srcs[root]
# endif
foreach prec : real_kinds
_defs = []
name = prec + fname
if prec == 'd'
_defs += ['-UCOMPLEX', '-DDOUBLE']
elif prec == 's'
_defs += ['-UCOMPLEX', '-UDOUBLE']
elif prec == 'cs'
_defs += ['-DCOMPLEX', '-UDOUBLE']
_interface_libs = []
foreach conf : _blas_roots
foreach type : conf['_types']
# Seed with common args
compiler_args = [_cargs]
# Set the type arguments
if precision_mappings.get(type).has_key('def')
foreach d : precision_mappings[type]['def']
compiler_args += ['-D' + d]
endforeach
endif
interface_confs += {'defs': _defs,
'name': prec + root,
'src': fname}
interface_confs += {'defs': _defs + '-DCBLAS',
'name': 'cblas_' + prec + root,
'src': fname}
if precision_mappings.get(type).has_key('undef')
foreach u : precision_mappings[type]['undef']
compiler_args += ['-U' + u]
endforeach
endif
# Construct the actual symbol names
sym_name = conf['base'].replace('?', type)
if conf.get('cblas', false)
cblas_sym_name = 'cblas_' + sym_name
endif
# Construct conditionals
if conf.has_key('def')
foreach d : conf['def']
compiler_args += ['-D' + d]
endforeach
message(interface_confs)
foreach u : conf['undef']
compiler_args += ['-U' + u]
endforeach
endif
# if get_option('bfloat16')
# TODO: Handle bfloat16
# sblas1_srcs += files('sbdot.c')
# sblas2_srcs += files('sbgemv.c')
# sblas3_srcs += files(['sbgemm.c', 'sbgemmt.c'])
# endif
_static_libs = []
foreach conf: interface_confs
sym_name = conf['name']
# Make mangled symbols
# TODO: This might be conditional on other options
sym_underscored = f'@sym_name@_'
_static_libs += static_library(
sym_name,
conf['src'],
include_directories: _inc,
c_args: [
conf['defs'],
_cargs,
compiler_args += [
f'-DASMNAME=@sym_name@',
f'-DASMFNAME=@sym_underscored@',
f'-DNAME=@sym_underscored@',
f'-DCNAME=@sym_name@',
f'-DCHAR_NAME="@sym_underscored@"',
f'-DCHAR_CNAME="@sym_name@"',
],
f'-DCHAR_CNAME="@sym_name@"'
]
# Create the static library for each symbol
lib = static_library(
sym_name,
sources: conf['fname'],
include_directories: _inc,
c_args: compiler_args
)
_interface_libs += lib
# If it's a CBLAS symbol, also create that
if conf.get('cblas', false)
cblas_lib = static_library(
cblas_sym_name,
sources: conf['fname'],
include_directories: _inc,
c_args: compiler_args + ['-DCBLAS']
)
_interface_libs += cblas_lib
endif
endforeach
endforeach
_interface = static_library('_interface',
c_args: _cargs,
link_whole: _static_libs)
# Create a combined static library linking all individual static libraries
_interface = static_library('_interface', link_whole: _interface_libs)

View File

@ -256,14 +256,22 @@ endif
# Also see:
# L1: https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-1/blas-level-1-routines-and-functions.html
precision_mappings = {
's': {'undef': ['COMPLEX', 'DOUBLE'], 'def': []},
's': {'undef': ['COMPLEX', 'DOUBLE']},
'd': {'undef': ['COMPLEX'], 'def': ['DOUBLE']},
'q': {'undef': ['COMPLEX'], 'def': ['XDOUBLE']},
'c': {'undef': ['DOUBLE'], 'def': ['COMPLEX']},
'z': {'undef': [], 'def': ['COMPLEX', 'DOUBLE']},
'x': {'undef': [], 'def': ['COMPLEX', 'XDOUBLE']},
'z': {'def': ['COMPLEX', 'DOUBLE']},
'x': {'def': ['COMPLEX', 'XDOUBLE']},
'cs': {'undef': ['DOUBLE'], 'def': ['COMPLEX']},
# zd is the same as z
'sc': {'undef': ['DOUBLE'], 'def': ['COMPLEX']},
'dz': {'def': ['COMPLEX', 'DOUBLE']},
'zd': {'def': ['COMPLEX', 'DOUBLE']},
'qx': {'def': ['COMPLEX', 'DOUBLE']},
'xq': {'def': ['COMPLEX', 'DOUBLE']},
'': {}, # special case, for cblas_?dot*_sub
# xq / qx == x
# sc / cs == c
# zd / dz is the same as z
# 'zd': {'undef': [], 'def': ['COMPLEX', 'DOUBLE']},
}
@ -271,7 +279,7 @@ precision_mappings = {
_inc = include_directories('.')
# subdir('lapack-netlib')
subdir('interface')
subdir('kernel')
# subdir('kernel')
_openblas = static_library('openblas',
link_whole: [ _interface, _kern])
# _openblas = static_library('openblas',
# link_whole: [ _interface, _kern])