[PATCH] lib/meson: refactor GPGPU assembly build process
Hajda, Andrzej
andrzej.hajda at intel.com
Fri May 30 13:05:44 UTC 2025
W dniu 30.05.2025 o 13:10, Kamil Konieczny pisze:
> Hi Andrzej,
> On 2025-05-29 at 14:32:23 +0200, Andrzej Hajda wrote:
>> GPGPU inline assembly was build into one big code file
>> inside libigt library. This approach has few drawbacks:
> Add newline here.
>
>> 1. Only files from the library can contain assembly.
>> 2. Change of one assembly chunk results in re-build of
>> all chunks.
>> 3. Most shaders lands in lib/gpgpu_shader.c.
> Add newline.
>
>> With this change assembly codes are generated and stored
>> in files relative to files containing asms. For example
>> lib/gpgpu_shader.c will have codes in
>> lib/gpgpu_shader.c.gen.iga64_codes.c.
> Remove last dot from filename, add newline.
>
>> It will allow to move asms specific for particular test
>> into the test files, instead of putting them to lib/gpgpu_shader.c.
> What about a little more explanation here, like:
>
> It will allow to move asms specific for particular test
> into the test files, instead of putting all of them into
> lib/gpgpu_shader.c. In result, GPGPU fill assemblies will
> be sparated into new one.
>
> Up to you.
>
>> Signed-off-by: Andrzej Hajda <andrzej.hajda at intel.com>
> Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
Thx, adjusted and pushed.
Regards
Andrzej
>
>> ---
>> This is just upstreamed version of internal patch.
>> ---
>> lib/gpgpu_fill.c.gen.iga64_codes.c | 80 ++++++++++++++++++++++
>> ...ed_codes.c => gpgpu_shader.c.gen.iga64_codes.c} | 76 +-------------------
>> lib/meson.build | 40 ++++++-----
>> scripts/generate_iga64_codes | 14 ++--
>> 4 files changed, 112 insertions(+), 98 deletions(-)
>>
>> diff --git a/lib/gpgpu_fill.c.gen.iga64_codes.c b/lib/gpgpu_fill.c.gen.iga64_codes.c
>> new file mode 100644
>> index 000000000000..b223425d049a
>> --- /dev/null
>> +++ b/lib/gpgpu_fill.c.gen.iga64_codes.c
>> @@ -0,0 +1,80 @@
>> +// SPDX-License-Identifier: MIT
>> +// Generated using Intel Graphics Assembler 1.1.0-int
>> +
>> +#include "gpgpu_shader.h"
>> +
>> +#define MD5_SUM_IGA64_ASMS 8304c8bb11385470bfd6ac32e1c36840
>> +
>> +struct iga64_template const iga64_code_gpgpu_fill[] = {
>> + { .gen_ver = 2000, .size = 44, .code = (const uint32_t []) {
>> + 0x00080061, 0x01050000, 0x00000104, 0x00000000,
>> + 0x00000069, 0x02058220, 0x02000014, 0x00000004,
>> + 0x00000061, 0x02150220, 0x00000064, 0x00000000,
>> + 0x000c0061, 0x04054220, 0x00000000, 0x00000000,
>> + 0x00101c61, 0x05050220, 0x00000104, 0x00000000,
>> + 0x00041b61, 0x04550220, 0x00220205, 0x00000000,
>> + 0x00000061, 0x04754550, 0x00000000, 0x000f000f,
>> + 0x00132031, 0x00000000, 0xd00e0494, 0x04000000,
>> + 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> + 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> + 0x80000901, 0x00010000, 0x00000000, 0x00000000,
>> + }},
>> + { .gen_ver = 1270, .size = 52, .code = (const uint32_t []) {
>> + 0x00020061, 0x01050000, 0x00000104, 0x00000000,
>> + 0x00000069, 0x02058220, 0x02000024, 0x00000004,
>> + 0x00000061, 0x02250220, 0x000000c4, 0x00000000,
>> + 0x00030061, 0x04054220, 0x00000000, 0x00000000,
>> + 0x00041c61, 0x05050220, 0x00000104, 0x00000000,
>> + 0x00011b61, 0x04050220, 0x00220205, 0x00000000,
>> + 0x00000061, 0x04454220, 0x00000000, 0x0000000f,
>> + 0x00000061, 0x04850220, 0x000000a4, 0x00000000,
>> + 0x80001901, 0x00010000, 0x00000000, 0x00000000,
>> + 0x00044031, 0x00000000, 0xc0000414, 0x02a00000,
>> + 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> + 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> + 0x80000901, 0x00010000, 0x00000000, 0x00000000,
>> + }},
>> + { .gen_ver = 1260, .size = 48, .code = (const uint32_t []) {
>> + 0x00080061, 0x01050000, 0x00000104, 0x00000000,
>> + 0x00000069, 0x02058220, 0x02000014, 0x00000004,
>> + 0x00000061, 0x02150220, 0x00000064, 0x00000000,
>> + 0x000c0061, 0x04054220, 0x00000000, 0x00000000,
>> + 0x00101c61, 0x05050220, 0x00000104, 0x00000000,
>> + 0x00041b61, 0x04050220, 0x00220205, 0x00000000,
>> + 0x00000061, 0x04254220, 0x00000000, 0x0000000f,
>> + 0x00000061, 0x04450220, 0x00000054, 0x00000000,
>> + 0x00132031, 0x00000000, 0xc0000414, 0x02a00000,
>> + 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> + 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> + 0x80000901, 0x00010000, 0x00000000, 0x00000000,
>> + }},
>> + { .gen_ver = 1250, .size = 52, .code = (const uint32_t []) {
>> + 0x00020061, 0x01050000, 0x00000104, 0x00000000,
>> + 0x00000069, 0x02058220, 0x02000024, 0x00000004,
>> + 0x00000061, 0x02250220, 0x000000c4, 0x00000000,
>> + 0x00030061, 0x04054220, 0x00000000, 0x00000000,
>> + 0x00041c61, 0x05050220, 0x00000104, 0x00000000,
>> + 0x00011b61, 0x04050220, 0x00220205, 0x00000000,
>> + 0x00000061, 0x04454220, 0x00000000, 0x0000000f,
>> + 0x00000061, 0x04850220, 0x000000a4, 0x00000000,
>> + 0x80001901, 0x00010000, 0x00000000, 0x00000000,
>> + 0x00044031, 0x00000000, 0xc0000414, 0x02a00000,
>> + 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> + 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> + 0x80000901, 0x00010000, 0x00000000, 0x00000000,
>> + }},
>> + { .gen_ver = 0, .size = 48, .code = (const uint32_t []) {
>> + 0x00020061, 0x01050000, 0x00000104, 0x00000000,
>> + 0x00000069, 0x02058220, 0x02000024, 0x00000004,
>> + 0x00000061, 0x02250220, 0x000000c4, 0x00000000,
>> + 0x00030061, 0x04054220, 0x00000000, 0x00000000,
>> + 0x00040461, 0x05050220, 0x00000104, 0x00000000,
>> + 0x00010361, 0x04050220, 0x00220205, 0x00000000,
>> + 0x00000061, 0x04454220, 0x00000000, 0x0000000f,
>> + 0x00000061, 0x04850220, 0x000000a4, 0x00000000,
>> + 0x00049031, 0x00000000, 0xc0000414, 0x02a00000,
>> + 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> + 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> + 0x80000101, 0x00010000, 0x00000000, 0x00000000,
>> + }}
>> +};
>> diff --git a/lib/iga64_generated_codes.c b/lib/gpgpu_shader.c.gen.iga64_codes.c
>> similarity index 89%
>> rename from lib/iga64_generated_codes.c
>> rename to lib/gpgpu_shader.c.gen.iga64_codes.c
>> index 551dead2be17..fffe242fe138 100644
>> --- a/lib/iga64_generated_codes.c
>> +++ b/lib/gpgpu_shader.c.gen.iga64_codes.c
>> @@ -3,81 +3,7 @@
>>
>> #include "gpgpu_shader.h"
>>
>> -#define MD5_SUM_IGA64_ASMS 22a5a4671242c3257209f4051f1c0c7e
>> -
>> -struct iga64_template const iga64_code_gpgpu_fill[] = {
>> - { .gen_ver = 2000, .size = 44, .code = (const uint32_t []) {
>> - 0x00080061, 0x01050000, 0x00000104, 0x00000000,
>> - 0x00000069, 0x02058220, 0x02000014, 0x00000004,
>> - 0x00000061, 0x02150220, 0x00000064, 0x00000000,
>> - 0x000c0061, 0x04054220, 0x00000000, 0x00000000,
>> - 0x00101c61, 0x05050220, 0x00000104, 0x00000000,
>> - 0x00041b61, 0x04550220, 0x00220205, 0x00000000,
>> - 0x00000061, 0x04754550, 0x00000000, 0x000f000f,
>> - 0x00132031, 0x00000000, 0xd00e0494, 0x04000000,
>> - 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> - 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> - 0x80000901, 0x00010000, 0x00000000, 0x00000000,
>> - }},
>> - { .gen_ver = 1270, .size = 52, .code = (const uint32_t []) {
>> - 0x00020061, 0x01050000, 0x00000104, 0x00000000,
>> - 0x00000069, 0x02058220, 0x02000024, 0x00000004,
>> - 0x00000061, 0x02250220, 0x000000c4, 0x00000000,
>> - 0x00030061, 0x04054220, 0x00000000, 0x00000000,
>> - 0x00041c61, 0x05050220, 0x00000104, 0x00000000,
>> - 0x00011b61, 0x04050220, 0x00220205, 0x00000000,
>> - 0x00000061, 0x04454220, 0x00000000, 0x0000000f,
>> - 0x00000061, 0x04850220, 0x000000a4, 0x00000000,
>> - 0x80001901, 0x00010000, 0x00000000, 0x00000000,
>> - 0x00044031, 0x00000000, 0xc0000414, 0x02a00000,
>> - 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> - 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> - 0x80000901, 0x00010000, 0x00000000, 0x00000000,
>> - }},
>> - { .gen_ver = 1260, .size = 48, .code = (const uint32_t []) {
>> - 0x00080061, 0x01050000, 0x00000104, 0x00000000,
>> - 0x00000069, 0x02058220, 0x02000014, 0x00000004,
>> - 0x00000061, 0x02150220, 0x00000064, 0x00000000,
>> - 0x000c0061, 0x04054220, 0x00000000, 0x00000000,
>> - 0x00101c61, 0x05050220, 0x00000104, 0x00000000,
>> - 0x00041b61, 0x04050220, 0x00220205, 0x00000000,
>> - 0x00000061, 0x04254220, 0x00000000, 0x0000000f,
>> - 0x00000061, 0x04450220, 0x00000054, 0x00000000,
>> - 0x00132031, 0x00000000, 0xc0000414, 0x02a00000,
>> - 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> - 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> - 0x80000901, 0x00010000, 0x00000000, 0x00000000,
>> - }},
>> - { .gen_ver = 1250, .size = 52, .code = (const uint32_t []) {
>> - 0x00020061, 0x01050000, 0x00000104, 0x00000000,
>> - 0x00000069, 0x02058220, 0x02000024, 0x00000004,
>> - 0x00000061, 0x02250220, 0x000000c4, 0x00000000,
>> - 0x00030061, 0x04054220, 0x00000000, 0x00000000,
>> - 0x00041c61, 0x05050220, 0x00000104, 0x00000000,
>> - 0x00011b61, 0x04050220, 0x00220205, 0x00000000,
>> - 0x00000061, 0x04454220, 0x00000000, 0x0000000f,
>> - 0x00000061, 0x04850220, 0x000000a4, 0x00000000,
>> - 0x80001901, 0x00010000, 0x00000000, 0x00000000,
>> - 0x00044031, 0x00000000, 0xc0000414, 0x02a00000,
>> - 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> - 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> - 0x80000901, 0x00010000, 0x00000000, 0x00000000,
>> - }},
>> - { .gen_ver = 0, .size = 48, .code = (const uint32_t []) {
>> - 0x00020061, 0x01050000, 0x00000104, 0x00000000,
>> - 0x00000069, 0x02058220, 0x02000024, 0x00000004,
>> - 0x00000061, 0x02250220, 0x000000c4, 0x00000000,
>> - 0x00030061, 0x04054220, 0x00000000, 0x00000000,
>> - 0x00040461, 0x05050220, 0x00000104, 0x00000000,
>> - 0x00010361, 0x04050220, 0x00220205, 0x00000000,
>> - 0x00000061, 0x04454220, 0x00000000, 0x0000000f,
>> - 0x00000061, 0x04850220, 0x000000a4, 0x00000000,
>> - 0x00049031, 0x00000000, 0xc0000414, 0x02a00000,
>> - 0x80000001, 0x00010000, 0x20000000, 0x00000000,
>> - 0x80000001, 0x00010000, 0x30000000, 0x00000000,
>> - 0x80000101, 0x00010000, 0x00000000, 0x00000000,
>> - }}
>> -};
>> +#define MD5_SUM_IGA64_ASMS f5d2183439f5e7b18097c3c2c2957dbb
>>
>> struct iga64_template const iga64_code_read_a64_d32[] = {
>> { .gen_ver = 2000, .size = 40, .code = (const uint32_t []) {
>> diff --git a/lib/meson.build b/lib/meson.build
>> index f5419805177f..c903aaa14bc9 100644
>> --- a/lib/meson.build
>> +++ b/lib/meson.build
>> @@ -236,9 +236,30 @@ lib_version = vcs_tag(input : 'version.h.in', output : 'version.h',
>> command : vcs_command )
>>
>> iga64_assembly_sources = [ 'gpgpu_shader.c', 'gpgpu_fill.c' ]
>> +libiga64_asms = static_library('iga64_asms',
>> + iga64_assembly_sources,
>> + include_directories: inc,
>> + dependencies : lib_deps,
>> + c_args : [
>> + '-DIGT_DATADIR="@0@"'.format(join_paths(prefix, datadir)),
>> + '-DIGT_SRCDIR="@0@"'.format(srcdir),
>> + '-DIGT_LOG_DOMAIN="gpu_codes"',
>> + '-ffat-lto-objects' ]
>> +)
>> +
>> +iga64_codes_targets = []
>> +foreach f: iga64_assembly_sources
>> + name = f.underscorify() + '.gen.iga64_codes.c'
>> + iga64_codes_targets += custom_target(name,
>> + input: [ f + '.gen.iga64_codes.c', libiga64_asms.extract_objects(f) ],
>> + output: name,
>> + depend_files: [ 'iga64_macros.h', generate_iga64_codes.path() ],
>> + command: [ 'env', 'IGT_SRCDIR=@SOURCE_ROOT@', generate_iga64_codes, '-o', '@OUTPUT@', '-i', '@INPUT0@', '@INPUT1@' ],
>> + console: true,
>> + )
>> +endforeach
>>
>> lib_intermediates = []
>> -iga64_assembly_libs = []
>> foreach f: lib_sources
>> name = f.underscorify()
>> lib = static_library('igt-' + name,
>> @@ -249,25 +270,12 @@ foreach f: lib_sources
>> '-DIGT_DATADIR="@0@"'.format(join_paths(prefix, datadir)),
>> '-DIGT_SRCDIR="@0@"'.format(srcdir),
>> '-DIGT_LOG_DOMAIN="@0@"'.format(f.split('.')[0]),
>> - ] + (iga64_assembly_sources.contains(f) ? [ '-ffat-lto-objects' ] : []))
>> + ])
>>
>> lib_intermediates += lib
>> - if iga64_assembly_sources.contains(f)
>> - iga64_assembly_libs += lib
>> - endif
>> endforeach
>>
>> -iga64_generated_codes = custom_target(
>> - 'iga64_generated_codes.c',
>> - input : [ 'iga64_generated_codes.c' ] + iga64_assembly_libs,
>> - output : 'iga64_generated_codes.c',
>> - depend_files : 'iga64_macros.h',
>> - command : [ 'env', 'IGT_SRCDIR=@0@'.format(source_root), generate_iga64_codes, '-o', '@OUTPUT@', '-i', '@INPUT@' ]
>> -)
>> -
>> -lib_intermediates += static_library('igt-iga64_generated_codes.c',
>> - [ iga64_generated_codes, lib_version ]
>> - )
>> +lib_intermediates += static_library('iga64_gpu_codes', iga64_codes_targets)
>>
>> lib_igt_build = shared_library('igt',
>> ['dummy.c'],
>> diff --git a/scripts/generate_iga64_codes b/scripts/generate_iga64_codes
>> index 1675ffe639b3..d196c7a016b7 100755
>> --- a/scripts/generate_iga64_codes
>> +++ b/scripts/generate_iga64_codes
>> @@ -29,17 +29,17 @@ while getopts ':i:o:' opt; do
>> case $opt in
>> i) INPUT=$OPTARG;;
>> o) OUTPUT=$OPTARG;;
>> - ?) die "Usage: $0 -i pre-generated-iga64-file -o generated-iga64-file libs-with-iga64-assembly [...]"
>> + ?) die "Usage: $0 -i pre-generated-iga64-file -o generated-iga64-file obj-with-iga64-assembly [...]"
>> esac
>> done
>> -LIBS=${@:OPTIND}
>> +OBJ=${@:OPTIND}
>>
>> # read all assemblies into ASMS array
>> ASMS=()
>> while read -d $'\0' asm; do
>> test -z "$asm" && continue
>> ASMS+=( "$asm" )
>> -done < <(for f in $LIBS; do objcopy --dump-section .iga64_assembly=/dev/stdout $f.p/*.o /dev/null; done)
>> +done < <(objcopy --dump-section .iga64_assembly=/dev/stdout $OBJ /dev/null)
>>
>> # check if we need to recompile - checksum difference and compiler present
>> MD5_ASMS="$(md5sum <<< "$(< $IGT_SRCDIR/lib/iga64_macros.h) ${ASMS[@]}" | cut -b1-32)"
>> @@ -47,13 +47,13 @@ MD5_PRE="$(grep -Po '(?<=^#define MD5_SUM_IGA64_ASMS )\S{32,32}' $INPUT 2>/dev/n
>>
>> if [ "$MD5_ASMS" = "$MD5_PRE" ]; then
>> echo "iga64 assemblies not changed, reusing pre-compiled file $INPUT."
>> - cp $INPUT $OUTPUT
>> + cp -p $INPUT $OUTPUT
>> exit 0
>> fi
>>
>> type iga64 >/dev/null || {
>> warn "WARNING: iga64 assemblies changed, but iga64 compiler not present, CHANGES will have no effect. Install iga64 (libigc-tools package) to re-compile code."
>> - cp $INPUT $OUTPUT
>> + cp -p $INPUT $OUTPUT
>> exit 0
>> }
>>
>> @@ -67,7 +67,7 @@ for gen in $GEN_VERSIONS; do
>> gen_name="${gen#*:}"
>> iga64 -p=$gen_name -d $WD/empty 2>/dev/null || {
>> warn "WARNING: iga64 assemblies changed, but iga64 compiler does not support platform '$gen_name', CHANGES will have no effect. Update iga64 (libigc-tools package) to re-compile code."
>> - cp $INPUT $OUTPUT
>> + cp -p $INPUT $OUTPUT
>> exit 0
>> }
>> done
>> @@ -127,4 +127,4 @@ for asm in "${ASMS[@]}"; do
>> echo -e "\t{ .gen_ver = $cur_ver, .size = $(dword_count "$cur_code"), .code = (const uint32_t []) {\n$cur_code\n\t}}\n};" >>$OUTPUT
>> done
>>
>> -cp $OUTPUT $INPUT
>> +cp -vp $OUTPUT $INPUT
>>
>> ---
>> base-commit: f564652c85f6bf5e6e076526fe0de7c96dbbe0b2
>> change-id: 20250528-refactor_gpgpu_asms-dd5fb1d78843
>>
>> Best regards,
>> --
>> Andrzej Hajda <andrzej.hajda at intel.com>
>>
More information about the igt-dev
mailing list