Skip to content

Commit

Permalink
Introduce DALI proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>
  • Loading branch information
jantonguirao committed Nov 29, 2024
1 parent cc8356b commit caf2d0b
Show file tree
Hide file tree
Showing 18 changed files with 1,096 additions and 433 deletions.
4 changes: 2 additions & 2 deletions dali/c_api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "dali/c_api.h" // NOLINT [build/include]

#include <algorithm>
#include <string>
#include <utility>
Expand All @@ -32,8 +34,6 @@
#include "dali/pipeline/data/copy_to_external.h"
#include "dali/pipeline/operator/checkpointing/checkpoint.h"

#include "dali/c_api.h" // NOLINT [build/include]

using dali::AccessOrder;
using dali::CPUBackend;
using dali::GPUBackend;
Expand Down
209 changes: 201 additions & 8 deletions dali/pipeline/data/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <typeinfo>
#include <unordered_map>
#include <vector>
#include "dali/core/dali_data_type.h"
#include "dali/core/util.h"
#include "dali/core/common.h"
#include "dali/core/spinlock.h"
Expand Down Expand Up @@ -88,18 +87,212 @@ inline Copier GetCopier() {

} // namespace detail

using DALIDataType = daliDataType_t;
/**
* @brief Enum identifiers for the different data types that
* the pipeline can output.
*
* IMPORTANT: This enum is used for serialization of DALI Pipeline. Therefore, any change made to
* this enum must retain backward compatibility. If the backward compatibility is broken
* (e.g. values of enumerations are shuffled), the already serialized pipelines
* around the globe will stop working correctly.
*/
enum DALIDataType : int {
DALI_NO_TYPE = -1,
DALI_UINT8 = 0,
DALI_UINT16 = 1,
DALI_UINT32 = 2,
DALI_UINT64 = 3,
DALI_INT8 = 4,
DALI_INT16 = 5,
DALI_INT32 = 6,
DALI_INT64 = 7,
DALI_FLOAT16 = 8,
DALI_FLOAT = 9,
DALI_FLOAT64 = 10,
DALI_BOOL = 11,
DALI_STRING = 12,
DALI_BOOL_VEC = 13,
DALI_INT_VEC = 14,
DALI_STRING_VEC = 15,
DALI_FLOAT_VEC = 16,
#ifdef DALI_BUILD_PROTO3
DALI_TF_FEATURE = 17,
DALI_TF_FEATURE_VEC = 18,
DALI_TF_FEATURE_DICT = 19,
#endif // DALI_BUILD_PROTO3
DALI_IMAGE_TYPE = 20,
DALI_DATA_TYPE = 21,
DALI_INTERP_TYPE = 22,
DALI_TENSOR_LAYOUT = 23,
DALI_PYTHON_OBJECT = 24,
DALI_TENSOR_LAYOUT_VEC = 25,
DALI_DATA_TYPE_VEC = 26,
DALI_NUM_BUILTIN_TYPES,
DALI_CUSTOM_TYPE_START = 1001
};

inline const char *GetBuiltinTypeName(DALIDataType t) {
switch (t) {
case DALI_NO_TYPE:
return "<no_type>";
break;
case DALI_UINT8:
return "uint8";
break;
case DALI_UINT16:
return "uint16";
break;
case DALI_UINT32:
return "uint32";
break;
case DALI_UINT64:
return "uint64";
break;
case DALI_INT8:
return "int8";
break;
case DALI_INT16:
return "int16";
break;
case DALI_INT32:
return "int32";
break;
case DALI_INT64:
return "int64";
break;
case DALI_FLOAT16:
return "float16";
break;
case DALI_FLOAT:
return "float";
break;
case DALI_FLOAT64:
return "double";
break;
case DALI_BOOL:
return "bool";
break;
case DALI_STRING:
return "string";
break;
case DALI_BOOL_VEC:
return "list of bool";
break;
case DALI_INT_VEC:
return "list of int";
break;
case DALI_STRING_VEC:
return "list of string";
break;
case DALI_FLOAT_VEC:
return "list of float";
break;
#ifdef DALI_BUILD_PROTO3
case DALI_TF_FEATURE:
return "TFUtil::Feature";
break;
case DALI_TF_FEATURE_VEC:
return "list of TFUtil::Feature";
break;
case DALI_TF_FEATURE_DICT:
return "dictionary of TFUtil::Feature";
break;
#endif // DALI_BUILD_PROTO3
case DALI_IMAGE_TYPE:
return "DALIImageType";
break;
case DALI_DATA_TYPE:
return "DALIDataType";
break;
case DALI_INTERP_TYPE:
return "DALIInterpType";
break;
case DALI_TENSOR_LAYOUT:
return "TensorLayout";
break;
case DALI_PYTHON_OBJECT:
return "Python object";
break;
case DALI_TENSOR_LAYOUT_VEC:
return "list of TensorLayout";
break;
case DALI_DATA_TYPE_VEC:
return "list of DALIDataType";
default:
return nullptr;
}
}

inline std::string to_string(DALIDataType dtype);
inline std::ostream &operator<<(std::ostream &, DALIDataType dtype);

constexpr auto GetBuiltinTypeName = daliDataTypeName;
constexpr auto IsFloatingPoint = daliDataTypeIsFloatingPoint;
constexpr auto IsIntegral = daliDataTypeIsIntegral;
constexpr auto IsSigned = daliDataTypeIsSigned;
constexpr auto IsUnsigned = daliDataTypeIsUnsigned;
constexpr auto IsEnum = daliDataTypeIsEnum;
constexpr bool IsFloatingPoint(DALIDataType type) {
switch (type) {
case DALI_FLOAT16:
case DALI_FLOAT:
case DALI_FLOAT64:
return true;
default:
return false;
}
}

constexpr bool IsIntegral(DALIDataType type) {
switch (type) {
case DALI_BOOL:
case DALI_UINT8:
case DALI_UINT16:
case DALI_UINT32:
case DALI_UINT64:
case DALI_INT8:
case DALI_INT16:
case DALI_INT32:
case DALI_INT64:
return true;
default:
return false;
}
}

constexpr bool IsSigned(DALIDataType type) {
switch (type) {
case DALI_FLOAT16:
case DALI_FLOAT:
case DALI_FLOAT64:
case DALI_INT8:
case DALI_INT16:
case DALI_INT32:
case DALI_INT64:
return true;
default:
return false;
}
}

constexpr bool IsUnsigned(DALIDataType type) {
switch (type) {
case DALI_BOOL:
case DALI_UINT8:
case DALI_UINT16:
case DALI_UINT32:
case DALI_UINT64:
return true;
default:
return false;
}
}


constexpr bool IsEnum(DALIDataType type) {
switch (type) {
case DALI_DATA_TYPE:
case DALI_IMAGE_TYPE:
case DALI_INTERP_TYPE:
return true;
default:
return false;
}
}

template <DALIDataType id>
struct id2type_helper;
Expand Down
Loading

0 comments on commit caf2d0b

Please sign in to comment.