-
Notifications
You must be signed in to change notification settings - Fork 359
Added minimal support to do some timing of OM Runtime functionality #3095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AlexandreEichenberger
merged 38 commits into
onnx:main
from
AlexandreEichenberger:timing
Mar 19, 2025
Merged
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
ee16dee
merge from remote branch
AlexandreEichenberger 5b6b918
added files
AlexandreEichenberger 5e7e21f
fix tests
AlexandreEichenberger 97d871a
update
AlexandreEichenberger 903fcb4
update
AlexandreEichenberger 0cb084d
update
AlexandreEichenberger 7cc9a95
update
AlexandreEichenberger fb39de3
update
AlexandreEichenberger 122c804
update
AlexandreEichenberger a4e3d3b
update
AlexandreEichenberger 3092abb
update
AlexandreEichenberger e6806ee
update
AlexandreEichenberger 2e1310e
update
AlexandreEichenberger bd52017
update
AlexandreEichenberger b98f5b2
update
AlexandreEichenberger b91b36d
update
AlexandreEichenberger 706bd81
update
AlexandreEichenberger f60b856
update
AlexandreEichenberger 14c98ff
update
AlexandreEichenberger e423712
update
AlexandreEichenberger f04f00c
update
AlexandreEichenberger 9c9da7f
update
AlexandreEichenberger cae8d3c
added support for driver timing
AlexandreEichenberger a91e59e
update
AlexandreEichenberger 16836b7
update
AlexandreEichenberger cd47c79
disable by default
AlexandreEichenberger 76e957f
updates
AlexandreEichenberger 3ae2950
add custom free
AlexandreEichenberger 53f0139
cleanup of code
AlexandreEichenberger e1201dc
added old for value comparison
AlexandreEichenberger efd696a
added old for value comparison
AlexandreEichenberger bc9f2bb
update
AlexandreEichenberger 6f8e36e
update
AlexandreEichenberger a890af6
remove printout for debugging
AlexandreEichenberger e8fd828
disable timing by default
AlexandreEichenberger 04476a5
fix case where we return a constant
AlexandreEichenberger b0b24ef
leave copy for the constant output case (rare)
AlexandreEichenberger eaa85ed
responce to comments
AlexandreEichenberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//===--------- OMInstrumentHelper.h - Helper for Instrumentation ----------===// | ||
// | ||
// Copyright 2019-2025 The IBM Research Authors. | ||
// | ||
// ============================================================================= | ||
// | ||
// This file contains helpers for gathering timing, enabled by setting: | ||
// | ||
// #define OM_DRIVER_TIMING 1 | ||
// #include "src/Runtime/OMInstrumentHelper.h" | ||
// | ||
// When not defined, all macros are empty, aka generate no code, so no | ||
// overheads. | ||
// | ||
// In Linux: uses gettimeofday and timersub. | ||
// | ||
// TIMING_INIT(var) defines a timing var (context must hold for all timing | ||
// operations). | ||
// TIMING_START(var) starts the timer named var. TIMING_STOP(var) | ||
// adds to the timer named var the difference between now and the last start. | ||
// TIMING_PRINT(var) prints the cumulative time of timer named var. | ||
// | ||
// TIMING_INIT_START does both init and start. | ||
// TIMING_STOP_PRINT does both stop and print. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef OM_INSTRUMENT_HELPER_H | ||
#define OM_INSTRUMENT_HELPER_H 1 | ||
|
||
// Set to 1 to disable all timing regardless of other flags. | ||
#define OM_DRIVER_TIMING_DISABLE_ALL 1 /* 1 (unless when debugging perf) */ | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Timing support for MVS | ||
|
||
#ifdef __MVS__ | ||
#define timersub(a, b, result) \ | ||
do { \ | ||
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ | ||
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ | ||
if ((result)->tv_usec < 0) { \ | ||
--(result)->tv_sec; \ | ||
(result)->tv_usec += 1000000; \ | ||
} \ | ||
} while (0); | ||
#endif | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Timing functions | ||
|
||
#if OM_DRIVER_TIMING && !OM_DRIVER_TIMING_DISABLE_ALL | ||
#include <stdio.h> | ||
#include <sys/time.h> | ||
|
||
// Global variable to help OMInstrumentHelper.h to keep track of nesting level | ||
// of timing operations. | ||
extern int timing_nest_level; | ||
extern char timing_nest_strings[6][20]; | ||
|
||
#define TIMING_INIT(_var_name) \ | ||
/* Define variable in current scope. */ \ | ||
struct timeval _var_name, _var_name##_tmp; \ | ||
int _var_name##_nest_level = -1; \ | ||
_var_name.tv_sec = 0; \ | ||
_var_name.tv_usec = 0; | ||
|
||
#define TIMING_START(_var_name) \ | ||
_var_name##_nest_level = timing_nest_level; \ | ||
++timing_nest_level; \ | ||
gettimeofday(&_var_name##_tmp, NULL); | ||
|
||
#define TIMING_STOP(_var_name) \ | ||
{ /* Define variables in their own scope */ \ | ||
struct timeval start_time, stop_time, diff_time; \ | ||
start_time = _var_name##_tmp; \ | ||
gettimeofday(&stop_time, NULL); \ | ||
timersub(&stop_time, &start_time, &diff_time); \ | ||
_var_name.tv_sec += diff_time.tv_sec; \ | ||
_var_name.tv_usec += diff_time.tv_usec; \ | ||
--timing_nest_level; \ | ||
} | ||
|
||
#define TIMING_PRINT(_var_name) \ | ||
if (_var_name##_nest_level >= 0) { /* was started at least once */ \ | ||
int l = _var_name##_nest_level <= 5 ? _var_name##_nest_level : 5; \ | ||
fprintf(stderr, "@OM_DRIVER, %s%s, %ld.%06ld\n", timing_nest_strings[l], \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can avoid using fprintf(stderr, "@OM_DRIVER, %*s%s, %ld.%06ld\n", l, "",
#_var_name, (long int)_var_name.tv_sec, (long int)_var_name.tv_usec); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will give this pattern a try. |
||
#_var_name, (long int)_var_name.tv_sec, (long int)_var_name.tv_usec); \ | ||
} | ||
|
||
#else | ||
#define TIMING_INIT(_var_name) | ||
#define TIMING_START(_var_name) | ||
#define TIMING_STOP(_var_name) | ||
#define TIMING_PRINT(_var_name) | ||
#endif | ||
|
||
// Combined calls. | ||
#define TIMING_INIT_START(_var_name) \ | ||
TIMING_INIT(_var_name) TIMING_START(_var_name) | ||
#define TIMING_STOP_PRINT(_var_name) \ | ||
TIMING_STOP(_var_name) TIMING_PRINT(_var_name) | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two
needing
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tx, added some additional comments on the difference between data and allocated pointers.