Skip to content

Commit

Permalink
Check for non-contiguous, enable some Tensor tests, update oneapi doc…
Browse files Browse the repository at this point in the history
…ker image to latest.
  • Loading branch information
ssheorey committed May 18, 2024
1 parent 96de934 commit 17c73ae
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
15 changes: 11 additions & 4 deletions cpp/open3d/core/kernel/UnaryEWSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,25 @@ void CopySYCL(const Tensor& src, Tensor& dst) {
Dtype src_dtype = src.GetDtype();
Dtype dst_dtype = dst.GetDtype();
Device dst_device = dst.GetDevice();
Device src_device = src.GetDevice();

if (src_dtype != dst_dtype) {
utility::LogError("CopySYCL: src and dst must have the same dtype");
utility::LogError(
"CopySYCL: Dtype conversion from src to dst not implemented!");
}
if (dst_device.IsSYCL() && !dst.IsContiguous() ||
src_device.IsSYCL() && !src.IsContiguous()) {
utility::LogError(
"CopySYCL: NonContiguous SYCL tensor Copy not implemented!");
}
Tensor src_conti = src.Contiguous(); // No op if already contiguous
if (dst.IsContiguous() && src.GetShape() == dst.GetShape() &&
src_dtype == dst_dtype) {
MemoryManager::Memcpy(dst.GetDataPtr(), dst_device,
src_conti.GetDataPtr(), src_conti.GetDevice(),
src_dtype.ByteSize() * shape.NumElements());
src_conti.GetDataPtr(), src_conti.GetDevice(),
src_dtype.ByteSize() * shape.NumElements());
} else {
dst.CopyFrom(src.Contiguous().To(dst_device));
dst.CopyFrom(src_conti.To(dst_device));
}
}

Expand Down
30 changes: 20 additions & 10 deletions cpp/tests/core/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ INSTANTIATE_TEST_SUITE_P(Tensor,
testing::ValuesIn(PermuteDevices::TestCases()));

class TensorPermuteDevicesWithSYCL : public PermuteDevices {};
INSTANTIATE_TEST_SUITE_P(Tensor,
TensorPermuteDevicesWithSYCL,
testing::ValuesIn(PermuteDevicesWithSYCL::TestCases()));
INSTANTIATE_TEST_SUITE_P(
Tensor,
TensorPermuteDevicesWithSYCL,
testing::ValuesIn(PermuteDevicesWithSYCL::TestCases()));

class TensorPermuteDevicePairs : public PermuteDevicePairs {};
INSTANTIATE_TEST_SUITE_P(
Tensor,
TensorPermuteDevicePairs,
testing::ValuesIn(TensorPermuteDevicePairs::TestCases()));

class TensorPermuteDevicePairsWithSYCL : public PermuteDevicePairsWithSYCL {};
INSTANTIATE_TEST_SUITE_P(
Tensor,
TensorPermuteDevicePairsWithSYCL,
testing::ValuesIn(TensorPermuteDevicePairsWithSYCL::TestCases()));

class TensorPermuteSizesDefaultStridesAndDevices
: public testing::TestWithParam<
std::tuple<std::pair<core::SizeVector, core::SizeVector>,
Expand Down Expand Up @@ -303,7 +310,7 @@ TEST_P(TensorPermuteDevicePairs, IndexSetFillFancy) {
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0}));
}

