MONAI icon indicating copy to clipboard operation
MONAI copied to clipboard

Cuda morphological hausdorff

Open jakubMitura14 opened this issue 3 years ago • 15 comments

about https://github.com/Project-MONAI/MONAI/discussions/4053

jakubMitura14 avatar Apr 05 '22 17:04 jakubMitura14

Thanks, could you please sign the commits and add the necessary copyright section, see: https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md#preparing-pull-requests

wyli avatar Apr 06 '22 08:04 wyli

Looks like we have some failing tests but no worries cause its just an import error. Looks like you need to import your new metirc in the __init__.py file of the metrics module.

I've added a few targeted comments for now, I would say the cuda file is quite long. Is there a sensible way to split it up? even just seperating some declarations into a well commented .cuh header file would provide a good entry point for people looking at the code.

charliebudd avatar Apr 06 '22 08:04 charliebudd

Deep thanks for your input @charliebudd, about dividing it into separate files, yes It was like that at the begining https://github.com/jakubMitura14/HousdorffHDF5cMake

But for some reasons particularly in cmake builds (rdc flag is on) occupancy gets lower when multiple files are used.

I also upload pdf with some description of the algorithm (work in progress), just for some reference. look into Algorithm description

Also can I ask how to run the tests locally, with all MONAI?. I mean I have locally the fork with CUDA Hausdorff Distance, and I want to check is it compiles, with the rest of MONAI.

For reference - working python pytorch extension - with benchmarks

Hausdorff.pdf

jakubMitura14 avatar Apr 06 '22 09:04 jakubMitura14

/black

wyli avatar Apr 06 '22 14:04 wyli

/black

wyli avatar Apr 09 '22 06:04 wyli

/black

wyli avatar Apr 12 '22 16:04 wyli

@wyli Hello could you run the workflows?

jakubMitura14 avatar Apr 21 '22 15:04 jakubMitura14

Hi @jakubMitura14 ,

I started the workflows, please sign-off the git commits.

Thanks.

Nic-Ma avatar Apr 21 '22 16:04 Nic-Ma

Hi @jakubMitura14 ,

I started the workflows, please sign-off the git commits.

Thanks.

Thanks @Nic-Ma ! I am signing commits now (I hope that correctly) only some first commits were not - what can I do with this?

Additionally I do not have the access currently to linux machine can I ask You, or somebody else to run

 style fixes: ./runtests.sh --autofix

Thanks!

jakubMitura14 avatar Apr 21 '22 18:04 jakubMitura14

Hi @jakubMitura14 , I started the workflows, please sign-off the git commits. Thanks.

Thanks @Nic-Ma ! I am signing commits now (I hope that correctly) only some first commits were not - what can I do with this?

Additionally I do not have the access currently to linux machine can I ask You, or somebody else to run

 style fixes: ./runtests.sh --autofix

Thanks!

I can help with this, but to do it more efficiently, would be great if you could review the code again, to remove the syntax errors such as: https://github.com/Project-MONAI/MONAI/blob/2ae038d44479e9578d08846d6d293c0eabe81bdb/monai/_extensions/hausdorff/hausdorff_cuda.cu#L2143-L2144

https://github.com/Project-MONAI/MONAI/blob/2ae038d44479e9578d08846d6d293c0eabe81bdb/monai/_extensions/hausdorff/hausdorff_cuda.cu#L2521

wyli avatar Apr 25 '22 09:04 wyli

Ok thanks !!

On Mon, Apr 25, 2022, 11:53 Wenqi Li @.***> wrote:

Hi @jakubMitura14 https://github.com/jakubMitura14 , I started the workflows, please sign-off the git commits. Thanks.

Thanks @Nic-Ma https://github.com/Nic-Ma ! I am signing commits now (I hope that correctly) only some first commits were not - what can I do with this?

Additionally I do not have the access currently to linux machine can I ask You, or somebody else to run

style fixes: ./runtests.sh --autofix

Thanks!

I can help with this, but to do it more efficiently, would be great if you could review the code again, to remove the syntax errors such as:

https://github.com/Project-MONAI/MONAI/blob/2ae038d44479e9578d08846d6d293c0eabe81bdb/monai/_extensions/hausdorff/hausdorff_cuda.cu#L2143-L2144

https://github.com/Project-MONAI/MONAI/blob/2ae038d44479e9578d08846d6d293c0eabe81bdb/monai/_extensions/hausdorff/hausdorff_cuda.cu#L2521

— Reply to this email directly, view it on GitHub https://github.com/Project-MONAI/MONAI/pull/4078#issuecomment-1108346782, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM24ZT2NWK2W2IP7FL2T5JTVGZTSVANCNFSM5STPDLXQ . You are receiving this because you were mentioned.Message ID: @.***>

jakubMitura14 avatar Apr 25 '22 15:04 jakubMitura14

there are some test errors, any idea?

======================================================================
ERROR: test_value_12 (tests.test_hausdorff_distance_morphologic.TestHausdorffDistanceMorphological)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
add_video needs package moviepy

    return func(*(a + p.args), **p.kwargs)
  File "/__w/MONAI/MONAI/tests/test_hausdorff_distance_morphologic.py", line 125, in test_value
    hd_metric = MorphologicalHausdorffDistanceMetric(
  File "/__w/MONAI/MONAI/monai/metrics/morphological_hausdorff_distance.py", line 88, in __init__
    self.compiled_extension = load_module("hausdorff")
  File "/__w/MONAI/MONAI/monai/_extensions/loader.py", line 86, in load_module
    module = load(
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1130, in load
    return _jit_compile(
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1368, in _jit_compile
    return _import_module_from_library(name, build_directory, is_python_module)
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1761, in _import_module_from_library
    module = importlib.util.module_from_spec(spec)
  File "<frozen importlib._bootstrap>", line 556, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1166, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: /github/home/.cache/torch_extensions/py38_cu116/hausdorff_Linux_3_8_12_112_11_6/hausdorff_Linux_3_8_12_112_11_6.so: undefined symbol: _Z25getHausdorffDistance_CUDAN2at6TensorES0_iiif

wyli avatar May 02 '22 17:05 wyli

there are some test errors, any idea?

======================================================================
ERROR: test_value_12 (tests.test_hausdorff_distance_morphologic.TestHausdorffDistanceMorphological)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
add_video needs package moviepy

    return func(*(a + p.args), **p.kwargs)
  File "/__w/MONAI/MONAI/tests/test_hausdorff_distance_morphologic.py", line 125, in test_value
    hd_metric = MorphologicalHausdorffDistanceMetric(
  File "/__w/MONAI/MONAI/monai/metrics/morphological_hausdorff_distance.py", line 88, in __init__
    self.compiled_extension = load_module("hausdorff")
  File "/__w/MONAI/MONAI/monai/_extensions/loader.py", line 86, in load_module
    module = load(
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1130, in load
    return _jit_compile(
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1368, in _jit_compile
    return _import_module_from_library(name, build_directory, is_python_module)
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1761, in _import_module_from_library
    module = importlib.util.module_from_spec(spec)
  File "<frozen importlib._bootstrap>", line 556, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1166, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: /github/home/.cache/torch_extensions/py38_cu116/hausdorff_Linux_3_8_12_112_11_6/hausdorff_Linux_3_8_12_112_11_6.so: undefined symbol: _Z25getHausdorffDistance_CUDAN2at6TensorES0_iiif

Frankly i do not know how the symbol _Z25getHausdorffDistance_CUDAN2at6TensorES0_iiif appears i suppose it is sth related to pybind but i do not figured it out yet what is the source of the problem

jakubMitura14 avatar May 02 '22 20:05 jakubMitura14

these commands would give more detailed error messages in colab GPU runtime: https://colab.research.google.com/drive/1szt-G4srXSRyJKpVuKiKhKYH9Mkbk5dO#scrollTo=q1YHjwlQqHi1 in case it's useful for debugging

wyli avatar May 03 '22 20:05 wyli

these commands would give more detailed error messages in colab GPU runtime: https://colab.research.google.com/drive/1szt-G4srXSRyJKpVuKiKhKYH9Mkbk5dO#scrollTo=q1YHjwlQqHi1 in case it's useful for debugging

Yes thanks ! it helps - but frankly i do not get why I have identifier "cudaMallocAsync" is undefined

this is perfectly valid cuda function locally it gave no such errors

hmm

jakubMitura14 avatar May 04 '22 17:05 jakubMitura14

Not sure if it is relevant, but the next cupy version will include a CUDA implementation for distance_transform_edt (so only for the euclidean distance case).

johnzielke avatar Aug 24 '23 22:08 johnzielke

Intresting - thanks !

jakubMitura14 avatar Aug 25 '23 06:08 jakubMitura14