Unverified Commit cded5b80 authored by Xin Yao's avatar Xin Yao Committed by GitHub
Browse files

[Feature] Bump DLPack to v0.7 and decouple DLPack from the core library (#4454)

* rename `DLContext` to `DGLContext`

* rename `kDLGPU` to `kDLCUDA`

* replace DLTensor with DGLArray

* fix linting

* Unify DGLType and DLDataType to DGLDataType

* Fix FFI

* rename DLDeviceType to DGLDeviceType

* decouple dlpack from the core library

* fix bug

* fix lint

* fix merge

* fix build

* address comments

* rename dl_converter to dlpack_convert

* remove redundant comments
parent f1689ad0
......@@ -29,8 +29,8 @@ class WorkspacePool::Pool {
nbytes = (nbytes + (kWorkspacePageSize - 1)) / kWorkspacePageSize * kWorkspacePageSize;
if (nbytes == 0) nbytes = kWorkspacePageSize;
Entry e;
DGLType type;
type.code = kDLUInt;
DGLDataType type;
type.code = kDGLUInt;
type.bits = 8;
type.lanes = 1;
if (free_list_.size() == 2) {
......@@ -113,7 +113,7 @@ class WorkspacePool::Pool {
std::vector<Entry> allocated_;
};
WorkspacePool::WorkspacePool(DLDeviceType device_type, std::shared_ptr<DeviceAPI> device)
WorkspacePool::WorkspacePool(DGLDeviceType device_type, std::shared_ptr<DeviceAPI> device)
: device_type_(device_type), device_(device) {
}
......
......@@ -30,7 +30,7 @@ class WorkspacePool {
* \param device_type The device type.
* \param device The device API.
*/
WorkspacePool(DLDeviceType device_type, std::shared_ptr<DeviceAPI> device);
WorkspacePool(DGLDeviceType device_type, std::shared_ptr<DeviceAPI> device);
/*! \brief destructor */
~WorkspacePool();
/*!
......@@ -52,7 +52,7 @@ class WorkspacePool {
/*! \brief pool of device local array */
std::vector<Pool*> array_;
/*! \brief device type this pool support */
DLDeviceType device_type_;
DGLDeviceType device_type_;
/*! \brief The device API */
std::shared_ptr<DeviceAPI> device_;
};
......
......@@ -3,10 +3,10 @@
#include <dgl/runtime/ndarray.h>
static constexpr DLContext CTX = DLContext{kDLCPU, 0};
static constexpr DLContext CPU = DLContext{kDLCPU, 0};
static constexpr DGLContext CTX = DGLContext{kDGLCPU, 0};
static constexpr DGLContext CPU = DGLContext{kDGLCPU, 0};
#ifdef DGL_USE_CUDA
static constexpr DLContext GPU = DLContext{kDLGPU, 0};
static constexpr DGLContext GPU = DGLContext{kDGLCUDA, 0};
#endif
template <typename T>
......
......@@ -25,7 +25,7 @@ TEST(ArrayTest, TestCreate) {
ASSERT_EQ(Len(a), 0);
};
void _TestRange(DLContext ctx) {
void _TestRange(DGLContext ctx) {
IdArray a = aten::Range(10, 10, 64, ctx);
ASSERT_EQ(Len(a), 0);
a = aten::Range(10, 20, 32, ctx);
......@@ -69,7 +69,7 @@ TEST(ArrayTest, TestClone) {
}
};
void _TestNumBits(DLContext ctx) {
void _TestNumBits(DGLContext ctx) {
IdArray a = aten::Range(0, 10, 32, ctx);
a = aten::AsNumBits(a, 64);
ASSERT_EQ(a->dtype.bits, 64);
......@@ -86,7 +86,7 @@ TEST(ArrayTest, TestAsNumBits) {
};
template <typename IDX>
void _TestArith(DLContext ctx) {
void _TestArith(DGLContext ctx) {
const int N = 100;
IdArray a = aten::Full(-10, N, sizeof(IDX)*8, ctx);
IdArray b = aten::Full(7, N, sizeof(IDX)*8, ctx);
......@@ -202,7 +202,7 @@ TEST(ArrayTest, Arith) {
};
template <typename IDX>
void _TestHStack(DLContext ctx) {
void _TestHStack(DGLContext ctx) {
IdArray a = aten::Range(0, 100, sizeof(IDX)*8, ctx);
IdArray b = aten::Range(100, 200, sizeof(IDX)*8, ctx);
IdArray c = aten::HStack(a, b).CopyTo(aten::CPU);
......@@ -222,7 +222,7 @@ TEST(ArrayTest, HStack) {
}
template <typename IDX>
void _TestIndexSelect(DLContext ctx) {
void _TestIndexSelect(DGLContext ctx) {
IdArray a = aten::Range(0, 100, sizeof(IDX)*8, ctx);
ASSERT_EQ(aten::IndexSelect<int>(a, 50), 50);
ASSERT_TRUE(ArrayEQ<IDX>(aten::IndexSelect(a, 10, 20),
......@@ -242,7 +242,7 @@ TEST(ArrayTest, TestIndexSelect) {
}
template <typename IDX>
void _TestRelabel_(DLContext ctx) {
void _TestRelabel_(DGLContext ctx) {
IdArray a = aten::VecToIdArray(std::vector<IDX>({0, 20, 10}), sizeof(IDX)*8, ctx);
IdArray b = aten::VecToIdArray(std::vector<IDX>({20, 5, 6}), sizeof(IDX)*8, ctx);
IdArray c = aten::Relabel_({a, b});
......@@ -266,7 +266,7 @@ TEST(ArrayTest, TestRelabel_) {
}
template <typename IDX>
void _TestConcat(DLContext ctx) {
void _TestConcat(DGLContext ctx) {
IdArray a = aten::VecToIdArray(std::vector<IDX>({1, 2, 3}), sizeof(IDX)*8, CTX);
IdArray b = aten::VecToIdArray(std::vector<IDX>({4, 5, 6}), sizeof(IDX)*8, CTX);
IdArray tc = aten::VecToIdArray(std::vector<IDX>({1, 2, 3, 4, 5, 6}), sizeof(IDX)*8, CTX);
......@@ -279,7 +279,7 @@ void _TestConcat(DLContext ctx) {
}
template <typename IdType>
void _TestToSimpleCsr(DLContext ctx) {
void _TestToSimpleCsr(DGLContext ctx) {
/*
* A = [[0, 0, 0, 0],
* [1, 0, 0, 1],
......@@ -373,7 +373,7 @@ TEST(MatrixTest, TestToSimpleCsr) {
}
template <typename IdType>
void _TestToSimpleCoo(DLContext ctx) {
void _TestToSimpleCoo(DGLContext ctx) {
/*
* A = [[0, 0, 0, 0],
* [1, 0, 0, 1],
......@@ -482,7 +482,7 @@ TEST(MatrixTest, TestToSimpleCoo) {
template <typename IdType>
void _TestDisjointUnionPartitionCoo(DLContext ctx) {
void _TestDisjointUnionPartitionCoo(DGLContext ctx) {
/*
* A = [[0, 0, 1],
* [1, 0, 1],
......@@ -640,7 +640,7 @@ TEST(DisjointUnionTest, TestDisjointUnionPartitionCoo) {
}
template <typename IdType>
void _TestDisjointUnionPartitionCsr(DLContext ctx) {
void _TestDisjointUnionPartitionCsr(DGLContext ctx) {
/*
* A = [[0, 0, 1],
* [1, 0, 1],
......@@ -786,7 +786,7 @@ TEST(DisjointUnionTest, TestDisjointUnionPartitionCsr) {
}
template <typename IdType>
void _TestSliceContiguousChunkCoo(DLContext ctx) {
void _TestSliceContiguousChunkCoo(DGLContext ctx) {
/*
* A = [[1, 0, 0, 0],
* [0, 0, 1, 0],
......@@ -872,7 +872,7 @@ TEST(SliceContiguousChunk, TestSliceContiguousChunkCoo) {
}
template <typename IdType>
void _TestSliceContiguousChunkCsr(DLContext ctx) {
void _TestSliceContiguousChunkCsr(DGLContext ctx) {
/*
* A = [[1, 0, 0, 0],
* [0, 0, 1, 0],
......@@ -955,7 +955,7 @@ TEST(SliceContiguousChunk, TestSliceContiguousChunkCsr) {
}
template <typename IdType>
void _TestMatrixUnionCsr(DLContext ctx) {
void _TestMatrixUnionCsr(DGLContext ctx) {
/*
* A = [[0, 0, 0, 0],
* [0, 0, 0, 0],
......@@ -1178,7 +1178,7 @@ TEST(MatrixUnionTest, TestMatrixUnionCsr) {
}
template <typename IdType>
void _TestMatrixUnionCoo(DLContext ctx) {
void _TestMatrixUnionCoo(DGLContext ctx) {
/*
* A = [[0, 0, 0, 0],
* [0, 0, 0, 0],
......@@ -1391,7 +1391,7 @@ TEST(MatrixUnionTest, TestMatrixUnionCoo) {
}
template <typename IDX>
void _TestCumSum(DLContext ctx) {
void _TestCumSum(DGLContext ctx) {
IdArray a = aten::VecToIdArray(std::vector<IDX>({8, 6, 7, 5, 3, 0, 9}),
sizeof(IDX)*8, ctx);
{
......@@ -1429,7 +1429,7 @@ TEST(ArrayTest, CumSum) {
}
template <typename IDX, typename D>
void _TestScatter_(DLContext ctx) {
void _TestScatter_(DGLContext ctx) {
IdArray out = aten::Full(1, 10, 8*sizeof(IDX), ctx);
IdArray idx = aten::VecToIdArray(std::vector<IDX>({2, 3, 9}), sizeof(IDX)*8, ctx);
IdArray val = aten::VecToIdArray(std::vector<IDX>({-20, 30, 90}), sizeof(IDX)*8, ctx);
......@@ -1452,7 +1452,7 @@ TEST(ArrayTest, Scatter_) {
}
template <typename IDX>
void _TestNonZero(DLContext ctx) {
void _TestNonZero(DGLContext ctx) {
auto val = aten::VecToIdArray(std::vector<IDX>({0, 1, 2, 0, -10, 0, 0, 23}), sizeof(IDX)*8, ctx);
auto idx = aten::NonZero(val);
auto tidx = aten::VecToIdArray(std::vector<int64_t>({1, 2, 4, 7}), 64, ctx);
......@@ -1484,7 +1484,7 @@ TEST(ArrayTest, NonZero) {
}
template <typename IdType>
void _TestLineGraphCOO(DLContext ctx) {
void _TestLineGraphCOO(DGLContext ctx) {
/*
* A = [[0, 0, 1, 0],
* [1, 0, 1, 0],
......@@ -1591,7 +1591,7 @@ TEST(LineGraphTest, LineGraphCOO) {
}
template <typename IDX>
void _TestSort(DLContext ctx) {
void _TestSort(DGLContext ctx) {
// case 1
IdArray a =
aten::VecToIdArray(std::vector<IDX>({8, 6, 7, 5, 3, 0, 9}), sizeof(IDX)*8, ctx);
......
......@@ -55,7 +55,7 @@ bool CSRIsClose(
}
template <typename IdType, typename DType>
std::pair<aten::CSRMatrix, NDArray> CSR_A(DLContext ctx = CTX) {
std::pair<aten::CSRMatrix, NDArray> CSR_A(DGLContext ctx = CTX) {
// matrix([[0. , 0. , 1. , 0.7, 0. ],
// [0. , 0. , 0.5, 0.+, 0. ],
// [0.4, 0.7, 0. , 0.2, 0. ],
......@@ -72,7 +72,7 @@ std::pair<aten::CSRMatrix, NDArray> CSR_A(DLContext ctx = CTX) {
}
template <typename IdType, typename DType>
std::pair<aten::CSRMatrix, NDArray> CSR_B(DLContext ctx = CTX) {
std::pair<aten::CSRMatrix, NDArray> CSR_B(DGLContext ctx = CTX) {
// matrix([[0. , 0.9, 0. , 0.6, 0. , 0.3],
// [0. , 0. , 0. , 0. , 0. , 0.4],
// [0.+, 0. , 0. , 0. , 0. , 0.9],
......@@ -89,7 +89,7 @@ std::pair<aten::CSRMatrix, NDArray> CSR_B(DLContext ctx = CTX) {
}
template <typename IdType, typename DType>
std::pair<aten::CSRMatrix, NDArray> CSR_C(DLContext ctx = CTX) {
std::pair<aten::CSRMatrix, NDArray> CSR_C(DGLContext ctx = CTX) {
// matrix([[0. , 0. , 0. , 0.2, 0. ],
// [0. , 0. , 0. , 0.5, 0.4],
// [0. , 0.2, 0. , 0.9, 0.2],
......@@ -104,7 +104,7 @@ std::pair<aten::CSRMatrix, NDArray> CSR_C(DLContext ctx = CTX) {
}
template <typename IdType, typename DType>
std::pair<aten::CSRMatrix, NDArray> CSR_A_mm_B(DLContext ctx = CTX) {
std::pair<aten::CSRMatrix, NDArray> CSR_A_mm_B(DGLContext ctx = CTX) {
// matrix([[0.56, 0.14, 0.21, 0.14, 0. , 0.9 ],
// [0.+ , 0.+ , 0.+ , 0.+ , 0. , 0.45],
// [0.16, 0.4 , 0.06, 0.28, 0. , 0.4 ],
......@@ -123,7 +123,7 @@ std::pair<aten::CSRMatrix, NDArray> CSR_A_mm_B(DLContext ctx = CTX) {
}
template <typename IdType, typename DType>
std::pair<aten::CSRMatrix, NDArray> CSR_A_plus_C(DLContext ctx = CTX) {
std::pair<aten::CSRMatrix, NDArray> CSR_A_plus_C(DGLContext ctx = CTX) {
auto csr = aten::CSRMatrix(
4, 5,
NDArray::FromVector(std::vector<IdType>({0, 2, 5, 9, 12}), ctx),
......@@ -134,12 +134,12 @@ std::pair<aten::CSRMatrix, NDArray> CSR_A_plus_C(DLContext ctx = CTX) {
}
template <typename DType>
NDArray CSR_A_mask_C(DLContext ctx = CTX) {
NDArray CSR_A_mask_C(DGLContext ctx = CTX) {
return NDArray::FromVector(std::vector<DType>({0.7, 0.0, 0.0, 0.7, 0.2, 0.0, 0.0, 0.0}), ctx);
}
template <typename IdType, typename DType>
void _TestCsrmm(DLContext ctx = CTX) {
void _TestCsrmm(DGLContext ctx = CTX) {
auto A = CSR_A<IdType, DType>(ctx);
auto B = CSR_B<IdType, DType>(ctx);
auto A_mm_B = aten::CSRMM(A.first, A.second, B.first, B.second);
......@@ -149,7 +149,7 @@ void _TestCsrmm(DLContext ctx = CTX) {
}
template <typename IdType, typename DType>
void _TestCsrsum(DLContext ctx = CTX) {
void _TestCsrsum(DGLContext ctx = CTX) {
auto A = CSR_A<IdType, DType>(ctx);
auto C = CSR_C<IdType, DType>(ctx);
auto A_plus_C = aten::CSRSum({A.first, C.first}, {A.second, C.second});
......@@ -160,7 +160,7 @@ void _TestCsrsum(DLContext ctx = CTX) {
}
template <typename IdType, typename DType>
void _TestCsrmask(DLContext ctx = CTX) {
void _TestCsrmask(DGLContext ctx = CTX) {
auto A = CSR_A<IdType, DType>(ctx);
auto C = CSR_C<IdType, DType>(ctx);
auto C_coo = CSRToCOO(C.first, false);
......
......@@ -6,7 +6,7 @@
using namespace dgl;
using namespace dgl::partition;
template<DLDeviceType XPU, typename IdType>
template<DGLDeviceType XPU, typename IdType>
void _TestRemainder_GeneratePermutation() {
const int64_t size = 160000;
const int num_parts = 7;
......@@ -19,13 +19,13 @@ void _TestRemainder_GeneratePermutation() {
std::pair<IdArray, IdArray> result = part->GeneratePermutation(idxs);
// first part of result should be the permutation
IdArray perm = result.first.CopyTo(DGLContext{kDLCPU, 0});
IdArray perm = result.first.CopyTo(DGLContext{kDGLCPU, 0});
ASSERT_TRUE(perm.Ptr<IdType>() != nullptr);
ASSERT_EQ(perm->shape[0], idxs->shape[0]);
const IdType * const perm_cpu = static_cast<const IdType*>(perm->data);
// second part of result should be the counts
IdArray counts = result.second.CopyTo(DGLContext{kDLCPU, 0});
IdArray counts = result.second.CopyTo(DGLContext{kDGLCPU, 0});
ASSERT_TRUE(counts.Ptr<int64_t>() != nullptr);
ASSERT_EQ(counts->shape[0], num_parts);
const int64_t * const counts_cpu = static_cast<const int64_t*>(counts->data);
......@@ -37,7 +37,7 @@ void _TestRemainder_GeneratePermutation() {
ASSERT_EQ(prefix.back(), idxs->shape[0]);
// copy original indexes to cpu
idxs = idxs.CopyTo(DGLContext{kDLCPU, 0});
idxs = idxs.CopyTo(DGLContext{kDGLCPU, 0});
const IdType * const idxs_cpu = static_cast<const IdType*>(idxs->data);
for (int p = 0; p < num_parts; ++p) {
......@@ -47,7 +47,7 @@ void _TestRemainder_GeneratePermutation() {
}
}
template<DLDeviceType XPU, typename IdType>
template<DGLDeviceType XPU, typename IdType>
void _TestRemainder_MapToX() {
const int64_t size = 160000;
const int num_parts = 7;
......@@ -80,11 +80,11 @@ void _TestRemainder_MapToX() {
TEST(PartitionTest, TestRemainderPartition) {
#ifdef DGL_USE_CUDA
_TestRemainder_GeneratePermutation<kDLGPU, int32_t>();
_TestRemainder_GeneratePermutation<kDLGPU, int64_t>();
_TestRemainder_GeneratePermutation<kDGLCUDA, int32_t>();
_TestRemainder_GeneratePermutation<kDGLCUDA, int64_t>();
_TestRemainder_MapToX<kDLGPU, int32_t>();
_TestRemainder_MapToX<kDLGPU, int64_t>();
_TestRemainder_MapToX<kDGLCUDA, int32_t>();
_TestRemainder_MapToX<kDGLCUDA, int64_t>();
#endif
// CPU is not implemented
}
......@@ -105,11 +105,11 @@ int _FindPart(
return -1;
}
template<DLDeviceType XPU, typename IdType>
template<DGLDeviceType XPU, typename IdType>
void _TestRange_GeneratePermutation() {
const int64_t size = 160000;
const int num_parts = 7;
IdArray range = aten::NewIdArray(num_parts+1, DGLContext{kDLCPU, 0},
IdArray range = aten::NewIdArray(num_parts+1, DGLContext{kDGLCPU, 0},
sizeof(IdType)*8);
for (int i = 0; i < num_parts; ++i) {
range.Ptr<IdType>()[i] = (size/num_parts)*i;
......@@ -124,13 +124,13 @@ void _TestRange_GeneratePermutation() {
std::pair<IdArray, IdArray> result = part->GeneratePermutation(idxs);
// first part of result should be the permutation
IdArray perm = result.first.CopyTo(DGLContext{kDLCPU, 0});
IdArray perm = result.first.CopyTo(DGLContext{kDGLCPU, 0});
ASSERT_TRUE(perm.Ptr<IdType>() != nullptr);
ASSERT_EQ(perm->shape[0], idxs->shape[0]);
const IdType * const perm_cpu = static_cast<const IdType*>(perm->data);
// second part of result should be the counts
IdArray counts = result.second.CopyTo(DGLContext{kDLCPU, 0});
IdArray counts = result.second.CopyTo(DGLContext{kDGLCPU, 0});
ASSERT_TRUE(counts.Ptr<int64_t>() != nullptr);
ASSERT_EQ(counts->shape[0], num_parts);
const int64_t * const counts_cpu = static_cast<const int64_t*>(counts->data);
......@@ -142,7 +142,7 @@ void _TestRange_GeneratePermutation() {
ASSERT_EQ(prefix.back(), idxs->shape[0]);
// copy original indexes to cpu
idxs = idxs.CopyTo(DGLContext{kDLCPU, 0});
idxs = idxs.CopyTo(DGLContext{kDGLCPU, 0});
const IdType * const idxs_cpu = static_cast<const IdType*>(idxs->data);
for (int p = 0; p < num_parts; ++p) {
......@@ -152,11 +152,11 @@ void _TestRange_GeneratePermutation() {
}
}
template<DLDeviceType XPU, typename IdType>
template<DGLDeviceType XPU, typename IdType>
void _TestRange_MapToX() {
const int64_t size = 160000;
const int num_parts = 7;
IdArray range = aten::NewIdArray(num_parts+1, DGLContext{kDLCPU, 0},
IdArray range = aten::NewIdArray(num_parts+1, DGLContext{kDGLCPU, 0},
sizeof(IdType)*8);
for (int i = 0; i < num_parts; ++i) {
Ptr<IdType>(range)[i] = (size/num_parts)*i;
......@@ -189,11 +189,11 @@ void _TestRange_MapToX() {
TEST(PartitionTest, TestRangePartition) {
#ifdef DGL_USE_CUDA
_TestRange_GeneratePermutation<kDLGPU, int32_t>();
_TestRange_GeneratePermutation<kDLGPU, int64_t>();
_TestRange_GeneratePermutation<kDGLCUDA, int32_t>();
_TestRange_GeneratePermutation<kDGLCUDA, int64_t>();
_TestRange_MapToX<kDLGPU, int32_t>();
_TestRange_MapToX<kDLGPU, int64_t>();
_TestRange_MapToX<kDGLCUDA, int32_t>();
_TestRange_MapToX<kDGLCUDA, int64_t>();
#endif
// CPU is not implemented
}
......@@ -9,7 +9,7 @@ using namespace dgl::runtime;
namespace {
template <typename IDX>
aten::CSRMatrix CSR1(DLContext ctx = CTX) {
aten::CSRMatrix CSR1(DGLContext ctx = CTX) {
// [[0, 1, 1, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -24,7 +24,7 @@ aten::CSRMatrix CSR1(DLContext ctx = CTX) {
}
template <typename IDX>
aten::CSRMatrix CSR2(DLContext ctx = CTX) {
aten::CSRMatrix CSR2(DGLContext ctx = CTX) {
// has duplicate entries
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
......@@ -40,7 +40,7 @@ aten::CSRMatrix CSR2(DLContext ctx = CTX) {
}
template <typename IDX>
aten::COOMatrix COO1(DLContext ctx = CTX) {
aten::COOMatrix COO1(DGLContext ctx = CTX) {
// [[0, 1, 1, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -55,7 +55,7 @@ aten::COOMatrix COO1(DLContext ctx = CTX) {
}
template <typename IDX>
aten::COOMatrix COO2(DLContext ctx = CTX) {
aten::COOMatrix COO2(DGLContext ctx = CTX) {
// has duplicate entries
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
......@@ -71,7 +71,7 @@ aten::COOMatrix COO2(DLContext ctx = CTX) {
}
template <typename IDX>
aten::CSRMatrix SR_CSR3(DLContext ctx) {
aten::CSRMatrix SR_CSR3(DGLContext ctx) {
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -85,7 +85,7 @@ aten::CSRMatrix SR_CSR3(DLContext ctx) {
}
template <typename IDX>
aten::CSRMatrix SRC_CSR3(DLContext ctx) {
aten::CSRMatrix SRC_CSR3(DGLContext ctx) {
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -99,7 +99,7 @@ aten::CSRMatrix SRC_CSR3(DLContext ctx) {
}
template <typename IDX>
aten::COOMatrix COO3(DLContext ctx) {
aten::COOMatrix COO3(DGLContext ctx) {
// has duplicate entries
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
......@@ -118,7 +118,7 @@ struct SparseCOOCSR {
static constexpr uint64_t NUM_COLS = 150;
static constexpr uint64_t NUM_NZ = 5;
template <typename IDX>
static aten::COOMatrix COOSparse(const DLContext &ctx = CTX) {
static aten::COOMatrix COOSparse(const DGLContext &ctx = CTX) {
return aten::COOMatrix(NUM_ROWS, NUM_COLS,
aten::VecToIdArray(std::vector<IDX>({0, 1, 2, 3, 4}),
sizeof(IDX) * 8, ctx),
......@@ -127,7 +127,7 @@ struct SparseCOOCSR {
}
template <typename IDX>
static aten::CSRMatrix CSRSparse(const DLContext &ctx = CTX) {
static aten::CSRMatrix CSRSparse(const DGLContext &ctx = CTX) {
auto &&indptr = std::vector<IDX>(NUM_ROWS + 1, NUM_NZ);
for (size_t i = 0; i < NUM_NZ; ++i) {
indptr[i + 1] = static_cast<IDX>(i + 1);
......@@ -150,7 +150,7 @@ bool isSparseCOO(const int64_t &num_threads, const int64_t &num_nodes,
}
template <typename IDX>
aten::COOMatrix RowSorted_NullData_COO(DLContext ctx = CTX) {
aten::COOMatrix RowSorted_NullData_COO(DGLContext ctx = CTX) {
// [[0, 1, 1, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -166,7 +166,7 @@ aten::COOMatrix RowSorted_NullData_COO(DLContext ctx = CTX) {
}
template <typename IDX>
aten::CSRMatrix RowSorted_NullData_CSR(DLContext ctx = CTX) {
aten::CSRMatrix RowSorted_NullData_CSR(DGLContext ctx = CTX) {
// [[0, 1, 1, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -184,7 +184,7 @@ aten::CSRMatrix RowSorted_NullData_CSR(DLContext ctx = CTX) {
} // namespace
template <typename IDX>
void _TestCOOToCSR(DLContext ctx) {
void _TestCOOToCSR(DGLContext ctx) {
auto coo = COO1<IDX>(ctx);
auto csr = CSR1<IDX>(ctx);
auto tcsr = aten::COOToCSR(coo);
......@@ -297,7 +297,7 @@ TEST(SpmatTest, TestCOOHasDuplicate) {
}
template <typename IDX>
void _TestCOOSort(DLContext ctx) {
void _TestCOOSort(DGLContext ctx) {
auto coo = COO3<IDX>(ctx);
auto sr_coo = COOSort(coo, false);
......@@ -387,7 +387,7 @@ TEST(SpmatTest, TestCOOReorder) {
}
template <typename IDX>
void _TestCOOGetData(DLContext ctx) {
void _TestCOOGetData(DGLContext ctx) {
auto coo = COO2<IDX>(ctx);
// test get all data
auto x = aten::COOGetAllData(coo, 0, 0);
......
......@@ -8,7 +8,7 @@ using namespace dgl::runtime;
namespace {
template <typename IDX>
aten::CSRMatrix CSR1(DLContext ctx = CTX) {
aten::CSRMatrix CSR1(DGLContext ctx = CTX) {
// [[0, 1, 1, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -23,7 +23,7 @@ aten::CSRMatrix CSR1(DLContext ctx = CTX) {
}
template <typename IDX>
aten::CSRMatrix CSR2(DLContext ctx = CTX) {
aten::CSRMatrix CSR2(DGLContext ctx = CTX) {
// has duplicate entries
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
......@@ -39,7 +39,7 @@ aten::CSRMatrix CSR2(DLContext ctx = CTX) {
}
template <typename IDX>
aten::CSRMatrix CSR3(DLContext ctx = CTX) {
aten::CSRMatrix CSR3(DGLContext ctx = CTX) {
// has duplicate entries and the columns are not sorted
// [[0, 1, 1, 1, 0],
// [1, 0, 0, 0, 0],
......@@ -63,7 +63,7 @@ aten::CSRMatrix CSR3(DLContext ctx = CTX) {
}
template <typename IDX>
aten::COOMatrix COO1(DLContext ctx = CTX) {
aten::COOMatrix COO1(DGLContext ctx = CTX) {
// [[0, 1, 1, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -78,7 +78,7 @@ aten::COOMatrix COO1(DLContext ctx = CTX) {
}
template <typename IDX>
aten::COOMatrix COO2(DLContext ctx = CTX) {
aten::COOMatrix COO2(DGLContext ctx = CTX) {
// has duplicate entries
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
......@@ -94,7 +94,7 @@ aten::COOMatrix COO2(DLContext ctx = CTX) {
}
template <typename IDX>
aten::CSRMatrix SR_CSR3(DLContext ctx) {
aten::CSRMatrix SR_CSR3(DGLContext ctx) {
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -108,7 +108,7 @@ aten::CSRMatrix SR_CSR3(DLContext ctx) {
}
template <typename IDX>
aten::CSRMatrix SRC_CSR3(DLContext ctx) {
aten::CSRMatrix SRC_CSR3(DGLContext ctx) {
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 0],
......@@ -122,7 +122,7 @@ aten::CSRMatrix SRC_CSR3(DLContext ctx) {
}
template <typename IDX>
aten::COOMatrix COO3(DLContext ctx) {
aten::COOMatrix COO3(DGLContext ctx) {
// has duplicate entries
// [[0, 1, 2, 0, 0],
// [1, 0, 0, 0, 0],
......@@ -139,7 +139,7 @@ aten::COOMatrix COO3(DLContext ctx) {
} // namespace
template <typename IDX>
void _TestCSRIsNonZero1(DLContext ctx) {
void _TestCSRIsNonZero1(DGLContext ctx) {
auto csr = CSR1<IDX>(ctx);
ASSERT_TRUE(aten::CSRIsNonZero(csr, 0, 1));
ASSERT_FALSE(aten::CSRIsNonZero(csr, 0, 0));
......@@ -151,7 +151,7 @@ void _TestCSRIsNonZero1(DLContext ctx) {
}
template <typename IDX>
void _TestCSRIsNonZero2(DLContext ctx) {
void _TestCSRIsNonZero2(DGLContext ctx) {
auto csr = CSR3<IDX>(ctx);
ASSERT_TRUE(aten::CSRIsNonZero(csr, 0, 1));
ASSERT_FALSE(aten::CSRIsNonZero(csr, 0, 0));
......@@ -176,7 +176,7 @@ TEST(SpmatTest, TestCSRIsNonZero) {
}
template <typename IDX>
void _TestCSRGetRowNNZ(DLContext ctx) {
void _TestCSRGetRowNNZ(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
ASSERT_EQ(aten::CSRGetRowNNZ(csr, 0), 3);
ASSERT_EQ(aten::CSRGetRowNNZ(csr, 3), 0);
......@@ -196,7 +196,7 @@ TEST(SpmatTest, TestCSRGetRowNNZ) {
}
template <typename IDX>
void _TestCSRGetRowColumnIndices(DLContext ctx) {
void _TestCSRGetRowColumnIndices(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
auto x = aten::CSRGetRowColumnIndices(csr, 0);
auto tx = aten::VecToIdArray(std::vector<IDX>({1, 2, 2}), sizeof(IDX)*8, ctx);
......@@ -219,7 +219,7 @@ TEST(SpmatTest, TestCSRGetRowColumnIndices) {
}
template <typename IDX>
void _TestCSRGetRowData(DLContext ctx) {
void _TestCSRGetRowData(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
auto x = aten::CSRGetRowData(csr, 0);
auto tx = aten::VecToIdArray(std::vector<IDX>({0, 2, 5}), sizeof(IDX)*8, ctx);
......@@ -242,7 +242,7 @@ TEST(SpmatTest, TestCSRGetRowData) {
}
template <typename IDX>
void _TestCSRGetData(DLContext ctx) {
void _TestCSRGetData(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
// test get all data
auto x = aten::CSRGetAllData(csr, 0, 0);
......@@ -286,7 +286,7 @@ TEST(SpmatTest, CSRGetData) {
}
template <typename IDX>
void _TestCSRGetDataAndIndices(DLContext ctx) {
void _TestCSRGetDataAndIndices(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
auto r = aten::VecToIdArray(std::vector<IDX>({0, 0, 0}), sizeof(IDX)*8, ctx);
auto c = aten::VecToIdArray(std::vector<IDX>({0, 1, 2}), sizeof(IDX)*8, ctx);
......@@ -309,7 +309,7 @@ TEST(SpmatTest, CSRGetDataAndIndices) {
}
template <typename IDX>
void _TestCSRTranspose(DLContext ctx) {
void _TestCSRTranspose(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
auto csr_t = aten::CSRTranspose(csr);
// [[0, 1, 0, 0],
......@@ -338,7 +338,7 @@ TEST(SpmatTest, CSRTranspose) {
}
template <typename IDX>
void _TestCSRToCOO(DLContext ctx) {
void _TestCSRToCOO(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
{
auto coo = CSRToCOO(csr, false);
......@@ -382,7 +382,7 @@ TEST(SpmatTest, CSRToCOO) {
}
template <typename IDX>
void _TestCSRSliceRows(DLContext ctx) {
void _TestCSRSliceRows(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
auto x = aten::CSRSliceRows(csr, 1, 4);
// [1, 0, 0, 0, 0],
......@@ -480,7 +480,7 @@ TEST(SpmatTest, TestCSRSliceRows) {
}
template <typename IDX>
void _TestCSRSliceMatrix1(DLContext ctx) {
void _TestCSRSliceMatrix1(DGLContext ctx) {
auto csr = CSR2<IDX>(ctx);
{
// square
......@@ -538,7 +538,7 @@ void _TestCSRSliceMatrix1(DLContext ctx) {
}
template <typename IDX>
void _TestCSRSliceMatrix2(DLContext ctx) {
void _TestCSRSliceMatrix2(DGLContext ctx) {
auto csr = CSR3<IDX>(ctx);
{
// square
......@@ -611,7 +611,7 @@ TEST(SpmatTest, CSRSliceMatrix) {
}
template <typename IDX>
void _TestCSRHasDuplicate(DLContext ctx) {
void _TestCSRHasDuplicate(DGLContext ctx) {
auto csr = CSR1<IDX>(ctx);
ASSERT_FALSE(aten::CSRHasDuplicate(csr));
csr = CSR2<IDX>(ctx);
......@@ -628,7 +628,7 @@ TEST(SpmatTest, CSRHasDuplicate) {
}
template <typename IDX>
void _TestCSRSort(DLContext ctx) {
void _TestCSRSort(DGLContext ctx) {
auto csr = CSR1<IDX>(ctx);
ASSERT_FALSE(aten::CSRIsSorted(csr));
auto csr1 = aten::CSRSort(csr);
......
......@@ -17,7 +17,7 @@ using namespace dgl;
using namespace dgl::runtime;
template <typename IdType>
aten::CSRMatrix CSR1(DLContext ctx) {
aten::CSRMatrix CSR1(DGLContext ctx) {
/*
* G = [[0, 0, 1],
* [1, 0, 1],
......@@ -39,11 +39,11 @@ aten::CSRMatrix CSR1(DLContext ctx) {
return csr_a;
}
template aten::CSRMatrix CSR1<int32_t>(DLContext ctx);
template aten::CSRMatrix CSR1<int64_t>(DLContext ctx);
template aten::CSRMatrix CSR1<int32_t>(DGLContext ctx);
template aten::CSRMatrix CSR1<int64_t>(DGLContext ctx);
template <typename IdType>
aten::COOMatrix COO1(DLContext ctx) {
aten::COOMatrix COO1(DGLContext ctx) {
/*
* G = [[1, 1, 0],
* [0, 1, 0]]
......@@ -64,10 +64,10 @@ aten::COOMatrix COO1(DLContext ctx) {
return coo;
}
template aten::COOMatrix COO1<int32_t>(DLContext ctx);
template aten::COOMatrix COO1<int64_t>(DLContext ctx);
template aten::COOMatrix COO1<int32_t>(DGLContext ctx);
template aten::COOMatrix COO1<int64_t>(DGLContext ctx);
template <typename IdType> void _TestUnitGraph_InOutDegrees(DLContext ctx) {
template <typename IdType> void _TestUnitGraph_InOutDegrees(DGLContext ctx) {
/*
InDegree(s) is available only if COO or CSC formats permitted.
OutDegree(s) is available only if COO or CSR formats permitted.
......@@ -114,7 +114,7 @@ template <typename IdType> void _TestUnitGraph_InOutDegrees(DLContext ctx) {
}
template <typename IdType>
void _TestUnitGraph(DLContext ctx) {
void _TestUnitGraph(DGLContext ctx) {
const aten::CSRMatrix &csr = CSR1<IdType>(ctx);
const aten::COOMatrix &coo = COO1<IdType>(ctx);
......@@ -156,7 +156,7 @@ void _TestUnitGraph(DLContext ctx) {
}
template <typename IdType>
void _TestUnitGraph_GetInCSR(DLContext ctx) {
void _TestUnitGraph_GetInCSR(DGLContext ctx) {
const aten::CSRMatrix &csr = CSR1<IdType>(ctx);
const aten::COOMatrix &coo = COO1<IdType>(ctx);
......@@ -193,7 +193,7 @@ void _TestUnitGraph_GetInCSR(DLContext ctx) {
}
template <typename IdType>
void _TestUnitGraph_GetOutCSR(DLContext ctx) {
void _TestUnitGraph_GetOutCSR(DGLContext ctx) {
const aten::CSRMatrix &csr = CSR1<IdType>(ctx);
const aten::COOMatrix &coo = COO1<IdType>(ctx);
......@@ -230,7 +230,7 @@ void _TestUnitGraph_GetOutCSR(DLContext ctx) {
}
template <typename IdType>
void _TestUnitGraph_GetCOO(DLContext ctx) {
void _TestUnitGraph_GetCOO(DGLContext ctx) {
const aten::CSRMatrix &csr = CSR1<IdType>(ctx);
const aten::COOMatrix &coo = COO1<IdType>(ctx);
......@@ -266,7 +266,7 @@ void _TestUnitGraph_GetCOO(DLContext ctx) {
}
template <typename IdType>
void _TestUnitGraph_Reserve(DLContext ctx) {
void _TestUnitGraph_Reserve(DGLContext ctx) {
const aten::CSRMatrix &csr = CSR1<IdType>(ctx);
const aten::COOMatrix &coo = COO1<IdType>(ctx);
......@@ -346,7 +346,7 @@ void _TestUnitGraph_Reserve(DLContext ctx) {
}
template <typename IdType>
void _TestUnitGraph_CopyTo(const DLContext &src_ctx,
void _TestUnitGraph_CopyTo(const DGLContext &src_ctx,
const DGLContext &dst_ctx) {
const aten::CSRMatrix &csr = CSR1<IdType>(src_ctx);
const aten::COOMatrix &coo = COO1<IdType>(src_ctx);
......
......@@ -19,7 +19,7 @@ using namespace dgl::aten;
using namespace dmlc;
// Function to convert an idarray to string
std::string IdArrayToStr(IdArray arr) {
arr = arr.CopyTo(DLContext{kDLCPU, 0});
arr = arr.CopyTo(DGLContext{kDGLCPU, 0});
int64_t len = arr->shape[0];
std::ostringstream oss;
oss << "(" << len << ")[";
......@@ -99,9 +99,9 @@ TEST(ZeroCopySerialize, ZeroShapeNDArray) {
TEST(ZeroCopySerialize, SharedMem) {
auto tensor1 = VecToIdArray<int64_t>({1, 2, 5, 3});
DLDataType dtype = {kDLInt, 64, 1};
DGLDataType dtype = {kDGLInt, 64, 1};
std::vector<int64_t> shape{4};
DLContext cpu_ctx = {kDLCPU, 0};
DGLContext cpu_ctx = {kDGLCPU, 0};
auto shared_tensor =
NDArray::EmptyShared("test", shape, dtype, cpu_ctx, true);
shared_tensor.CopyFrom(tensor1);
......
Subproject commit bee4d1dd8dc1ee4a1fd8fa6a96476c2f8b7492a3
Subproject commit e2bdd3bee8cb6501558042633fa59144cc8b7f5f
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment