-
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.
- Loading branch information
1 parent
78dd837
commit fab34fb
Showing
4 changed files
with
117 additions
and
53 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 |
---|---|---|
@@ -1,41 +0,0 @@ | ||
import torch | ||
import torch.testing._internal.common_utils as common_utils | ||
|
||
|
||
class CudaNonDefaultStream: | ||
def __enter__(self): | ||
# Before starting CUDA test save currently active streams on all | ||
# CUDA devices and set new non default streams to all CUDA devices | ||
# to ensure CUDA tests do not use default stream by mistake. | ||
beforeDevice = torch.cuda.current_device() | ||
self.beforeStreams = [] | ||
for d in range(torch.cuda.device_count()): | ||
self.beforeStreams.append(torch.cuda.current_stream(d)) | ||
deviceStream = torch.cuda.Stream(device=d) | ||
self.beforeStreams[-1].synchronize() | ||
""" | ||
torch._C._cuda_setStream(stream_id=deviceStream.stream_id, | ||
device_index=deviceStream.device_index, | ||
device_type=deviceStream.device_type) | ||
""" | ||
torch.cuda.set_stream(deviceStream) | ||
|
||
# torch._C._cuda_setDevice(beforeDevice) | ||
torch.cuda.set_device(beforeDevice) | ||
|
||
def __exit__(self, exec_type, exec_value, traceback): | ||
# After completing CUDA test load previously active streams on all | ||
# CUDA devices. | ||
beforeDevice = torch.cuda.current_device() | ||
for d in range(torch.cuda.device_count()): | ||
""" | ||
torch._C._cuda_setStream(stream_id=self.beforeStreams[d].stream_id, | ||
device_index=self.beforeStreams[d].device_index, | ||
device_type=self.beforeStreams[d].device_type) | ||
""" | ||
torch.cuda.set_stream(self.beforeStreams[d]) | ||
# torch._C._cuda_setDevice(beforeDevice) | ||
torch.cuda.set_device(beforeDevice) | ||
|
||
|
||
common_utils.CudaNonDefaultStream = CudaNonDefaultStream | ||
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,62 @@ | ||
import unittest | ||
import ditorch # noqa: F401 | ||
import sys | ||
import json | ||
|
||
|
||
def discover_test_cases_recursively(suite_or_case): | ||
if isinstance(suite_or_case, unittest.TestCase): | ||
return [suite_or_case] | ||
rc = [] | ||
for element in suite_or_case: | ||
rc.extend(discover_test_cases_recursively(element)) | ||
return rc | ||
|
||
|
||
def get_test_full_names(test_cases): | ||
full_name_list = [] | ||
for case in test_cases: | ||
id = case.id() | ||
module_name = id.split(".")[0] + ".py" | ||
test_name = id[id.find(".") + 1 :] | ||
full_name = module_name + " " + test_name | ||
full_name_list.append(full_name) | ||
return full_name_list | ||
|
||
|
||
def discover_all_test_case(path="."): | ||
loader = unittest.TestLoader() | ||
test_cases = loader.discover(path) | ||
test_cases = discover_test_cases_recursively(test_cases) | ||
return test_cases | ||
|
||
|
||
def dump_all_test_case_id_to_file(test_cases, path="all_test_cases.json"): | ||
test_case_ids = {} | ||
case_num = 0 | ||
for case in test_cases: | ||
case_id = case.id() | ||
print(case_id) | ||
case_num += 1 | ||
module_name = case_id.split(".")[0] + ".py" | ||
test_name = case_id[case_id.find(".") + 1 :] | ||
if not module_name.startswith("test_"): | ||
continue | ||
|
||
if module_name not in test_case_ids: | ||
test_case_ids[module_name] = [test_name] | ||
else: | ||
test_case_ids[module_name].append(test_name) | ||
|
||
with open(path, "wt") as f: | ||
json.dump(test_case_ids, f) | ||
|
||
print(f"dumped {case_num} test cases from {len(test_case_ids)} files to {path}") | ||
return test_case_ids | ||
|
||
|
||
if __name__ == "__main__": | ||
print(f"discover:{sys.argv}") | ||
path = sys.argv[1] if len(sys.argv) > 1 else "." | ||
all_tests_case = discover_all_test_case(path) | ||
dump_all_test_case_id_to_file(all_tests_case) |
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