Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for DALI enum types #5422

Merged
merged 7 commits into from
Apr 16, 2024

Conversation

klecki
Copy link
Contributor

@klecki klecki commented Apr 10, 2024

Category: New feature

Description:

Support for DALI enum types (DALIDataType, DALIImageType, DALIInterpType) is added to Constant, Cast, Choice and Copy operators.

Thanks to Constant op support, followin syntax will work now:

fn.random.choice([types.DALIInterpType.INTERP_LINEAR, types.DALIInterpType.INTERP_NN])

allowing convenient selection of enum parameters.
Constant promotions insert constant nodes automatically.
When types.Constant is used, for true scalars the ScalarConstant placeholder is typically created.
For enum values we always use proper constant node as enums are not usable in artihmetic operations
and this is the main target of ScalarConstant.

Casting support is allowed only between non-fp types and enums.

Explicit error is raised when the enums are used with buffer protcol (conversion to numpy, printing etc) - Python expectes pointer-to-object representation there, while we return them as C-style enums with numeric value under the hood.
As an alternative we can allow to just access the underlying data but I have chosen a bit more restricive approach for now.

The values indicating the enum types were exposed in type hints for DALIDataType.

__rerp__ of Tensor and TensorList is adjusted to not access the underlying data (it is shown only for __str__).
It invokes buffer protocol to show the summary of data contents and in this case it is not possible. As the repr
is used in Python-produced errors, the actual error might have been obscured by trying to access data.

Additional information:

Affected modules and functionalities:

Enum support, type hints, several operators.

Key points relevant for the review:

Are there any additional operators that we might want to cover?
Equal/not equal comparisons between enum values?

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

Support for DALI enum types (DALIDataType, DALIImageType, DALIInterpType)
is added to Constant, Cast, Choice and Copy operators.

Thanks to Constant op support, followin syntax will work now:
```
fn.random.choice([types.DALIInterpType.INTERP_LINEAR, types.DALIInterpType.INTERP_NN])
```
allowing convenient selection of enum parameters.

Casting support is allowed only between non-fp types and enums.

Explicit error is raised when the enums are used with buffer protcol
(conversion to numpy, printing etc) - Python expectes pointer-to-object
representation there, while we return them as C-style enums with numeric
value under the hood.
As an alternative we can allow to just access the underlying data but I
have chosen a bit more restricive approach for now.

Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
@@ -19,6 +19,7 @@
#include "dali/kernels/common/utils.h"
#include "dali/kernels/kernel.h"
#include "dali/kernels/dynamic_scratchpad.h"
#include "dali/pipeline/data/types.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to pull the pipeline/data/types.h into kernel implementation here, to be able to instantiate the kernel for the DALIDataType etc.

Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
@klecki
Copy link
Contributor Author

klecki commented Apr 12, 2024

!build

dali/python/nvidia/dali/types.py Fixed Show fixed Hide fixed
dali/python/nvidia/dali/types.py Fixed Show fixed Hide fixed
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [14198822]: BUILD STARTED

Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
@klecki
Copy link
Contributor Author

klecki commented Apr 12, 2024

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [14199589]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [14199589]: BUILD FAILED

Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
@klecki
Copy link
Contributor Author

klecki commented Apr 15, 2024

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [14246341]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [14246341]: BUILD PASSED

@klecki klecki merged commit bc13f15 into NVIDIA:main Apr 16, 2024
7 checks passed
@klecki klecki deleted the support-dali-special-type-selection branch April 16, 2024 12:27
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants