Skip to content

Conversation

@pbalcer
Copy link
Contributor

@pbalcer pbalcer commented Apr 17, 2023

urtrace is a command-line tool for tracing and profiling Unified Runtime library calls in a process. It can be used to inspect the function arguments of each call, and provides options for filtering, output formatting, and profiling.

@pbalcer
Copy link
Contributor Author

pbalcer commented Apr 17, 2023

I also have a few other things in the pipeline for argument printing verbosity, but I didn't want to do them here due to potential conflicts with #411.

Example output (it will improve once #411 is merged):

unified-runtime/build/bin ‹urtrace*› » ./urtrace --null --profiling  ./hello_world 
urInit(.device_flags = 0) -> UR_RESULT_SUCCESS; (4.156us)
Platform initialized.
urPlatformGet(.NumEntries = 1, .phPlatforms = [], .pNumPlatforms = 0x7f1befb01820 (1)) -> UR_RESULT_SUCCESS; (3.148us)
urPlatformGet(.NumEntries = 1, .phPlatforms = [0x80800001], .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS; (1.033us)
urPlatformGetApiVersion(.hDriver = 0x80800001, .pVersion = 0x7f1befb018b0 (0.6)) -> UR_RESULT_SUCCESS; (1.119us)
API version: 0.6
urDeviceGet(.hPlatform = 0x80800001, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 0, .phDevices = [], .pNumDevices = 0x7f1befb018c0 (1)) -> UR_RESULT_SUCCESS; (1.445us)
urDeviceGet(.hPlatform = 0x80800001, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 1, .phDevices = [0x80800002], .pNumDevices = nullptr) -> UR_RESULT_SUCCESS; (1.053us)
urDeviceGetInfo(.hDevice = 0x80800002, .propName = UR_DEVICE_INFO_TYPE, .propSize = 4, .pPropValue = 0x7f1befb01960, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; (1.672us)
urDeviceGetInfo(.hDevice = 0x80800002, .propName = UR_DEVICE_INFO_NAME, .propSize = 1023, .pPropValue = 0x7f1befb01970, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; (2.3us)
Found a Null Device gpu.
urTearDown(.pParams = nullptr) -> UR_RESULT_SUCCESS; (1.044us)

Copy link
Contributor

@igchor igchor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pbalcer pbalcer force-pushed the urtrace branch 2 times, most recently from 084b45e to e0c026c Compare April 18, 2023 08:56
# with a known good match file.
#

find_package(Python3 COMPONENTS Interpreter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done in the main CMakeLists.txt - do you have to run this again in this script to have python3 path defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because this is a separate instance of the cmake process.

add_test(NAME ${TEST_NAME}
    COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/match.cmake
    ...
)

This starts a new cmake process to run the provided script. It's unfortunate, but that's how it works. I could replace this entire match.cmake script with a python one, which would simplify things (but that's a separate PR).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's ok then.

# with a known good match file.
#

find_package(Python3 COMPONENTS Interpreter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's ok then.

@@ -0,0 +1,136 @@
#!/usr/bin/env python

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give this file a .py extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because I want it to look like a normal binary if installed in the system.

ostr << dur.count() << "ns";
} break;
case TIME_UNIT_US: {
std::chrono::duration<double, std::micro> d = dur;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Might be more readable:
std::chrono::microseconds d = dur

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it would only print whole integer microseconds, which is not useful...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that, sure.

MAX_TIME_UNIT,
};

const char *time_unit_str[MAX_TIME_UNIT] = {"auto", "ns", "us", "ms", "s"};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would making a time_unit and a const char *time_unit_str a map entry cause a performance hit here? It seems cleaner to use a map instead, however you won't be able to switch through all of the keys.

Copy link
Contributor Author

@pbalcer pbalcer Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree that using a map is cleaner. This allocates no memory and is very straightforward. It's a very common pattern for mapping enum values to strings...

@pbalcer pbalcer force-pushed the urtrace branch 2 times, most recently from f83e33d to 549f701 Compare April 19, 2023 10:29
if args.debug:
print(result)

exit(result.returncode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No empty line at EOF.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not true? Git shows something like 'no newline at end of file' and on github in PRs there's a red bar if that's the case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I meant, to add an empty newline, sorry for misconfusion.

@pbalcer pbalcer force-pushed the urtrace branch 2 times, most recently from 1b3cb44 to 9ce3535 Compare April 19, 2023 12:54
urtrace is a command-line tool for tracing and profiling Unified Runtime library
calls in a process. It can be used to inspect the function arguments of each call,
and provides options for filtering, output formatting, and profiling.
ostr << dur.count() << "ns";
} break;
case TIME_UNIT_US: {
std::chrono::duration<double, std::micro> d = dur;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that, sure.

if args.debug:
print(result)

exit(result.returncode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I meant, to add an empty newline, sorry for misconfusion.

@pbalcer pbalcer merged commit ed77900 into oneapi-src:main Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants