Sample edges. This function can be parallelized. */
| 1010 | |
| 1011 | /** Sample edges. This function can be parallelized. */ |
| 1012 | void sample(int start, int end) { |
| 1013 | CUDA_CHECK(cudaSetDevice(device_id)); |
| 1014 | |
| 1015 | random.to_host(); |
| 1016 | CURAND_CHECK(curandGenerateUniformDouble(generator, random.device_ptr, kRandBatchSize)); |
| 1017 | |
| 1018 | auto &sample_pool = solver->sample_pools[solver->pool_id ^ 1]; |
| 1019 | std::vector<std::vector<int>> offsets(num_partition); |
| 1020 | for (auto &&partition_offsets : offsets) |
| 1021 | partition_offsets.resize(num_partition, start); |
| 1022 | int num_complete = 0, rand_id = 0; |
| 1023 | std::vector<std::pair<int, Index>> heads(solver->sample_batch_size); |
| 1024 | std::vector<std::pair<int, Index>> tails(solver->sample_batch_size); |
| 1025 | std::vector<Attributes> attributes(solver->sample_batch_size); |
| 1026 | while (num_complete < num_partition * num_partition) { |
| 1027 | for (int i = 0; i < solver->sample_batch_size; i++) { |
| 1028 | if (rand_id > kRandBatchSize - 2) { |
| 1029 | random.to_host(); |
| 1030 | CURAND_CHECK(curandGenerateUniformDouble(generator, random.device_ptr, kRandBatchSize)); |
| 1031 | rand_id = 0; |
| 1032 | } |
| 1033 | size_t edge_id = solver->edge_table.sample(random[rand_id++], random[rand_id++]); |
| 1034 | |
| 1035 | Index head_global_id = std::get<0>(solver->graph->edges[edge_id]); |
| 1036 | Index tail_global_id = std::get<1>(solver->graph->edges[edge_id]); |
| 1037 | heads[i] = solver->head_locations[head_global_id]; |
| 1038 | tails[i] = solver->tail_locations[tail_global_id]; |
| 1039 | attributes[i] = get_attributes(solver->graph->edges[edge_id]); |
| 1040 | } |
| 1041 | for (int i = 0; i < solver->sample_batch_size; i++) { |
| 1042 | int head_partition_id = heads[i].first; |
| 1043 | int tail_partition_id = tails[i].first; |
| 1044 | int &offset = offsets[head_partition_id][tail_partition_id]; |
| 1045 | if (offset < end) { |
| 1046 | auto &pool = sample_pool[head_partition_id][tail_partition_id]; |
| 1047 | Index head_local_id = heads[i].second; |
| 1048 | Index tail_local_id = tails[i].second; |
| 1049 | pool[offset] = std::tuple_cat(std::tie(head_local_id, tail_local_id), attributes[i]); |
| 1050 | if (++offset == end) |
| 1051 | num_complete++; |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | /** Count edges for each sample block. This function can be parallelized. */ |
| 1058 | void count(size_t start, size_t end, int id) { |
no test coverage detected