forked from onnx/onnx-mlir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prototype of Instrumentation (onnx#750)
* simple instrument Signed-off-by: Tong Chen <[email protected]> * driver Signed-off-by: Tong Chen <[email protected]> * fix path Signed-off-by: Tong Chen <[email protected]> * run instrumentation Signed-off-by: Tong Chen <[email protected]> * use id Signed-off-by: Tong Chen <[email protected]> * new output Signed-off-by: Tong Chen <[email protected]> * pass for instrumentation Signed-off-by: Tong Chen <[email protected]> * support noBroadcasting Signed-off-by: Tong Chen <[email protected]> * print virtual memory Signed-off-by: Tong Chen <[email protected]> * new opID Signed-off-by: Tong Chen <[email protected]> * slit instrument Signed-off-by: Tong Chen <[email protected]> * change API name Signed-off-by: Tong Chen <[email protected]> * Revert "pass for instrumentation" This reverts commit 9e8e300. * fixes Signed-off-by: Tong Chen <[email protected]> * format Signed-off-by: Tong Chen <[email protected]> * fix Signed-off-by: Tong Chen <[email protected]> * change intrface * add control Signed-off-by: Tong Chen <[email protected]> * fix Signed-off-by: Tong Chen <[email protected]> * format Signed-off-by: Tong Chen <[email protected]> * format Signed-off-by: Tong Chen <[email protected]> * document Signed-off-by: Tong Chen <[email protected]> * remove temporary test script Signed-off-by: Tong Chen <[email protected]> Co-authored-by: Kevin O'Brien <[email protected]>
- Loading branch information
1 parent
66cc7a7
commit 7d1bad6
Showing
17 changed files
with
373 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,41 @@ | ||
<!--- SPDX-License-Identifier: Apache-2.0 --> | ||
|
||
# Instrumentation | ||
|
||
Instrumentation is prototyped in onnx-mlir and can be used to debug runtime issue. | ||
|
||
## Compile for instrumentation | ||
|
||
By default, instrumentation is turned off. To turn it on, modify the default value of `OMInstrumentEnabled' in 'src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.cpp' and build the compiler. Command line flag will be added. | ||
|
||
Currently, only some onnx ops are instrumented. They are Conv, element-wise binary and element-wise varadic operations. | ||
|
||
The instrumentation is added before and after the op.o | ||
|
||
Currently, the call of initialization, OMInstrumentInit, need to be added before you load the dynamic library. It is being considered to add it to the beginning of main_graph by compiler. | ||
|
||
## Run with instrumentation | ||
The instrumenation library will print out the time and virtual memory usage along at each instrumentation point. A sample output is listed below: | ||
``` | ||
ID=Conv TAG=0 Time elapsed: 0.000966 accumulated: 0.000966 | ||
335128 | ||
ID=Conv TAG=1 Time elapsed: 0.395338 accumulated: 0.396304 | ||
335128 | ||
ID=Mul TAG=0 Time elapsed: 0.302189 accumulated: 0.698493 | ||
335128 | ||
ID=Mul TAG=1 Time elapsed: 0.021133 accumulated: 0.719626 | ||
335128 | ||
``` | ||
The output is explained here: | ||
* ID: currently is the name (limited to up to 7 chars) of the op. | ||
* TAG: 0 for before the op, while 1 for after the op. | ||
* elpased: time, in second, elapsed from previous instrumentation point. | ||
* accumulated: time, in second, from instrumentationInit. | ||
* the following line, 33512 in this example, is the virtual memory size (in kb) used by this process. | ||
|
||
## Control of output | ||
* If env variable OMINSTRUMENTTIME is set, the report of time is disabled | ||
* If env variable OMINSTRUMENTMEMORY is set, the report of virtual memory is disabled | ||
|
||
## Used in gdb | ||
The function for instrument point is called `OMInstrumentPoint`. Breakpoint can be set inside this function to kind of step through onnx ops. |
This file contains 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 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,67 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//===-------------- OMInstrument.h - OM Instrument Declaration header ------------===// | ||
// | ||
// Copyright 2019-2020 The IBM Research Authors. | ||
// | ||
// ============================================================================= | ||
// | ||
// This file contains declaration of API functions for instrumentation. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef ONNX_MLIR_OMINSTRUMENT_H | ||
#define ONNX_MLIR_OMINSTRUMENT_H | ||
|
||
#ifdef __cplusplus | ||
#include <algorithm> | ||
#include <cstdint> | ||
#include <iostream> | ||
#include <map> | ||
#include <numeric> | ||
#include <string> | ||
#include <vector> | ||
#include <cstdlib> | ||
#else | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#endif // #ifdef __cplusplus | ||
|
||
#ifdef __APPLE__ | ||
#include <stdlib.h> | ||
#else | ||
#include <malloc.h> | ||
#endif // #ifdef __APPLE__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* Initialize instrument. | ||
* Initialize counter and read env variables for control | ||
* | ||
*/ | ||
void OMInstrumentInit(); | ||
|
||
/** | ||
* Create an instrument point. | ||
* Measurement of runtime behavior will be measured and output | ||
* In current implementation, the elapsed time from previous instrument point, | ||
* and virtual memory size will be reported. | ||
* | ||
* @param id for this point. op name is used now. | ||
* @param tag can used to give extra control of output. Used for begin/end mark now | ||
* @return void | ||
* | ||
*/ | ||
void OMInstrumentPoint(int64_t id, int64_t tag); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // ONNX_MLIR_OMINSTRUMENT_H |
This file contains 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 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 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 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 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 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 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 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 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.