forked from snuspl/nimble
-
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.
[caffe2][nomnigraph] Add optimize function to opt:: namespace that ta…
…kes in a level and optimizes the graph/workspace accordingly. Adding it to predictor and speed_benchmark arguments (#7558)
- Loading branch information
Showing
8 changed files
with
85 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "caffe2/opt/optimizer.h" | ||
|
||
#include "caffe2/opt/converter.h" | ||
#include "caffe2/opt/mobile.h" | ||
#include "caffe2/opt/fusion.h" | ||
|
||
namespace caffe2 { | ||
namespace opt { | ||
|
||
void workspaceOptimizations(nom::repr::NNModule* nn, Workspace* ws, int level) { | ||
switch (level) { | ||
case 1: | ||
opt::fuseConvBN(nn, ws); | ||
case 0: | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void graphOptimzations(nom::repr::NNModule* nn, int level) { | ||
switch (level) { | ||
case 1: | ||
#ifdef USE_NNPACK | ||
opt::addNNPACK(nn, false); | ||
opt::fuseNNPACKConvRelu(nn); | ||
#endif | ||
case 0: | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
NetDef optimize(NetDef net, Workspace* ws, int level) { | ||
auto nn = convertToNNModule(net); | ||
graphOptimzations(&nn, level); | ||
workspaceOptimizations(&nn, ws, level); | ||
return convertToCaffe2Proto(nn, net); | ||
} | ||
|
||
NetDef optimize(NetDef net, int level) { | ||
auto nn = convertToNNModule(net); | ||
graphOptimzations(&nn, level); | ||
return convertToCaffe2Proto(nn, net); | ||
} | ||
|
||
} // namespace opt | ||
} // namespace caffe2 | ||
|
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,17 @@ | ||
#ifndef CAFFE2_OPT_OPTIMIZER_H | ||
#define CAFFE2_OPT_OPTIMIZER_H | ||
|
||
#include "caffe2/core/common.h" | ||
#include "caffe2/proto/caffe2.pb.h" | ||
#include "caffe2/core/workspace.h" | ||
|
||
namespace caffe2 { | ||
namespace opt { | ||
|
||
NetDef optimize(NetDef net, Workspace* ws, int level = 1); | ||
NetDef optimize(NetDef net, int level = 1); | ||
|
||
} // namespace opt | ||
} // namespace caffe2 | ||
|
||
#endif // CAFFE2_OPT_OPTIMIZER_H |