-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from sony/feature/20210909-disable-tf32
Disable TF32 by default
- Loading branch information
Showing
7 changed files
with
145 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2017,2018,2019,2020,2021 Sony Corporation. | ||
# Copyright 2021 Sony Group Corporation. | ||
# | ||
# 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. | ||
|
||
from __future__ import print_function | ||
|
||
import pytest | ||
import os | ||
import subprocess | ||
|
||
|
||
def teardown_function(function): | ||
if os.getenv('NNABLA_CUDA_ALLOW_TF32'): | ||
del os.environ["NNABLA_CUDA_ALLOW_TF32"] | ||
if os.getenv('NVIDIA_TF32_OVERRIDE'): | ||
del os.environ["NVIDIA_TF32_OVERRIDE"] | ||
|
||
|
||
''' | ||
This test is verify that tf32 is set correctly by the environment variables. | ||
''' | ||
|
||
|
||
@pytest.mark.parametrize("nnabla_tf32", [None, "0", "1"]) | ||
@pytest.mark.parametrize("nvidia_tf32", [None, "0", "1"]) | ||
@pytest.mark.parametrize("context", ['cuda', 'cudnn']) | ||
def test_allow_tf32(nnabla_tf32, nvidia_tf32, context): | ||
|
||
if nnabla_tf32: | ||
os.environ["NNABLA_CUDA_ALLOW_TF32"] = nnabla_tf32 | ||
if nvidia_tf32: | ||
os.environ["NVIDIA_TF32_OVERRIDE"] = nvidia_tf32 | ||
|
||
d = os.path.dirname(os.path.abspath(__file__)) | ||
test_main_path = d + "/test_allow_tf32_main.py" | ||
|
||
if nnabla_tf32 == "1": | ||
result = subprocess.run( | ||
["python", test_main_path, "--context", context, "--allow-tf32"]) | ||
else: | ||
result = subprocess.run( | ||
["python", test_main_path, "--context", context]) | ||
|
||
assert result.returncode == 0 |
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,46 @@ | ||
# Copyright 2017,2018,2019,2020,2021 Sony Corporation. | ||
# Copyright 2021 Sony Group Corporation. | ||
# | ||
# 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. | ||
|
||
from __future__ import print_function | ||
|
||
import numpy as np | ||
import nnabla as nn | ||
import os | ||
import argparse | ||
|
||
''' | ||
This test is called by test_allow_tf32.py to verify that tf32 is set correctly by the environment variables. | ||
In pytest, init_cuda is executed only once throughout the whole tests, and this test case is added as a separate test because the correct behavior could not be confirmed. | ||
''' | ||
|
||
|
||
def main(args): | ||
context = args.context | ||
|
||
from nnabla.ext_utils import get_extension_context | ||
with nn.context_scope(get_extension_context(context)): | ||
import nnabla_ext.cuda.init as cuda_init | ||
allow_tf32 = cuda_init.is_tf32_enabled() | ||
|
||
assert args.allow_tf32 == allow_tf32 | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--allow-tf32", action='store_true', default=False) | ||
parser.add_argument("--context", type=str, | ||
default="cuda", choices=["cudnn", "cuda"]) | ||
args = parser.parse_args() | ||
main(args) |
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