Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
ssheorey committed Dec 27, 2024
1 parent c325213 commit 8db6e35
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 87 deletions.
2 changes: 1 addition & 1 deletion cpp/open3d/core/Indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ class Indexer {
class IndexerIterator {
public:
struct Iterator {
Iterator() {};
Iterator(){};
Iterator(const Indexer& indexer);
Iterator(Iterator&& other) = default;

Expand Down
10 changes: 8 additions & 2 deletions cpp/open3d/core/Tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ class Tensor : public IsDevice {

/// Underlying memory buffer for Tensor.
std::shared_ptr<Blob> blob_ = nullptr;
}; // namespace core
};

template <>
inline Tensor::Tensor(const std::vector<bool>& init_vals,
Expand Down Expand Up @@ -1425,5 +1425,11 @@ inline Tensor operator/(T scalar_lhs, const Tensor& rhs) {
return Tensor::Full({}, scalar_lhs, rhs.GetDtype(), rhs.GetDevice()) / rhs;
}

inline void AssertNotSYCL(const Tensor& tensor) {
if (tensor.GetDevice().IsSYCL()) {
utility::LogError("Not supported for SYCL device.");
}
}

} // namespace core
} // namespace open3d
} // namespace open3d
11 changes: 1 addition & 10 deletions cpp/open3d/core/kernel/UnaryEWSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void CopySYCL(const Tensor& src, Tensor& dst) {
src.GetDataPtr(), src.GetDevice(),
src_dtype.ByteSize() * shape.NumElements());
} else if (dst.NumElements() > 1 && dst.IsContiguous() &&
src.NumElements() == 1 /*&& !src_dtype.IsObject()*/) {
src.NumElements() == 1 && !src_dtype.IsObject()) {
int64_t num_elements = dst.NumElements();
DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(dst_dtype, [&]() {
scalar_t scalar_element = src.To(dst_dtype).Item<scalar_t>();
Expand Down Expand Up @@ -201,14 +201,6 @@ void UnaryEWSYCL(const Tensor& src, Tensor& dst, UnaryEWOpCode op_code) {
Dtype dst_dtype = dst.GetDtype();
Device device = src.GetDevice(); // == dst.GetDevice()

auto assert_dtype_is_float = [](Dtype dtype) -> void {
if (dtype != Float32 && dtype != Float64) {
utility::LogError(
"Only supports Float32 and Float64, but {} is used.",
dtype.ToString());
}
};

if (op_code == UnaryEWOpCode::LogicalNot) {
if (dst_dtype == src_dtype) {
Indexer indexer({src}, dst, DtypePolicy::ALL_SAME);
Expand All @@ -230,7 +222,6 @@ void UnaryEWSYCL(const Tensor& src, Tensor& dst, UnaryEWOpCode op_code) {
} else if (op_code == UnaryEWOpCode::IsNan ||
op_code == UnaryEWOpCode::IsInf ||
op_code == UnaryEWOpCode::IsFinite) {
assert_dtype_is_float(src_dtype);
Indexer indexer({src}, dst, DtypePolicy::INPUT_SAME_OUTPUT_BOOL);
DISPATCH_DTYPE_TO_TEMPLATE(src_dtype, [&]() {
if (op_code == UnaryEWOpCode::IsNan) {
Expand Down
6 changes: 4 additions & 2 deletions cpp/open3d/core/nns/NearestNeighborSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ class NearestNeighborSearch {
/// Constructor.
///
/// \param dataset_points Dataset points for constructing search index. Must
/// be 2D, with shape {n, d}.
/// be 2D, with shape {n, d}. SYCL tensors are not yet supported.
// NearestNeighborSearch(const Tensor &dataset_points)
// : dataset_points_(dataset_points){};
NearestNeighborSearch(const Tensor &dataset_points,
const Dtype &index_dtype = core::Int32)
: dataset_points_(dataset_points), index_dtype_(index_dtype){};
: dataset_points_(dataset_points), index_dtype_(index_dtype) {
AssertNotSYCL(dataset_points_);
};
~NearestNeighborSearch();
NearestNeighborSearch(const NearestNeighborSearch &) = delete;
NearestNeighborSearch &operator=(const NearestNeighborSearch &) = delete;
Expand Down
7 changes: 3 additions & 4 deletions cpp/tests/core/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ namespace open3d {
namespace tests {

class BlobPermuteDevices : public PermuteDevicesWithSYCL {};
INSTANTIATE_TEST_SUITE_P(
Blob,
BlobPermuteDevices,
testing::ValuesIn(PermuteDevicesWithSYCL::TestCases()));
INSTANTIATE_TEST_SUITE_P(Blob,
BlobPermuteDevices,
testing::ValuesIn(BlobPermuteDevices::TestCases()));

TEST_P(BlobPermuteDevices, BlobConstructor) {
core::Device device = GetParam();
Expand Down
8 changes: 3 additions & 5 deletions cpp/tests/core/CoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void PrintTo(const Device &device, std::ostream *os) {
}
void PrintTo(const Dtype &dtype, std::ostream *os) { *os << dtype.ToString(); }
} // namespace core

namespace tests {

std::vector<core::Dtype> PermuteDtypesWithBool::TestCases() {
Expand Down Expand Up @@ -51,8 +52,6 @@ std::vector<core::Device> PermuteDevices::TestCases() {
devices.push_back(cuda_devices[0]);
devices.push_back(cuda_devices[1]);
}

utility::LogWarning("Total {} devices.", devices.size());
return devices;
}

Expand All @@ -61,7 +60,8 @@ std::vector<core::Device> PermuteDevicesWithSYCL::TestCases() {
std::vector<core::Device> sycl_devices =
core::Device::GetAvailableSYCLDevices();
if (!sycl_devices.empty()) {
devices.push_back(sycl_devices[0]); // only the first SYCL device
// devices.push_back(sycl_devices[0]); // only the first SYCL device
devices.insert(devices.end(), sycl_devices.begin(), sycl_devices.end());
}
return devices;
}
Expand Down Expand Up @@ -92,7 +92,6 @@ PermuteDevicePairs::TestCases() {
}
}
}

return device_pairs;
}

Expand Down Expand Up @@ -130,7 +129,6 @@ PermuteDevicePairsWithSYCL::TestCases() {
}
}
}

return device_pairs;
}

Expand Down
9 changes: 5 additions & 4 deletions cpp/tests/core/EigenConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
namespace open3d {
namespace tests {

class EigenConverterPermuteDevices : public PermuteDevices {};
INSTANTIATE_TEST_SUITE_P(EigenConverter,
EigenConverterPermuteDevices,
testing::ValuesIn(PermuteDevices::TestCases()));
class EigenConverterPermuteDevices : public PermuteDevicesWithSYCL {};
INSTANTIATE_TEST_SUITE_P(
EigenConverter,
EigenConverterPermuteDevices,
testing::ValuesIn(EigenConverterPermuteDevices::TestCases()));

TEST_P(EigenConverterPermuteDevices, TensorToEigenMatrix) {
core::Device device = GetParam();
Expand Down
32 changes: 16 additions & 16 deletions cpp/tests/core/Indexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
namespace open3d {
namespace tests {

class IndexerPermuteDevices : public PermuteDevices {};
class IndexerPermuteDevices : public PermuteDevicesWithSYCL {};
INSTANTIATE_TEST_SUITE_P(Indexer,
IndexerPermuteDevices,
testing::ValuesIn(PermuteDevices::TestCases()));
testing::ValuesIn(IndexerPermuteDevices::TestCases()));

TEST_P(IndexerPermuteDevices, TensorRef) {
core::Device device = GetParam();
Expand Down Expand Up @@ -57,7 +57,7 @@ TEST_P(IndexerPermuteDevices, IndexerCopyConstructor) {

core::Tensor input0({2, 1, 1, 3}, core::Float32, device);
core::Tensor input1({1, 3}, core::Float32, device);
core::Tensor output({2, 2, 2, 1, 3}, core::Float32, device);
core::Tensor output({2, 2, 1, 3}, core::Float32, device);
core::Indexer indexer_a({input0, input1}, output);
core::Indexer indexer_b = indexer_a;

Expand All @@ -80,48 +80,48 @@ TEST_P(IndexerPermuteDevices, BroadcastRestride) {

core::Tensor input0({2, 1, 1, 3}, core::Float32, device);
core::Tensor input1({1, 3}, core::Float32, device);
core::Tensor output({2, 2, 2, 1, 3}, core::Float32, device);
core::Tensor output({2, 2, 1, 3}, core::Float32, device);
core::Indexer indexer({input0, input1}, output);

core::TensorRef input0_tr = indexer.GetInput(0);
core::TensorRef input1_tr = indexer.GetInput(1);
core::TensorRef output_tr = indexer.GetOutput();

EXPECT_EQ(input0_tr.ndims_, 5);
EXPECT_EQ(input1_tr.ndims_, 5);
EXPECT_EQ(output_tr.ndims_, 5);
EXPECT_EQ(input0_tr.ndims_, 4);
EXPECT_EQ(input1_tr.ndims_, 4);
EXPECT_EQ(output_tr.ndims_, 4);

// Check core::Indexer's global info
EXPECT_EQ(indexer.NumInputs(), 2);
EXPECT_EQ(indexer.NumWorkloads(), 24);
EXPECT_EQ(indexer.NumWorkloads(), 12);
EXPECT_EQ(core::SizeVector(indexer.GetPrimaryShape(),
indexer.GetPrimaryShape() + indexer.NumDims()),
core::SizeVector({2, 2, 2, 1, 3}));
core::SizeVector({2, 2, 1, 3}));
EXPECT_EQ(core::SizeVector(indexer.GetPrimaryStrides(),
indexer.GetPrimaryStrides() + indexer.NumDims()),
core::SizeVector({12, 6, 3, 3, 1}));
core::SizeVector({6, 3, 3, 1}));

// Check tensor shape
EXPECT_EQ(core::SizeVector(input0_tr.shape_,
input0_tr.shape_ + input0_tr.ndims_),
core::SizeVector({1, 2, 1, 1, 3}));
core::SizeVector({2, 1, 1, 3}));
EXPECT_EQ(core::SizeVector(input1_tr.shape_,
input1_tr.shape_ + input1_tr.ndims_),
core::SizeVector({1, 1, 1, 1, 3}));
core::SizeVector({1, 1, 1, 3}));
EXPECT_EQ(core::SizeVector(output_tr.shape_,
output_tr.shape_ + output_tr.ndims_),
core::SizeVector({2, 2, 2, 1, 3}));
core::SizeVector({2, 2, 1, 3}));

// Check tensor strides
EXPECT_EQ(core::SizeVector(input0_tr.byte_strides_,
input0_tr.byte_strides_ + input0_tr.ndims_),
core::SizeVector({0, 3 * 4, 0, 3 * 4, 1 * 4}));
core::SizeVector({3 * 4, 0, 3 * 4, 1 * 4}));
EXPECT_EQ(core::SizeVector(input1_tr.byte_strides_,
input1_tr.byte_strides_ + input1_tr.ndims_),
core::SizeVector({0, 0, 0, 3 * 4, 1 * 4}));
core::SizeVector({0, 0, 3 * 4, 1 * 4}));
EXPECT_EQ(core::SizeVector(output_tr.byte_strides_,
output_tr.byte_strides_ + output_tr.ndims_),
core::SizeVector({12 * 4, 6 * 4, 3 * 4, 3 * 4, 1 * 4}));
core::SizeVector({6 * 4, 3 * 4, 3 * 4, 1 * 4}));
}

TEST_P(IndexerPermuteDevices, GetPointers) {
Expand Down
7 changes: 3 additions & 4 deletions cpp/tests/core/Linalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ namespace open3d {
namespace tests {

class LinalgPermuteDevices : public PermuteDevicesWithSYCL {};
INSTANTIATE_TEST_SUITE_P(
Linalg,
LinalgPermuteDevices,
testing::ValuesIn(PermuteDevicesWithSYCL::TestCases()));
INSTANTIATE_TEST_SUITE_P(Linalg,
LinalgPermuteDevices,
testing::ValuesIn(LinalgPermuteDevices::TestCases()));

TEST_P(LinalgPermuteDevices, Matmul) {
const float EPSILON = 1e-8;
Expand Down
7 changes: 4 additions & 3 deletions cpp/tests/core/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ namespace open3d {
namespace tests {

class MemoryManagerPermuteDevices : public PermuteDevicesWithSYCL {};
INSTANTIATE_TEST_SUITE_P(MemoryManager,
MemoryManagerPermuteDevices,
testing::ValuesIn(PermuteDevices::TestCases()));
INSTANTIATE_TEST_SUITE_P(
MemoryManager,
MemoryManagerPermuteDevices,
testing::ValuesIn(MemoryManagerPermuteDevices::TestCases()));

class MemoryManagerPermuteDevicePairs : public PermuteDevicePairsWithSYCL {};
INSTANTIATE_TEST_SUITE_P(
Expand Down
1 change: 1 addition & 0 deletions cpp/tests/core/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3136,6 +3136,7 @@ TEST_P(TensorPermuteDevicesWithSYCL, ReduceMean) {

TEST_P(TensorPermuteDevicesWithSYCL, ToDLPackFromDLPack) {
core::Device device = GetParam();
if (device.IsSYCL()) GTEST_SKIP() << "Not Implemented!";
core::Tensor src_t = core::Tensor::Init<float>(
{{{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}},
{{12, 13, 14, 15}, {16, 17, 18, 19}, {20, 21, 22, 23}}},
Expand Down
14 changes: 7 additions & 7 deletions cpp/tests/core/TensorCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
namespace open3d {
namespace tests {

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

TEST_P(TensorCheckPermuteDevicesWithSYCL, AssertTensorDtype) {
TEST_P(TensorCheckPermuteDevices, AssertTensorDtype) {
core::Device device = GetParam();
core::Tensor t = core::Tensor::Empty({}, core::Float32, device);

Expand Down Expand Up @@ -59,7 +59,7 @@ TEST_P(TensorCheckPermuteDevicesWithSYCL, AssertTensorDtype) {
}
}

TEST_P(TensorCheckPermuteDevicesWithSYCL, AssertTensorDtypes) {
TEST_P(TensorCheckPermuteDevices, AssertTensorDtypes) {
core::Device device = GetParam();
core::Tensor t = core::Tensor::Empty({}, core::Float32, device);

Expand Down Expand Up @@ -88,7 +88,7 @@ TEST_P(TensorCheckPermuteDevicesWithSYCL, AssertTensorDtypes) {
t, std::vector<core::Dtype>({core::Int32, core::Int64})));
}

TEST_P(TensorCheckPermuteDevicesWithSYCL, AssertTensorDevice) {
TEST_P(TensorCheckPermuteDevices, AssertTensorDevice) {
core::Device device = GetParam();
core::Tensor t = core::Tensor::Empty({}, core::Float32, device);

Expand All @@ -106,7 +106,7 @@ TEST_P(TensorCheckPermuteDevicesWithSYCL, AssertTensorDevice) {
}
}

TEST_P(TensorCheckPermuteDevicesWithSYCL, AssertTensorShape) {
TEST_P(TensorCheckPermuteDevices, AssertTensorShape) {
core::Device device = GetParam();
core::Tensor t;

Expand Down
17 changes: 9 additions & 8 deletions cpp/tests/core/TensorFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
namespace open3d {
namespace tests {

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

TEST_P(TensorFunctionPermuteDevicesWithSYCL, Concatenate) {
TEST_P(TensorFunctionPermuteDevices, Concatenate) {
core::Device device = GetParam();

core::Tensor a, b, c, output_tensor;
Expand Down Expand Up @@ -111,7 +112,7 @@ TEST_P(TensorFunctionPermuteDevicesWithSYCL, Concatenate) {
}
}

TEST_P(TensorFunctionPermuteDevicesWithSYCL, Append) {
TEST_P(TensorFunctionPermuteDevices, Append) {
core::Device device = GetParam();

core::Tensor self, other, output;
Expand Down Expand Up @@ -215,7 +216,7 @@ TEST_P(TensorFunctionPermuteDevicesWithSYCL, Append) {
EXPECT_TRUE(core::Append(self, other).AllClose(self.Append(other)));
}

TEST_P(TensorFunctionPermuteDevicesWithSYCL, Maximum) {
TEST_P(TensorFunctionPermuteDevices, Maximum) {
core::Device device = GetParam();

core::Tensor input, other, output;
Expand Down Expand Up @@ -268,7 +269,7 @@ TEST_P(TensorFunctionPermuteDevicesWithSYCL, Maximum) {
core::Tensor::Init<bool>({true, true, true, true}, device)));
}

TEST_P(TensorFunctionPermuteDevicesWithSYCL, Minimum) {
TEST_P(TensorFunctionPermuteDevices, Minimum) {
core::Device device = GetParam();

core::Tensor input, other, output;
Expand Down
9 changes: 5 additions & 4 deletions cpp/tests/core/TensorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
namespace open3d {
namespace tests {

class TensorListPermuteDevices : public PermuteDevices {};
INSTANTIATE_TEST_SUITE_P(TensorList,
TensorListPermuteDevices,
testing::ValuesIn(PermuteDevices::TestCases()));
class TensorListPermuteDevices : public PermuteDevicesWithSYCL {};
INSTANTIATE_TEST_SUITE_P(
TensorList,
TensorListPermuteDevices,
testing::ValuesIn(TensorListPermuteDevices::TestCases()));

TEST_P(TensorListPermuteDevices, EmptyConstructor) {
core::Device device = GetParam();
Expand Down
Loading

0 comments on commit 8db6e35

Please sign in to comment.