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

C API 2.0 Tensor and TensorList #5799

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dali/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright (c) 2017-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,6 +46,7 @@ if (BUILD_DALI_PIPELINE)
add_subdirectory(util)
add_subdirectory(plugin)
add_subdirectory(c_api)
add_subdirectory(c_api_2)
endif()

if(BUILD_DALI_OPERATORS)
Expand Down
21 changes: 21 additions & 0 deletions dali/c_api_2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Get all the source files

# The headers here are private and should not be installed.
# collect_headers(DALI_INST_HDRS PARENT_SCOPE)

collect_sources(DALI_SRCS PARENT_SCOPE)
collect_test_sources(DALI_TEST_SRCS PARENT_SCOPE)
75 changes: 75 additions & 0 deletions dali/c_api_2/c_api_internal_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>
#include <stdexcept>
#define DALI_ALLOW_NEW_C_API
#include "dali/dali.h"
#include "dali/c_api_2/error_handling.h"
#include "dali/core/cuda_error.h"

namespace dali {

template <typename ExceptionType>
daliResult_t ThrowAndTranslate(ExceptionType &&ex) {
DALI_PROLOG();
throw std::forward<ExceptionType>(ex);
DALI_EPILOG();
}

template <typename ExceptionType>
void CheckException(ExceptionType &&ex, daliResult_t expected_result) {
std::string message(ex.what());
daliResult_t ret = ThrowAndTranslate(std::forward<ExceptionType>(ex));
EXPECT_EQ(ret, expected_result);
EXPECT_EQ(daliGetLastError(), expected_result);
EXPECT_EQ(daliGetLastErrorMessage(), message);
std::cout << daliGetErrorName(ret) << " "
<< daliGetLastErrorMessage() << std::endl;
daliClearLastError();
EXPECT_EQ(daliGetLastError(), DALI_SUCCESS);
EXPECT_STREQ(daliGetLastErrorMessage(), "");
}

TEST(CAPI2InternalTest, ErrorTranslation) {
CheckException(std::runtime_error("Runtime Error"), DALI_ERROR_INVALID_OPERATION);
CheckException(std::bad_alloc(), DALI_ERROR_OUT_OF_MEMORY);
CheckException(CUDABadAlloc(), DALI_ERROR_OUT_OF_MEMORY);
CheckException(std::logic_error("Logic dictates that it's an error"), DALI_ERROR_INTERNAL);
CheckException(std::out_of_range("Bullet left the shooting range"), DALI_ERROR_OUT_OF_RANGE);
CheckException(invalid_key("This key doesn't fit into the keyhole."), DALI_ERROR_INVALID_KEY);

CheckException(std::system_error(std::make_error_code(std::errc::no_such_file_or_directory)),
DALI_ERROR_PATH_NOT_FOUND);
CheckException(std::system_error(std::make_error_code(std::errc::no_such_device_or_address)),
DALI_ERROR_PATH_NOT_FOUND);

CheckException(std::system_error(std::make_error_code(std::errc::no_space_on_device)),
DALI_ERROR_IO_ERROR);
CheckException(std::system_error(
std::make_error_code(std::errc::inappropriate_io_control_operation)),
DALI_ERROR_IO_ERROR);
CheckException(std::system_error(std::make_error_code(std::io_errc::stream)),
DALI_ERROR_IO_ERROR);

CheckException(std::system_error(std::make_error_code(std::errc::not_enough_memory)),
DALI_ERROR_OUT_OF_MEMORY);

CheckException(std::system_error(std::make_error_code(std::errc::bad_file_descriptor)),
DALI_ERROR_SYSTEM);
CheckException(std::system_error(std::make_error_code(std::errc::too_many_files_open)),
DALI_ERROR_SYSTEM);
}

} // namespace dali
Loading
Loading