-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]: change matmul default setting: do not use tensor core, use ne…
…w cublasGemmEx api (#10267) Modify the default setting of matrix multiplication: do not utilize the Tensor Core feature. Add python api for matmul allow_tf32 like pytorch: oneflow.backends.cuda.matmul.allow_tf32 = True Add python api for matmul allow_fp16_reduced_precision_reduction like pytorch: oneflow.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = True
- Loading branch information
1 parent
89b6916
commit 1cbe5f5
Showing
8 changed files
with
240 additions
and
15 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,39 @@ | ||
/* | ||
Copyright 2020 The OneFlow Authors. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include <memory> | ||
#include <pybind11/pybind11.h> | ||
#include "oneflow/api/python/of_api_registry.h" | ||
#include "oneflow/core/ep/cuda/cuda_matmul_mode.h" | ||
|
||
namespace py = pybind11; | ||
|
||
namespace oneflow { | ||
|
||
namespace ep { | ||
|
||
ONEFLOW_API_PYBIND11_MODULE("ep", m) { | ||
m.def("is_matmul_allow_tf32", &CudaMatmulMode::is_matmul_allow_tf32); | ||
m.def("set_matmul_allow_tf32", &CudaMatmulMode::set_matmul_allow_tf32); | ||
m.def("is_matmul_allow_fp16_reduced_precision_reduction", | ||
&CudaMatmulMode::is_matmul_allow_fp16_reduced_precision_reduction); | ||
m.def("set_matmul_allow_fp16_reduced_precision_reduction", | ||
&CudaMatmulMode::set_matmul_allow_fp16_reduced_precision_reduction); | ||
} | ||
|
||
} // namespace ep | ||
|
||
} // namespace oneflow |
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,54 @@ | ||
/* | ||
Copyright 2020 The OneFlow Authors. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "oneflow/core/ep/cuda/cuda_matmul_mode.h" | ||
|
||
namespace oneflow { | ||
|
||
namespace ep { | ||
|
||
namespace { | ||
|
||
bool* GetMatmulAllowTF32() { | ||
static bool matmul_allow_tf32 = true; | ||
return &matmul_allow_tf32; | ||
} | ||
|
||
bool* GetMatmulAllowFP16ReducedPrecisionReducton() { | ||
static bool matmul_allow_fp16_reduced_precision_reduction = true; | ||
return &matmul_allow_fp16_reduced_precision_reduction; | ||
} | ||
|
||
} // namespace | ||
|
||
bool CudaMatmulMode::is_matmul_allow_tf32() { return *GetMatmulAllowTF32(); } | ||
|
||
void CudaMatmulMode::set_matmul_allow_tf32(bool matmul_allow_tf32) { | ||
*GetMatmulAllowTF32() = matmul_allow_tf32; | ||
} | ||
|
||
bool CudaMatmulMode::is_matmul_allow_fp16_reduced_precision_reduction() { | ||
return *GetMatmulAllowFP16ReducedPrecisionReducton(); | ||
} | ||
|
||
void CudaMatmulMode::set_matmul_allow_fp16_reduced_precision_reduction( | ||
bool matmul_allow_fp16_reduced_precision_reduction) { | ||
*GetMatmulAllowFP16ReducedPrecisionReducton() = matmul_allow_fp16_reduced_precision_reduction; | ||
} | ||
|
||
} // namespace ep | ||
|
||
} // namespace oneflow |
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,34 @@ | ||
/* | ||
Copyright 2020 The OneFlow Authors. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#ifndef ONEFLOW_CORE_EP_CUDA_MATMUL_MODE_H_ | ||
#define ONEFLOW_CORE_EP_CUDA_MATMUL_MODE_H_ | ||
|
||
namespace oneflow { | ||
namespace ep { | ||
|
||
struct CudaMatmulMode { | ||
static bool is_matmul_allow_tf32(); | ||
static void set_matmul_allow_tf32(bool matmul_allow_tf32); | ||
static bool is_matmul_allow_fp16_reduced_precision_reduction(); | ||
static void set_matmul_allow_fp16_reduced_precision_reduction( | ||
bool matmul_allow_fp16_reduced_precision_reduction); | ||
}; | ||
|
||
} // namespace ep | ||
} // namespace oneflow | ||
|
||
#endif // ONEFLOW_CORE_EP_CUDA_MATMUL_MODE_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Copyright 2020 The OneFlow Authors. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
import oneflow._oneflow_internal | ||
|
||
|
||
class cuMatmulMode: | ||
def __getattr__(self, name): | ||
if name == "allow_tf32": | ||
return oneflow._oneflow_internal.ep.is_matmul_allow_tf32() | ||
elif name == "allow_fp16_reduced_precision_reduction": | ||
return ( | ||
oneflow._oneflow_internal.ep.is_matmul_allow_fp16_reduced_precision_reduction() | ||
) | ||
raise AssertionError("Unknown attribute " + name) | ||
|
||
def __setattr__(self, name, value): | ||
if name == "allow_tf32": | ||
return oneflow._oneflow_internal.ep.set_matmul_allow_tf32(value) | ||
elif name == "allow_fp16_reduced_precision_reduction": | ||
return oneflow._oneflow_internal.ep.set_matmul_allow_fp16_reduced_precision_reduction( | ||
value | ||
) | ||
raise AssertionError("Unknown attribute " + name) | ||
|
||
|
||
matmul = cuMatmulMode() |
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