Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
f1f53d0f
Commit
f1f53d0f
authored
Sep 05, 2023
by
xiabo
Browse files
适配rocm
parent
fc038a38
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
18 deletions
+70
-18
setup.py
setup.py
+52
-0
tests/test_ops/test_carafe.py
tests/test_ops/test_carafe.py
+5
-5
tests/test_ops/test_cc_attention.py
tests/test_ops/test_cc_attention.py
+2
-2
tests/test_ops/test_furthest_point_sample.py
tests/test_ops/test_furthest_point_sample.py
+2
-2
tests/test_ops/test_masked_conv2d.py
tests/test_ops/test_masked_conv2d.py
+5
-5
tests/test_ops/test_psa_mask.py
tests/test_ops/test_psa_mask.py
+4
-4
No files found.
setup.py
View file @
f1f53d0f
...
...
@@ -36,7 +36,59 @@ def choose_requirement(primary, secondary):
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
():
get_version_add
()
version_file
=
'mmcv/version.py'
with
open
(
version_file
,
encoding
=
'utf-8'
)
as
f
:
exec
(
compile
(
f
.
read
(),
version_file
,
'exec'
))
...
...
tests/test_ops/test_carafe.py
View file @
f1f53d0f
...
...
@@ -48,15 +48,15 @@ class TestCarafe:
pytest
.
skip
(
'test requires compilation'
)
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
(
'
tests
/data/for_carafe/carafe_mask.bin'
,
dtype
=
np
.
float32
)
'
.
/data/for_carafe/carafe_mask.bin'
,
dtype
=
np
.
float32
)
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
(
'
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
(
'
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_mask
=
np_mask
.
reshape
((
2
,
100
,
6
,
6
))
...
...
tests/test_ops/test_cc_attention.py
View file @
f1f53d0f
...
...
@@ -24,10 +24,10 @@ class TestCrissCrossAttention:
loss_func
=
Loss
()
input
=
np
.
fromfile
(
'
tests
/data/for_ccattention/ccattention_input.bin'
,
'
.
/data/for_ccattention/ccattention_input.bin'
,
dtype
=
np
.
float32
)
output
=
np
.
fromfile
(
'
tests
/data/for_ccattention/ccattention_output.bin'
,
'
.
/data/for_ccattention/ccattention_output.bin'
,
dtype
=
np
.
float32
)
input
=
input
.
reshape
((
1
,
32
,
45
,
45
))
output
=
output
.
reshape
((
1
,
32
,
45
,
45
))
...
...
tests/test_ops/test_furthest_point_sample.py
View file @
f1f53d0f
...
...
@@ -41,9 +41,9 @@ def test_fps_with_dist():
assert
torch
.
all
(
idx
==
expected_idx
)
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
(
'
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
()
features_for_fps_distance
=
torch
.
from_numpy
(
features_for_fps_distance
).
cuda
()
...
...
tests/test_ops/test_masked_conv2d.py
View file @
f1f53d0f
...
...
@@ -21,15 +21,15 @@ class TestMaskedConv2d:
def
test_masked_conv2d_all_close
(
self
,
device
):
from
mmcv.ops
import
MaskedConv2d
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
(
'
tests
/data/for_masked_conv2d/masked_conv2d_for_mask.npy'
)
'
.
/data/for_masked_conv2d/masked_conv2d_for_mask.npy'
)
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
(
'
tests
/data/for_masked_conv2d/masked_conv2d_for_bias.npy'
)
'
.
/data/for_masked_conv2d/masked_conv2d_for_bias.npy'
)
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
)
mask
=
torch
.
tensor
(
np_mask
,
dtype
=
torch
.
float
,
device
=
device
)
weight
=
torch
.
tensor
(
np_weight
,
dtype
=
torch
.
float
,
device
=
device
)
...
...
tests/test_ops/test_psa_mask.py
View file @
f1f53d0f
...
...
@@ -39,9 +39,9 @@ class TestPSAMask:
test_loss
=
Loss
()
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
(
'
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
))
output_collect
=
output_collect
.
reshape
((
4
,
64
,
8
,
8
))
...
...
@@ -91,9 +91,9 @@ class TestPSAMask:
test_loss
=
Loss
()
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
(
'
tests
/data/for_psa_mask/psa_output_distribute.bin'
,
'
.
/data/for_psa_mask/psa_output_distribute.bin'
,
dtype
=
np
.
float32
)
input
=
input
.
reshape
((
4
,
16
,
8
,
8
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment