-
Notifications
You must be signed in to change notification settings - Fork 629
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
Improve support for DALI enum types #5422
Conversation
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" |
There was a problem hiding this comment.
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>
!build |
CI MESSAGE: [14198822]: BUILD STARTED |
!build |
CI MESSAGE: [14199589]: BUILD STARTED |
CI MESSAGE: [14199589]: BUILD FAILED |
Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
!build |
CI MESSAGE: [14246341]: BUILD STARTED |
CI MESSAGE: [14246341]: BUILD PASSED |
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:
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:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A