TEST_P(TensorPermuteDevicePairs, Copy) {
TEST_P(TensorPermuteDevicePairsWithSYCL, Copy) {
core::Device dst_device;
core::Device src_device;
std::tie(dst_device, src_device) = GetParam();
Expand All @@ -322,7 +329,7 @@ TEST_P(TensorPermuteDevicePairs, Copy) {
EXPECT_EQ(dst_t.ToFlatVector<float>(), vals);
}

TEST_P(TensorPermuteDevicePairs, CopyBool) {
TEST_P(TensorPermuteDevicePairsWithSYCL, CopyBool) {
core::Device dst_device;
core::Device src_device;
std::tie(dst_device, src_device) = GetParam();
Expand All @@ -341,7 +348,7 @@ TEST_P(TensorPermuteDevicePairs, CopyBool) {
EXPECT_EQ(dst_t.ToFlatVector<bool>(), vals);
}

TEST_P(TensorPermuteDevicesWithSYCL, To) {
TEST_P(TensorPermuteDevices, To) {
core::Device device = GetParam();
core::SizeVector shape{2, 3};

Expand All @@ -362,12 +369,15 @@ TEST_P(TensorPermuteDevicePairs, ToDevice) {
core::Device src_device;
std::tie(dst_device, src_device) = GetParam();

core::Tensor src_t = core::Tensor::Init<float>({0, 1, 2, 3}, src_device);
core::Tensor src_t =
core::Tensor::Init<float>({0.f, 1.f, 2.f, 3.f}, src_device);
core::Tensor dst_t = src_t.To(dst_device);
EXPECT_TRUE(dst_t.To(src_device).AllClose(src_t));

EXPECT_ANY_THROW(src_t.To(core::Device("CPU:1")));

EXPECT_ANY_THROW(src_t.To(core::Device("SYCL:100")));

EXPECT_ANY_THROW(src_t.To(core::Device("CUDA:-1")));
EXPECT_ANY_THROW(src_t.To(core::Device("CUDA:100000")));
}
Expand All @@ -393,7 +403,7 @@ TEST_P(TensorPermuteDevicePairs, CopyBroadcast) {
EXPECT_EQ(dst_t.ToFlatVector<float>(), dst_vals);
}

TEST_P(TensorPermuteDevicesWithSYCL, Expand) {
TEST_P(TensorPermuteDevices, Expand) {
core::Device device = GetParam();
core::Dtype dtype(core::Float32);

Expand All @@ -413,7 +423,7 @@ TEST_P(TensorPermuteDevicesWithSYCL, Expand) {
EXPECT_EQ(dst_t.GetDataPtr(), src_t.GetDataPtr());
}

TEST_P(TensorPermuteDevicesWithSYCL, Flatten) {
TEST_P(TensorPermuteDevices, Flatten) {
core::Device device = GetParam();

// Flatten 0-D Tensor.
Expand Down Expand Up @@ -743,7 +753,7 @@ TEST_P(TensorPermuteDevicesWithSYCL, ToString) {
[True False False]])");
}

TEST_P(TensorPermuteDevicePairs, CopyContiguous) {
TEST_P(TensorPermuteDevicePairsWithSYCL, CopyContiguous) {
core::Device dst_device;
core::Device src_device;
std::tie(dst_device, src_device) = GetParam();
Expand Down
15 changes: 9 additions & 6 deletions docker/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,21 @@ ENV PATH="/root/miniconda3/bin:${PATH}"
ENV PATH="/root/miniconda3/envs/open3d/bin:${PATH}"
ENV PATH="/opt/intel/oneapi/intelpython/latest/bin:${PATH}"
ENV PATH="/opt/intel/oneapi/intelpython/latest/envs/open3d/bin:${PATH}"
RUN wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm Miniconda3-latest-Linux-x86_64.sh \
&& conda --version
RUN if [ "${BUILD_SYCL_MODULE}" = "OFF" ]; then \
wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh; \
bash Miniconda3-latest-Linux-x86_64.sh -b; \
rm Miniconda3-latest-Linux-x86_64.sh; \
conda create -y -n open3d python=${PYTHON_VERSION}; \
else \
conda config --add channels intel \
&& conda create -y -n open3d intelpython3_core python=${PYTHON_VERSION}; \
fi
RUN conda --version \
&& conda create -y -n open3d python=${PYTHON_VERSION}

# Activate open3d virtualenv
# This works during docker build. It becomes the prefix of all RUN commands.
# Ref: https://stackoverflow.com/a/60148365/1255535
SHELL ["conda", "run", "-n", "open3d", "/bin/bash", "-c"]
SHELL ["conda", "run", "-n", "open3d", "/bin/bash", "-o", "pipefail", "-c"]

# Dependencies: cmake
ENV PATH=${HOME}/${CMAKE_VERSION}/bin:${PATH}
Expand Down

0 comments on commit 17c73ae

Please sign in to comment.