-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Filter activation fusions on MCDM #18371
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,23 +10,25 @@ | |
|
||
namespace Dml | ||
{ | ||
class ExecutionProviderImpl; | ||
|
||
// Applies transforms to a Lotus graph. The graph transformer is responsible for setting the execution provider | ||
// on the graph nodes which DML supports. | ||
class GraphTransformer : public onnxruntime::GraphTransformer | ||
{ | ||
public: | ||
GraphTransformer( | ||
const std::string& name | ||
) : onnxruntime::GraphTransformer(name) | ||
{ | ||
} | ||
const std::string& name, | ||
const onnxruntime::IExecutionProvider* provider | ||
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.
tabs |
||
); | ||
|
||
private: | ||
onnxruntime::common::Status ApplyImpl(onnxruntime::Graph& graph, bool& modified, int graph_level, const onnxruntime::logging::Logger& logger) const final; | ||
|
||
private: | ||
void PerformOperatorFusion(onnxruntime::Graph* graph, bool* modified) const; | ||
void PerformOperatorFusion(onnxruntime::Graph* graph, bool isMcdmDevice, bool* modified) const; | ||
|
||
const ExecutionProviderImpl* m_providerImpl = nullptr; | ||
}; | ||
|
||
} // namespace Dml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,8 @@ namespace Dml | |
std::string_view domain; | ||
int sinceVersion; | ||
std::vector<std::string_view> activationFilter; | ||
bool enableOnMcdm; | ||
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. 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. Just talked with Jeff - it's a stopgap. Consider resolved. |
||
std::vector<std::string_view> extraMcdmActivationFilter; | ||
std::optional<uint32_t> inputCountFilter; | ||
}; | ||
|
||
|
@@ -142,10 +144,10 @@ namespace Dml | |
|
||
static const OperatorInfo c_fusableOps[] = | ||
{ | ||
OperatorInfo{ "Conv", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Conv }, | ||
OperatorInfo{ "Conv", onnxruntime::kOnnxDomain, OnnxOperatorSet11::sc_sinceVer_Conv }, | ||
OperatorInfo{ "ConvTranspose", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_ConvTranspose }, | ||
OperatorInfo{ "ConvTranspose", onnxruntime::kOnnxDomain, OnnxOperatorSet11::sc_sinceVer_ConvTranspose }, | ||
OperatorInfo{ "Conv", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Conv, {}, true, {"Relu", "LeakyRelu"} }, | ||
OperatorInfo{ "Conv", onnxruntime::kOnnxDomain, OnnxOperatorSet11::sc_sinceVer_Conv, {}, true, {"Relu", "LeakyRelu"} }, | ||
OperatorInfo{ "ConvTranspose", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_ConvTranspose, {}, true, {"Relu", "LeakyRelu"} }, | ||
OperatorInfo{ "ConvTranspose", onnxruntime::kOnnxDomain, OnnxOperatorSet11::sc_sinceVer_ConvTranspose, {}, true, {"Relu", "LeakyRelu"} }, | ||
OperatorInfo{ "BatchNormalization", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_BatchNormalization }, | ||
OperatorInfo{ "BatchNormalization", onnxruntime::kOnnxDomain, OnnxOperatorSet9::sc_sinceVer_BatchNormalization }, | ||
OperatorInfo{ "BatchNormalization", onnxruntime::kOnnxDomain, OnnxOperatorSet14::sc_sinceVer_BatchNormalization }, | ||
|
@@ -163,11 +165,11 @@ namespace Dml | |
OperatorInfo{ "MatMul", onnxruntime::kOnnxDomain, OnnxOperatorSet13::sc_sinceVer_MatMul }, | ||
|
||
// The filter for activation functions maps to what DML's fused op internally fuses at the shader level. | ||
OperatorInfo{ "Add", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Add, {"Relu", "LeakyRelu"} }, | ||
OperatorInfo{ "Add", onnxruntime::kOnnxDomain, OnnxOperatorSet13::sc_sinceVer_Add, {"Relu", "LeakyRelu"} }, | ||
OperatorInfo{ "Add", onnxruntime::kOnnxDomain, OnnxOperatorSet14::sc_sinceVer_Add, {"Relu", "LeakyRelu"} }, | ||
OperatorInfo{ "Sum", onnxruntime::kOnnxDomain, OnnxOperatorSet8::sc_sinceVer_Sum, {"Relu", "LeakyRelu"}, 2 }, | ||
OperatorInfo{ "Sum", onnxruntime::kOnnxDomain, OnnxOperatorSet13::sc_sinceVer_Sum, {"Relu", "LeakyRelu"}, 2 }, | ||
OperatorInfo{ "Add", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Add, {"Relu", "LeakyRelu"}, true }, | ||
OperatorInfo{ "Add", onnxruntime::kOnnxDomain, OnnxOperatorSet13::sc_sinceVer_Add, {"Relu", "LeakyRelu"}, true }, | ||
OperatorInfo{ "Add", onnxruntime::kOnnxDomain, OnnxOperatorSet14::sc_sinceVer_Add, {"Relu", "LeakyRelu"}, true }, | ||
OperatorInfo{ "Sum", onnxruntime::kOnnxDomain, OnnxOperatorSet8::sc_sinceVer_Sum, {"Relu", "LeakyRelu"}, true, {} , 2 }, | ||
OperatorInfo{ "Sum", onnxruntime::kOnnxDomain, OnnxOperatorSet13::sc_sinceVer_Sum, {"Relu", "LeakyRelu"}, true, {} , 2 }, | ||
}; | ||
|
||
// Not all activations can be fused - only simple elementwise activations (i.e. activation functions which | ||
|
@@ -205,7 +207,8 @@ namespace Dml | |
int candidateOpInputCount, | ||
std::string_view activationOpType, | ||
std::string_view activationOpDomain, | ||
int activationOpSinceVersion) | ||
int activationOpSinceVersion, | ||
bool isMcdmDevice) | ||
{ | ||
auto opIt = std::find( | ||
std::begin(c_fusableOps), | ||
|
@@ -233,6 +236,20 @@ namespace Dml | |
return std::nullopt; | ||
} | ||
|
||
if (isMcdmDevice) | ||
{ | ||
if (!opIt->enableOnMcdm) | ||
{ | ||
return std::nullopt; | ||
} | ||
|
||
if (!opIt->extraMcdmActivationFilter.empty() && | ||
std::find(opIt->extraMcdmActivationFilter.begin(), opIt->extraMcdmActivationFilter.end(), activationOpType) == opIt->extraMcdmActivationFilter.end()) | ||
{ | ||
return std::nullopt; | ||
} | ||
} | ||
|
||
if (opIt->inputCountFilter && *opIt->inputCountFilter != static_cast<uint32_t>(candidateOpInputCount)) | ||
{ | ||
return std::nullopt; | ||
|
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.
tabs #Closed