Commit f1f53d0f authored by xiabo's avatar xiabo
Browse files

适配rocm

parent fc038a38
...@@ -36,7 +36,59 @@ def choose_requirement(primary, secondary): ...@@ -36,7 +36,59 @@ def choose_requirement(primary, secondary):
return str(primary) return str(primary)
def get_sha(pytorch_root: Union[str, Path]) -> str:
try:
return subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=pytorch_root).decode('ascii').strip()
except Exception:
return 'Unknown'
def get_abi():
try:
command = "echo '#include <string>' | gcc -x c++ -E -dM - | fgrep _GLIBCXX_USE_CXX11_ABI"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
output = result.stdout.strip()
abi = "abi" + output.split(" ")[-1]
return abi
except Exception:
return 'abiUnknown'
def get_version_add(sha: Optional[str] = None) -> str:
version=''
mmcv_root = os.path.dirname(os.path.abspath(__file__))
add_version_path = os.path.join(os.path.join(mmcv_root, "mmcv"), "version.py")
if sha != 'Unknown':
if sha is None:
sha = get_sha(mmcv_root)
version = 'git' + sha[:7]
# abi
version += "." + get_abi()
# dtk version
if os.getenv("ROCM_PATH"):
rocm_path = os.getenv('ROCM_PATH', "")
rocm_version_path = os.path.join(rocm_path, '.info', "rocm_version")
with open(rocm_version_path, 'r',encoding='utf-8') as file:
lines = file.readlines()
rocm_version=lines[0][:-2].replace(".", "")
version += ".dtk" + rocm_version
# torch version
version += ".torch" + torch.__version__[:4]
lines=[]
with open(add_version_path, 'r',encoding='utf-8') as file:
lines = file.readlines()
lines[2] = "__dcu_version__ = '2.0.0+{}'\n".format(version)
with open(add_version_path, encoding="utf-8",mode="w") as file:
file.writelines(lines)
file.close()
def get_version(): def get_version():
get_version_add()
version_file = 'mmcv/version.py' version_file = 'mmcv/version.py'
with open(version_file, encoding='utf-8') as f: with open(version_file, encoding='utf-8') as f:
exec(compile(f.read(), version_file, 'exec')) exec(compile(f.read(), version_file, 'exec'))
......
...@@ -48,15 +48,15 @@ class TestCarafe: ...@@ -48,15 +48,15 @@ class TestCarafe:
pytest.skip('test requires compilation') pytest.skip('test requires compilation')
np_feat = np.fromfile( np_feat = np.fromfile(
'tests/data/for_carafe/carafe_feat.bin', dtype=np.float32) './data/for_carafe/carafe_feat.bin', dtype=np.float32)
np_mask = np.fromfile( np_mask = np.fromfile(
'tests/data/for_carafe/carafe_mask.bin', dtype=np.float32) './data/for_carafe/carafe_mask.bin', dtype=np.float32)
np_output = np.fromfile( np_output = np.fromfile(
'tests/data/for_carafe/carafe_output.bin', dtype=np.float32) './data/for_carafe/carafe_output.bin', dtype=np.float32)
np_feat_grad = np.fromfile( np_feat_grad = np.fromfile(
'tests/data/for_carafe/carafe_feat_grad.bin', dtype=np.float32) './data/for_carafe/carafe_feat_grad.bin', dtype=np.float32)
np_mask_grad = np.fromfile( np_mask_grad = np.fromfile(
'tests/data/for_carafe/carafe_mask_grad.bin', dtype=np.float32) './data/for_carafe/carafe_mask_grad.bin', dtype=np.float32)
np_feat = np_feat.reshape((2, 64, 3, 3)) np_feat = np_feat.reshape((2, 64, 3, 3))
np_mask = np_mask.reshape((2, 100, 6, 6)) np_mask = np_mask.reshape((2, 100, 6, 6))
......
...@@ -24,10 +24,10 @@ class TestCrissCrossAttention: ...@@ -24,10 +24,10 @@ class TestCrissCrossAttention:
loss_func = Loss() loss_func = Loss()
input = np.fromfile( input = np.fromfile(
'tests/data/for_ccattention/ccattention_input.bin', './data/for_ccattention/ccattention_input.bin',
dtype=np.float32) dtype=np.float32)
output = np.fromfile( output = np.fromfile(
'tests/data/for_ccattention/ccattention_output.bin', './data/for_ccattention/ccattention_output.bin',
dtype=np.float32) dtype=np.float32)
input = input.reshape((1, 32, 45, 45)) input = input.reshape((1, 32, 45, 45))
output = output.reshape((1, 32, 45, 45)) output = output.reshape((1, 32, 45, 45))
......
...@@ -41,9 +41,9 @@ def test_fps_with_dist(): ...@@ -41,9 +41,9 @@ def test_fps_with_dist():
assert torch.all(idx == expected_idx) assert torch.all(idx == expected_idx)
import numpy as np import numpy as np
fps_idx = np.load('tests/data/for_3d_ops/fps_idx.npy') fps_idx = np.load('./data/for_3d_ops/fps_idx.npy')
features_for_fps_distance = np.load( features_for_fps_distance = np.load(
'tests/data/for_3d_ops/features_for_fps_distance.npy') './data/for_3d_ops/features_for_fps_distance.npy')
expected_idx = torch.from_numpy(fps_idx).cuda() expected_idx = torch.from_numpy(fps_idx).cuda()
features_for_fps_distance = torch.from_numpy( features_for_fps_distance = torch.from_numpy(
features_for_fps_distance).cuda() features_for_fps_distance).cuda()
......
...@@ -21,15 +21,15 @@ class TestMaskedConv2d: ...@@ -21,15 +21,15 @@ class TestMaskedConv2d:
def test_masked_conv2d_all_close(self, device): def test_masked_conv2d_all_close(self, device):
from mmcv.ops import MaskedConv2d from mmcv.ops import MaskedConv2d
np_input = np.load( np_input = np.load(
'tests/data/for_masked_conv2d/masked_conv2d_for_input.npy') './data/for_masked_conv2d/masked_conv2d_for_input.npy')
np_mask = np.load( np_mask = np.load(
'tests/data/for_masked_conv2d/masked_conv2d_for_mask.npy') './data/for_masked_conv2d/masked_conv2d_for_mask.npy')
np_weight = np.load( np_weight = np.load(
'tests/data/for_masked_conv2d/masked_conv2d_for_weight.npy') './data/for_masked_conv2d/masked_conv2d_for_weight.npy')
np_bias = np.load( np_bias = np.load(
'tests/data/for_masked_conv2d/masked_conv2d_for_bias.npy') './data/for_masked_conv2d/masked_conv2d_for_bias.npy')
np_output = np.load( np_output = np.load(
'tests/data/for_masked_conv2d/masked_conv2d_for_output.npy') './data/for_masked_conv2d/masked_conv2d_for_output.npy')
input = torch.tensor(np_input, dtype=torch.float, device=device) input = torch.tensor(np_input, dtype=torch.float, device=device)
mask = torch.tensor(np_mask, dtype=torch.float, device=device) mask = torch.tensor(np_mask, dtype=torch.float, device=device)
weight = torch.tensor(np_weight, dtype=torch.float, device=device) weight = torch.tensor(np_weight, dtype=torch.float, device=device)
......
...@@ -39,9 +39,9 @@ class TestPSAMask: ...@@ -39,9 +39,9 @@ class TestPSAMask:
test_loss = Loss() test_loss = Loss()
input = np.fromfile( input = np.fromfile(
'tests/data/for_psa_mask/psa_input.bin', dtype=np.float32) './data/for_psa_mask/psa_input.bin', dtype=np.float32)
output_collect = np.fromfile( output_collect = np.fromfile(
'tests/data/for_psa_mask/psa_output_collect.bin', dtype=np.float32) './data/for_psa_mask/psa_output_collect.bin', dtype=np.float32)
input = input.reshape((4, 16, 8, 8)) input = input.reshape((4, 16, 8, 8))
output_collect = output_collect.reshape((4, 64, 8, 8)) output_collect = output_collect.reshape((4, 64, 8, 8))
...@@ -91,9 +91,9 @@ class TestPSAMask: ...@@ -91,9 +91,9 @@ class TestPSAMask:
test_loss = Loss() test_loss = Loss()
input = np.fromfile( input = np.fromfile(
'tests/data/for_psa_mask/psa_input.bin', dtype=np.float32) './data/for_psa_mask/psa_input.bin', dtype=np.float32)
output_distribute = np.fromfile( output_distribute = np.fromfile(
'tests/data/for_psa_mask/psa_output_distribute.bin', './data/for_psa_mask/psa_output_distribute.bin',
dtype=np.float32) dtype=np.float32)
input = input.reshape((4, 16, 8, 8)) input = input.reshape((4, 16, 8, 8))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment