Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ jobs:
**.hpp
**.c
**.h
files_ignore: |
backends/**/include/
- name: Run clang-format
if: steps.changed-cpp-files.outputs.any_changed == 'true'
run: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ jobs:
name: Build and Check on ubuntu-24.04 with ${{ matrix.compilers }}
strategy:
matrix:
config-option: ["", "--disable-clang-parser"]
compilers: ["CC=gcc CXX=g++", "CC=clang CXX=clang++ CFLAGS=\"-Wno-gnu-folding-constant\""]
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/setup-thapi
- run: mkdir -p build
- run: ./autogen.sh
- run: ../configure ${{ matrix.config-option }} ${{ matrix.compilers }}
- run: ../configure ${{ matrix.compilers }}
working-directory: build
- run: make
working-directory: build
Expand Down
30 changes: 18 additions & 12 deletions backends/ze/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

if STRICT
# We disable `nonnull` check due to
# ././ze_tracepoints.h: In function 'lttng_ust__event_get_size__lttng_ust_ze___zeModuleCreate_entry':
# .//ze_tracepoints.h: In function 'lttng_ust__event_get_size__lttng_ust_ze___zeModuleCreate_entry':
# [...]/lttng/ust-tracepoint-event.h:578:17: error: argument 1 null where non-null expected [-Werror=nonnull]
# 578 | strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1;
WERROR = -Werror -Wno-error=nonnull
else
WERROR =
# We disable `extern-c-compat` check due to
# ./layers/zel_tracing_register_cb.h:2729:9: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat]
#2729 | typedef struct _zer_get_default_context_params_t
# | ^
#1 error generated.
WERROR = -Werror -Wno-error=nonnull
endif

ZE_NAMESPACES = ze zet zes zel zex
ZE_NAMESPACES = ze zet zes zel zex # zer
ZE_STRUCTS_NAMESPACES = $(ZE_NAMESPACES:=_structs)

ZE_HDR_ROOT = \
Expand All @@ -23,13 +26,16 @@ ZE_HDR_ROOT = \
zet_api.h \
zet_ddi.h \
zet_ddi_ver.h \
#zer_api.h \
#zer_ddi.h \
#zer_ddi_ver.h \
zex_api.h \
loader/ze_loader_api.h \
layers/zel_tracing_api.h \
layers/zel_tracing_ddi.h \
layers/zel_tracing_ddi_ver.h \
layers/zel_tracing_register_cb.h \
loader/ze_loader.h
loader/ze_loader.h \
loader/ze_loader_api.h

ZE_HDR = $(ZE_HDR_ROOT:%=$(srcdir)/include/%)
MODIFIED_ZE_HDR = $(ZE_HDR_ROOT:%=modified_include/%)
Expand Down Expand Up @@ -149,7 +155,7 @@ nodist_libZESampling_la_SOURCES = \
$(ZE_PROBES_INCL) \
$(ZE_STATIC_PROBES_INCL)

libZESampling_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I$(top_srcdir)/backends/ze/include -I./
libZESampling_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I./modified_include -I./
libZESampling_la_CFLAGS = -Wall -Wextra $(WERROR) $(LTTNG_UST_CFLAGS)
libZESampling_la_LDFLAGS = -avoid-version -module
libZESampling_la_LIBADD = $(top_builddir)/sampling/libThapiSampling.la libzetracepoints.la -ldl $(LTTNG_UST_LIBS)
Expand All @@ -174,7 +180,7 @@ nodist_libzetracepoints_la_SOURCES = \
$(ZE_PROBES_SRC) \
$(ZE_STATIC_PROBES_SRC)

libzetracepoints_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I./
libzetracepoints_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./modified_include -I./
libzetracepoints_la_CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Wno-sign-compare $(WERROR) $(LTTNG_UST_CFLAGS)
libzetracepoints_la_LDFLAGS = $(LTTNG_UST_LIBS)

Expand All @@ -189,7 +195,7 @@ nodist_libze_loader_la_SOURCES = \
$(ZE_STATIC_PROBES_INCL) \
tracer_ze.c

