dmlc--dgl
17d604b5c7
* Split from NCCL PR * Fix type in comment * Expand documentation for sparse_all_to_all_push * Restore previous behavior in example * Re-work optimizer to use NCCL based on gradient location * Allow for running with embedding on CPU but using NCCL for gradient exchange * Optimize single partition case * Fix pylint errors * Add missing include * fix gradient indexing * Fix line continuation * Migrate 'first_step' * Skip tests without enough GPUs to run NCCL * Improve empty tensor handling for pytorch 1.5 * Fix indentation * Allow multiple NCCL communicator to coexist * Improve handling of empty message * Update python/dgl/nn/pytorch/sparse_emb.py Co-authored-by: xiang song(charlie.song) <classicxsong@gmail.com> * Update python/dgl/nn/pytorch/sparse_emb.py Co-authored-by: xiang song(charlie.song) <classicxsong@gmail.com> * Keepy empty tensor dimensionaless * th.empty -> th.tensor * Preserve shape for empty non-zero dimension tensors * Use shared state, when embedding is shared * Add support for gathering an embedding * Fix typo * Fix more typos * Fix backend call * Use NodeDataLoader to take advantage of ddp * Update training script to share memory * Only squeeze last dimension * Better handle empty message * Keep embedding on the target device GPU if dgl_sparse if false in RGCN example * Fix typo in comment * Add asserts * Improve documentation in example Co-authored-by: xiang song(charlie.song) <classicxsong@gmail.com>
95 行
3.0 KiB
C++
95 行
3.0 KiB
C++
#include <gtest/gtest.h>
|
|
#include "../../src/partition/ndarray_partition.h"
|
|
#include "./common.h"
|
|
|
|
|
|
using namespace dgl;
|
|
using namespace dgl::partition;
|
|
|
|
|
|
template<DLDeviceType XPU, typename IdType>
|
|
void _TestRemainder_GeneratePermutation() {
|
|
const int64_t size = 160000;
|
|
const int num_parts = 7;
|
|
NDArrayPartitionRef part = CreatePartitionRemainderBased(
|
|
size, num_parts);
|
|
|
|
IdArray idxs = aten::Range(0, size/10, sizeof(IdType)*8,
|
|
DGLContext{XPU, 0});
|
|
|
|
std::pair<IdArray, IdArray> result = part->GeneratePermutation(idxs);
|
|
|
|
// first part of result should be the permutation
|
|
IdArray perm = result.first.CopyTo(DGLContext{kDLCPU, 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});
|
|
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);
|
|
|
|
std::vector<int64_t> prefix(num_parts+1, 0);
|
|
for (int p = 0; p < num_parts; ++p) {
|
|
prefix[p+1] = prefix[p] + counts_cpu[p];
|
|
}
|
|
ASSERT_EQ(prefix.back(), idxs->shape[0]);
|
|
|
|
// copy original indexes to cpu
|
|
idxs = idxs.CopyTo(DGLContext{kDLCPU, 0});
|
|
const IdType * const idxs_cpu = static_cast<const IdType*>(idxs->data);
|
|
|
|
for (int p = 0; p < num_parts; ++p) {
|
|
for (int64_t i = prefix[p]; i < prefix[p+1]; ++i) {
|
|
EXPECT_EQ(idxs_cpu[perm_cpu[i]] % num_parts, p);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<DLDeviceType XPU, typename IdType>
|
|
void _TestRemainder_MapToX() {
|
|
const int64_t size = 160000;
|
|
const int num_parts = 7;
|
|
NDArrayPartitionRef part = CreatePartitionRemainderBased(
|
|
size, num_parts);
|
|
|
|
for (int part_id = 0; part_id < num_parts; ++part_id) {
|
|
IdArray local = aten::Range(0, part->PartSize(part_id), sizeof(IdType)*8,
|
|
DGLContext{XPU, 0});
|
|
IdArray global = part->MapToGlobal(local, part_id);
|
|
IdArray act_local = part->MapToLocal(global).CopyTo(CPU);
|
|
|
|
// every global index should have the same remainder as the part id
|
|
ASSERT_EQ(global->shape[0], local->shape[0]);
|
|
global = global.CopyTo(CPU);
|
|
for (size_t i = 0; i < global->shape[0]; ++i) {
|
|
EXPECT_EQ(Ptr<IdType>(global)[i] % num_parts, part_id) << "i=" << i <<
|
|
", num_parts=" << num_parts << ", part_id=" << part_id;
|
|
}
|
|
|
|
// the remapped local indices to should match the original
|
|
local = local.CopyTo(CPU);
|
|
ASSERT_EQ(local->shape[0], act_local->shape[0]);
|
|
for (size_t i = 0; i < act_local->shape[0]; ++i) {
|
|
EXPECT_EQ(Ptr<IdType>(local)[i], Ptr<IdType>(act_local)[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST(PartitionTest, TestRemainderPartition) {
|
|
#ifdef DGL_USE_CUDA
|
|
_TestRemainder_GeneratePermutation<kDLGPU, int32_t>();
|
|
_TestRemainder_GeneratePermutation<kDLGPU, int64_t>();
|
|
|
|
_TestRemainder_MapToX<kDLGPU, int32_t>();
|
|
_TestRemainder_MapToX<kDLGPU, int64_t>();
|
|
#endif
|
|
|
|
// CPU is not implemented
|
|
}
|
|
|
|
|
|
|