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

Method load_embedding

include/core/solver.h:1349–1386  ·  view source on GitHub ↗

* @brief Load an embedding matrix and its moment matrices to GPU cache * @param id id of embedding matrix * * The actual operation depends on the protocol. It is safe to call this function multiple times. */

Source from the content-addressed store, hash-verified

1347 * The actual operation depends on the protocol. It is safe to call this function multiple times.
1348 */
1349 void load_embedding(int id) {
1350 Protocol protocol = protocols[id];
1351 if ((protocol & kSharedWithPredecessor) && ((protocol & kGlobal) || head_partition_id == tail_partition_id)) {
1352 embeddings[id] = embeddings[id - 1];
1353 moments[id] = moments[id - 1];
1354 return;
1355 }
1356 if (id > 0 && embeddings[id] == embeddings[id - 1]) {
1357 embeddings[id] = std::make_shared<Memory<Vector, Index>>(device_id, 0, work_stream);
1358 gradients[id] = std::make_shared<Memory<Vector, Index>>(device_id, 0, work_stream);
1359 moments[id] = std::make_shared<std::vector<Memory<Vector, Index>>>();
1360 for (int i = 0; i < num_moment; i++)
1361 moments[id]->push_back(Memory<Vector, Index>(device_id, 0, work_stream));
1362 }
1363 auto &global_embedding = *(solver->embeddings[id]);
1364 auto &global_moment = *(solver->moments[id]);
1365 auto &embedding = *embeddings[id];
1366 auto &moment = *moments[id];
1367 auto &gradient = *gradients[id];
1368 std::vector<Index> none, *mapping = &none;
1369
1370 if (protocol & kHeadPartition)
1371 mapping = &head_global_ids;
1372 if (protocol & kTailPartition)
1373 mapping = &tail_global_ids;
1374
1375 embedding.gather(global_embedding, *mapping);
1376 embedding.to_device_async();
1377
1378 // only load partitioned moments, or global moments if uninitialized
1379 if (solver->is_train)
1380 if (!(protocol & kGlobal) || (num_moment && moment[0].count == 0)) {
1381 for (int i = 0; i < num_moment; i++) {
1382 moment[i].gather(global_moment[i], *mapping);
1383 moment[i].to_device_async();
1384 }
1385 }
1386 }
1387
1388 /**
1389 * @brief Write back an embedding matrix and its moment matrices from GPU cache

Callers

nothing calls this directly

Calls 2

gatherMethod · 0.80
to_device_asyncMethod · 0.80

Tested by

no test coverage detected