libze_loader_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I$(top_srcdir)/utils -I./
libze_loader_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./modified_include -I$(top_srcdir)/utils -I./
libze_loader_la_CFLAGS = -Wall -Wextra $(WERROR) $(LIBFFI_CFLAGS) $(LTTNG_UST_CFLAGS)
libze_loader_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS)
libze_loader_la_LDFLAGS += -version-info 1:0:0
Expand Down Expand Up @@ -260,7 +266,7 @@ libZEInterval_la_SOURCES = \
btx_zeinterval_callbacks.cpp \
btx_zeinterval_callbacks.hpp

libZEInterval_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I./ -I./btx_filter_ze
libZEInterval_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./modified_include -I./ -I./btx_filter_ze
libZEInterval_la_CFLAGS = -Wall -Wextra -Wno-unused-parameter $(WERROR) $(BABELTRACE2_CFLAGS)
libZEInterval_la_CXXFLAGS = -std=c++17 -Wall -Wextra -Wno-unused-parameter $(WERROR) $(BABELTRACE2_CFLAGS)
libZEInterval_la_LDFLAGS = $(BABELTRACE2_LIBS) -avoid-version -module
Expand All @@ -286,7 +292,7 @@ $(BTX_ZE_GENERATED_SOURCE_TEST) &: btx_ze_model.yaml

noinst_LTLIBRARIES += libtestzesource.la
nodist_libtestzesource_la_SOURCES = $(BTX_ZE_GENERATED_SOURCE_TEST)
libtestzesource_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I./btx_source_ze_test/
libtestzesource_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./modified_include -I./btx_source_ze_test/
libtestzesource_la_CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter $(WERROR) $(BABELTRACE2_CFLAGS)

TRACE_OUT = $(TRACE_COMMON:.thapi_text_pretty=.bt_text_pretty)
Expand Down
167 changes: 167 additions & 0 deletions backends/ze/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Header Location

- Standard: `https://github.com/argonne-lcf/level-zero-spec/tree/ddi_ver`
- Loader: `https://github.com/oneapi-src/level-zero/tags`
- Extension: `https://github.com/intel/compute-runtime/blob/master/level_zero/include/level_zero/driver_experimental/zex_api.h`

# Steps:

## 1/ Loader Repo

- We will use the loader repo to get most of the headers. The loader contains the spec header (`ze_api.h`) and the loader-specific API (`loader/ze_loader.h`).

- Note: It is preferable to have a loader already installed on your system:
- We may need it to check for symbols that are "defined in the header but not exported by the lib"
- We are wary of exposing a newer loader than the system one, as users may request symbols that we cannot forward

- If you have access to a Level Zero lib, compile and run:
```bash
$ icpx -lze_loader utils_spec_update/query_ze_version.cpp && ./a.out
Driver version: 259.33578
API version: 1.13
Loader component versions:
[0] Name: loader
Spec: 1.13
Lib version: 1.24.0
[1] Name: tracing layer
Spec: 1.13
Lib version: 1.24.0
```
- This will give you the loader version.

- If you have access to a loader, you can copy/paste the `/usr/include/level_zero/` folder into `$THAPI_ROOT/backend/ze/include/`.
If not, use `git clone --depth 1 --branch $(lib_version) https://github.com/oneapi-src/level-zero.git`, where `lib_version` is the version you want.
To find the latest lib version of the loader released, run:
```bash
$ git ls-remote --sort="v:refname" --tags https://github.com/oneapi-src/level-zero.git | tail -1
6369d8d642e9c7625e67f38664267f171b8e42dc refs/tags/v1.28.2
```

### Note on `ze_loader_api.h`

- We need also to copy / paste `source/loader/ze_loader_api.h`. The loader export it, so we export it too, just in case.
- Those header, are a nighmare.
- 1/ C++ header: We modify them manually to remove any C++
- 2/ We split them by namespace:
- `ze_loader`, contain `zel`,
- `ze_loader_api_ze_namespace.h` contain the `ze`.

## 2/ DDI Ver

### Sync

- Sync the fork (` https://github.com/argonne-lcf/level-zero-spec.git`) with the original remote
- Sync the `ddi_ver` branch

### Building `ddi_table`

Then we will build the `ddi_table` corresponding to the Level Zero API version.

If you don't know the Header/API version associated with the driver previously used, you can grep for `ZE_API_VERSION_CURRENT`:
```bash
$ grep define ZE_API_VERSION_CURRENT ./level_zero/ze_api.h | head -1
ZE_API_VERSION_CURRENT = ZE_MAKE_VERSION( 1, 13 ), ///< latest known version
```

Now it's time to generate `ddi_ver.h`:
```bash
git clone -b ddi_ver https://github.com/argonne-lcf/level-zero-spec.git
cd level-zero-spec/scripts/
uv pip install -r third_party/requirements.txt
python run.py --ver $version --\!debug --\!html
```

- The headers will be generated in `level-zero-spec/include/`. Copy `../include/*_ddi_ver.h` into `$THAPI_ROOT/backend/ze/include/`.
- You can sanity-check that the headers are the same And that `ZE_API_VERSION_CURRENT_M` define the same version
```
grep "ZE_API_VERSION_CURRENT" ../include/ze_api.h # Sanity check
ZE_API_VERSION_CURRENT = ZE_MAKE_VERSION( 1, 13 ), ///< latest known version
#ifndef ZE_API_VERSION_CURRENT_M
#define ZE_API_VERSION_CURRENT_M ZE_MAKE_VERSION( 1, 15 )
#endif // ZE_API_VERSION_CURRENT_M
```
(We don't talk about `ZE_API_VERSION_CURRENT_M`...)

- Note that `layers/zel_tracing_ddi_ver.h` is not generated manually, and need manual update.
- We remove all the C++, and all the weird important who bring symbol for other namespace.

## 3/ Optional: ZEX

- We are missing the `zex` header:
- Found at `https://github.com/intel/compute-runtime/blob/master/level_zero/include/level_zero/driver_experimental/zex_api.h`

## Now Try to Compile:

- Try to compile

## 4/ Add medatadata

You can use the `check_metadata.py` script to help you indentify function which need update and then figure it out.

# Potential Problems, Thinks to check

## 0

Run `utils_spec_update/test_symbol_exported.sh $loader_so $out_so`
If symbol are not exposed by the loader, but are exposed by us it's a bug!
Add a patch to comment them in `header.path`.

```
$ bash ./utils_spec_update/test_symbol_exported.sh /usr/lib64/libze_loader.so ~/project/p26.04/THAPI/build/ici/lib/thapi/ze/libze_loader.so
--- /usr/lib64/libze_loader.so
+++ /home/applenco/project/p26.04/THAPI/build/ici/lib/thapi/ze/libze_loader.so
@@ -240,6 +240,7 @@
zelLoaderContextTeardown
zelLoaderDriverCheck
zelLoaderGetContext
+zelLoaderGetVersion
zelLoaderGetVersions
zelLoaderGetVersionsInternal
zelLoaderTracingLayerInit
@@ -444,6 +445,7 @@
zelTracerRTASParallelOperationGetPropertiesExtRegisterCallback
zelTracerRTASParallelOperationJoinExpRegisterCallback
zelTracerRTASParallelOperationJoinExtRegisterCallback
+zelTracerResetAllCallbacks
zelTracerSamplerCreateRegisterCallback
zelTracerSamplerDestroyRegisterCallback
zelTracerSetEnabled
```

One possibility is to do:
```
cp -r ../../build/backends/ze/modified_include .
# Modify `modified_include`
Then
`diff -u4 -r --new-file include/ modified_include/ > headers.patch`

## 1

```
tracer_ze.c:197:8: error: use of undeclared identifier 'ZE_STRUCTURE_TYPE_DEVICE_CACHE_LINE_SIZE_EXT'; did you mean 'ZE_STRUCTURE_TYPE_DEVICE_CACHELINE_SIZE_EXT'?
197 | case ZE_STRUCTURE_TYPE_DEVICE_CACHE_LINE_SIZE_EXT:
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ZE_STRUCTURE_TYPE_DEVICE_CACHELINE_SIZE_EXT
```

Due to Intel's lack of naming consistency, you may need to update the `struct_type_conversion_table` in `ze_model.rb`.

## 2

```
tracer_ze.c:8456:20: error: unused function 'zelTracerResetAllCallbacks_hid' [-Werror,-Wunused-function]
8456 | static ze_result_t zelTracerResetAllCallbacks_hid(zel_tracer_handle_t hTracer)__attribute__ ((alias ("zelTracerResetAllCallbacks")));
| ^~~~~~~~~~~~~~~~~
```
Need to modify the `$zel_commands.each` block that generates `#{c.decl_hidden_alias};` in `gen_ze.rb`.

## 3

Runtime error: When running `babeltrace_thapi` (`iprof -t`), constant error:
```
PogrammableParamValueInfoExp>': uninitialized constant ZE::ZETMetricProgrammableParamValueInfoExp::ZET_MAX_METRIC_PROGRAMMABLE_VALUE_DESCRIPTION_EXP (NameError)

:description, [ :char, ZET_MAX_METRIC_PROGRAMMABLE_VALUE_DESCRIPTION_EXP ]
```
Update in `backends/ze/gen_ze_library.rb`, Module ZE.
TODO: `h2yaml` should be able to find all the constants defined.
2 changes: 1 addition & 1 deletion backends/ze/extract_ze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <ze_api.h>
#include <ze_ddi.h>
#include <ze_ddi_ver.h>
#include <loader/ze_loader_api.h>
#include <loader/ze_loader_api_ze_namespace.h>
EOF

if enable_clang_parser?
Expand Down
1 change: 1 addition & 0 deletions backends/ze/extract_zel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <layers/zel_tracing_ddi_ver.h>
#include <layers/zel_tracing_register_cb.h>
#include <loader/ze_loader.h>
#include <loader/ze_loader_api.h>
EOF

if enable_clang_parser?
Expand Down
37 changes: 37 additions & 0 deletions backends/ze/extract_zer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative 'extract_base'

zel_header = <<EOF
#include <zer_api.h>
#include <zer_ddi.h>
#include <zer_ddi_ver.h>
EOF

if enable_clang_parser?
header = [shared_header, zel_header].join("\n")
require 'open3'
yaml, status = Open3.capture2(
'h2yaml --compat-cast-to-yaml -Wc,-xc -Wc,-Imodified_include/ --filter-header "zer" -', stdin_data: header
)
exit(1) unless status.success?

else
require_relative 'extract_base'
preprocessed_sources_ze_api = $cpp.preprocess(<<~EOF).gsub(/^#.*?$/, '')
#include <ze_api.h>
#include <ze_ddi.h>
EOF

preprocessed_sources_zel_api = $cpp.preprocess(<<~EOF).gsub(/^#.*?$/, '')
#define _ZE_API_H
#{zel_header}
EOF

$parser.parse(preprocessed_sources_ze_api)
ast = $parser.parse(preprocessed_sources_zel_api)
yaml = ast.extract_declarations.to_yaml

end

File.open('zer_api.yaml', 'w') do |f|
f.puts yaml
end
4 changes: 3 additions & 1 deletion backends/ze/gen_babeltrace_ze_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[:lttng_ust_zet, $zet_commands],
[:lttng_ust_zes, $zes_commands],
[:lttng_ust_zel, $zel_commands],
[:lttng_ust_zer, $zer_commands],
[:lttng_ust_zex, $zex_commands]].collect do |provider, commands|
commands.collect do |c|
[gen_event_bt_model(provider, c, :start),
Expand Down Expand Up @@ -76,8 +77,9 @@ def gen_struct_event_bt_model(provider, struct)
[:lttng_ust_zet_structs, get_structs_types(:zet, $zet_api['typedefs'], $zet_api['structs'])],
[:lttng_ust_zes_structs, get_structs_types(:zes, $zes_api['typedefs'], $zes_api['structs'])],
[:lttng_ust_zel_structs, get_structs_types(:zel, $zel_api['typedefs'], $zel_api['structs'])],
[:lttng_ust_zer_structs, get_structs_types(:zer, $zer_api['typedefs'], $zer_api['structs'])],
[:lttng_ust_zex_structs,
get_structs_types(:zex, $zes_api['typedefs'], $zes_api['structs'])]].collect do |provider, structs|
get_structs_types(:zex, $zex_api['typedefs'], $zex_api['structs'])]].collect do |provider, structs|
structs.collect do |struct|
gen_struct_event_bt_model(provider, struct)
end
Expand Down
Loading
Loading