2024-10-30 19:39:08 +05:30
---
myst:
html_meta:
"description": "ROCprofiler-SDK is a tooling infrastructure for profiling general-purpose GPU compute applications running on the ROCm software."
"keywords": "ROCprofiler-SDK API reference, ROCprofiler-SDK intercept table, Intercept table API"
---
2023-11-28 10:04:37 -06:00
2024-10-30 19:39:08 +05:30
# ROCprofiler-SDK runtime intercept tables
2024-08-01 02:59:35 -05:00
2024-10-30 19:39:08 +05:30
While tools commonly leverage the callback or buffer tracing services for tracing the HIP, HSA, and ROCTx
APIs, ROCprofiler-SDK also provides access to the raw API dispatch tables.
2024-08-01 02:59:35 -05:00
2024-10-30 19:39:08 +05:30
## Forward declaration of public C API function
All the aforementioned APIs are designed similar to the following sample:
2024-08-01 02:59:35 -05:00
``` cpp
extern " C "
{
// forward declaration of public C API function
int
foo ( int ) __attribute__ ( ( visibility ( " default " ) ) ) ;
}
```
2024-10-30 19:39:08 +05:30
## Internal implementation of API function
2024-08-01 02:59:35 -05:00
``` cpp
namespace impl
{
int
foo ( int val )
{
// real implementation
return ( 2 * val ) ;
}
}
```
2024-10-30 19:39:08 +05:30
## Dispatch table implementation
2024-08-01 02:59:35 -05:00
``` cpp
namespace impl
{
struct dispatch_table
{
int ( * foo_fn ) ( int ) = nullptr ;
} ;
2024-10-30 19:39:08 +05:30
// Invoked once: populates the dispatch_table with function pointers to implementation
2024-08-01 02:59:35 -05:00
dispatch_table * &
construct_dispatch_table ( )
{
static dispatch_table * tbl = new dispatch_table { } ;
tbl - > foo_fn = impl : : foo ;
2024-10-30 19:39:08 +05:30
// In between, ROCprofiler-SDK gets passed the pointer
2024-08-01 02:59:35 -05:00
// to the dispatch table and has the opportunity to wrap the function
// pointers for interception
return tbl ;
}
2024-10-30 19:39:08 +05:30
// Constructs dispatch table and stores it in static variable
2024-08-01 02:59:35 -05:00
dispatch_table *
get_dispatch_table ( )
{
static dispatch_table * & tbl = construct_dispatch_table ( ) ;
return tbl ;
}
} // namespace impl
```
2024-10-30 19:39:08 +05:30
## Implementation of public C API function
2024-08-01 02:59:35 -05:00
``` cpp
extern " C "
{
// implementation of public C API function
int
foo ( int val )
{
return impl : : get_dispatch_table ( ) - > foo_fn ( val ) ;
}
}
```
2024-10-30 19:39:08 +05:30
## Dispatch table chaining
2024-08-01 02:59:35 -05:00
2024-10-30 19:39:08 +05:30
ROCprofiler-SDK can save the original values of the function pointers such as `foo_fn` in `impl::construct_dispatch_table()` and install its own function pointers in its place. This results in the public C API function `foo` calling into the ROCprofiler-SDK function pointer, which in turn, calls the original function pointer to `impl::foo` . This phenomenon is named chaining. Once ROCprofiler-SDK
makes necessary modifications to the dispatch table, tools requesting access to the raw dispatch table via `rocprofiler_at_intercept_table_registration` , are provided the pointer to the dispatch table.
2024-08-01 02:59:35 -05:00
2024-10-30 19:39:08 +05:30
For an example of dispatch table chaining, see [samples/intercept_table ](https://github.com/ROCm/rocprofiler-sdk-internal/tree/amd-staging/samples/intercept_table ).