MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / naive_sample

Method naive_sample

include/core/solver.h:975–1009  ·  view source on GitHub ↗

Sample edges for naive parallel. This function can be parallelized. */

Source from the content-addressed store, hash-verified

973
974 /** Sample edges for naive parallel. This function can be parallelized. */
975 void naive_sample(int start, int end) {
976 CUDA_CHECK(cudaSetDevice(device_id));
977
978 random.to_host();
979 CURAND_CHECK(curandGenerateUniformDouble(generator, random.device_ptr, kRandBatchSize));
980
981 auto &sample_pool = solver->sample_pools[solver->pool_id ^ 1];
982 int partition_id = 0, rand_id = 0, offset = start;
983 std::vector<Index> heads(solver->sample_batch_size);
984 std::vector<Index> tails(solver->sample_batch_size);
985 std::vector<Attributes> attributes(solver->sample_batch_size);
986 while (partition_id < num_partition) {
987 for (int i = 0; i < solver->sample_batch_size; i++) {
988 if (rand_id > kRandBatchSize - 2) {
989 random.to_host();
990 CURAND_CHECK(curandGenerateUniformDouble(generator, random.device_ptr, kRandBatchSize));
991 rand_id = 0;
992 }
993 size_t edge_id = solver->edge_table.sample(random[rand_id++], random[rand_id++]);
994
995 heads[i] = std::get<0>(solver->graph->edges[edge_id]);
996 tails[i] = std::get<1>(solver->graph->edges[edge_id]);
997 attributes[i] = get_attributes(solver->graph->edges[edge_id]);
998 }
999 for (int i = 0; i < solver->sample_batch_size; i++) {
1000 auto &pool = sample_pool[partition_id][0];
1001 pool[offset] = std::tuple_cat(std::tie(heads[i], tails[i]), attributes[i]);
1002 if (++offset == end) {
1003 if (++partition_id == num_partition)
1004 return;
1005 offset = start;
1006 }
1007 }
1008 }
1009 }
1010
1011 /** Sample edges. This function can be parallelized. */
1012 void sample(int start, int end) {

Callers

nothing calls this directly

Calls 2

to_hostMethod · 0.80
sampleMethod · 0.80

Tested by

no test coverage detected