Skip to content

Commit

Permalink
dirsync fbgemm with xplat
Browse files Browse the repository at this point in the history
Summary: As title

Reviewed By: mzlee

Differential Revision: D21419886

fbshipit-source-id: 7c762466ef5fba8ddf340218de3df3683ecd262b
  • Loading branch information
jspark1105 authored and facebook-github-bot committed May 14, 2020
1 parent 483ccc9 commit 7ed5f9f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 66 deletions.
19 changes: 9 additions & 10 deletions bench/EmbeddingSpMDM8BitBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ int run_benchmark(
// Generate lengths
uniform_int_distribution<int> length_distribution(
1, std::min(2 * average_len + 1, num_rows));
vector<int> offsets(batch_size + 1);
offsets[0] = 0;
vector<int> lengths(batch_size);
for (int i = 0; i < batch_size; ++i) {
offsets[i + 1] = offsets[i] + length_distribution(generator);
lengths[i] = length_distribution(generator);
}

// Compute the number of indices
int lengths_sum = offsets[batch_size];
int lengths_sum = accumulate(lengths.begin(), lengths.end(), 0);
if (fbgemm_get_thread_num() == 0) {
cout << "lengths_sum " << lengths_sum << endl;
}
Expand All @@ -112,7 +111,7 @@ int run_benchmark(
random_shuffle(container.begin(), container.end());
copy(
container.begin(),
container.begin() + (offsets[i + 1] - offsets[i]),
container.begin() + lengths[i],
back_inserter(indices));
}
copy(begin(indices), end(indices), back_inserter(indices_32));
Expand Down Expand Up @@ -157,7 +156,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand All @@ -169,7 +168,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand Down Expand Up @@ -200,7 +199,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data());
} else {
Expand All @@ -210,7 +209,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data());
}
Expand All @@ -222,7 +221,7 @@ int run_benchmark(
cache_evict(fused_embedding_table);
cache_evict(indices);
cache_evict(indices_32);
cache_evict(offsets);
cache_evict(lengths);
cache_evict(weights);
cache_evict(output);
}
Expand Down
27 changes: 13 additions & 14 deletions bench/EmbeddingSpMDMBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@ void run_benchmark(
// Generate lengths
uniform_int_distribution<int> length_distribution(
1, std::min(2 * average_len + 1, num_rows));
vector<int> offsets(batch_size + 1);
offsets[0] = 0;
vector<int> lengths(batch_size);
for (int i = 0; i < batch_size; ++i) {
offsets[i + 1] = offsets[i] + length_distribution(generator);
lengths[i] = length_distribution(generator);
}

// Compute the number of indices
int lengths_sum = offsets[batch_size];
int lengths_sum = accumulate(lengths.begin(), lengths.end(), 0);
cout << "lengths_sum " << lengths_sum << endl;

// Generate indices
Expand All @@ -96,7 +95,7 @@ void run_benchmark(
random_shuffle(container.begin(), container.end());
copy(
container.begin(),
container.begin() + (offsets[i + 1] - offsets[i]),
container.begin() + lengths[i],
back_inserter(indices));
}
copy(begin(indices), end(indices), back_inserter(indices_32));
Expand Down Expand Up @@ -136,7 +135,7 @@ void run_benchmark(
num_rows,
embedding_table_fp16.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand All @@ -148,7 +147,7 @@ void run_benchmark(
num_rows,
embedding_table_fp16.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand All @@ -162,7 +161,7 @@ void run_benchmark(
num_rows,
embedding_table.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand All @@ -174,7 +173,7 @@ void run_benchmark(
num_rows,
embedding_table.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand Down Expand Up @@ -202,7 +201,7 @@ void run_benchmark(
num_rows,
embedding_table_fp16.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data());
} else {
Expand All @@ -212,7 +211,7 @@ void run_benchmark(
num_rows,
embedding_table_fp16.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data());
}
Expand All @@ -224,7 +223,7 @@ void run_benchmark(
num_rows,
embedding_table.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data());
} else {
Expand All @@ -234,7 +233,7 @@ void run_benchmark(
num_rows,
embedding_table.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data());
}
Expand All @@ -247,7 +246,7 @@ void run_benchmark(
cache_evict(embedding_table);
cache_evict(indices);
cache_evict(indices_32);
cache_evict(offsets);
cache_evict(lengths);
cache_evict(weights);
cache_evict(output);
}
Expand Down
19 changes: 9 additions & 10 deletions bench/EmbeddingSpMDMNBitBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ int run_benchmark(
// Generate lengths
uniform_int_distribution<int> length_distribution(
1, std::min(2 * average_len + 1, num_rows));
vector<int> offsets(batch_size + 1);
offsets[0] = 0;
vector<int> lengths(batch_size);
for (int i = 0; i < batch_size; ++i) {
offsets[i + 1] = offsets[i] + length_distribution(generator);
lengths[i] = length_distribution(generator);
}

// Compute the number of indices
int lengths_sum = offsets[batch_size];
int lengths_sum = accumulate(lengths.begin(), lengths.end(), 0);
cout << "lengths_sum " << lengths_sum << endl;

// Generate indices
Expand All @@ -117,7 +116,7 @@ int run_benchmark(
random_shuffle(container.begin(), container.end());
copy(
container.begin(),
container.begin() + (offsets[i + 1] - offsets[i]),
container.begin() + lengths[i],
back_inserter(indices));
}
copy(begin(indices), end(indices), back_inserter(indices_32));
Expand Down Expand Up @@ -156,7 +155,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand All @@ -169,7 +168,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand Down Expand Up @@ -199,7 +198,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data());
} else {
Expand All @@ -209,7 +208,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data());
}
Expand All @@ -221,7 +220,7 @@ int run_benchmark(
cache_evict(fused_embedding_table);
cache_evict(indices);
cache_evict(indices_32);
cache_evict(offsets);
cache_evict(lengths);
cache_evict(weights);
cache_evict(output);
}
Expand Down
19 changes: 9 additions & 10 deletions bench/EmbeddingSpMDMNBitRowWiseSparseBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ int run_benchmark(
// Generate lengths
uniform_int_distribution<int> length_distribution(
1, std::min(2 * average_len + 1, num_rows));
vector<int> offsets(batch_size + 1);
offsets[0] = 0;
vector<int> lengths(batch_size);
for (int i = 0; i < batch_size; ++i) {
offsets[i + 1] = offsets[i] + length_distribution(generator);
lengths[i] = length_distribution(generator);
}

// Compute the number of indices
int lengths_sum = offsets[batch_size];
int lengths_sum = accumulate(lengths.begin(), lengths.end(), 0);

// Generate indices
vector<int64_t> indices;
Expand All @@ -132,7 +131,7 @@ int run_benchmark(
random_shuffle(container.begin(), container.end());
copy(
container.begin(),
container.begin() + (offsets[i + 1] - offsets[i]),
container.begin() + lengths[i],
back_inserter(indices));
}
copy(begin(indices), end(indices), back_inserter(indices_32));
Expand Down Expand Up @@ -188,7 +187,7 @@ int run_benchmark(
fused_embedding_table.data(),
indices_32.data(),
mapping_table.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand All @@ -203,7 +202,7 @@ int run_benchmark(
fused_embedding_table.data(),
indices.data(),
mapping_table.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
normalize_by_lengths,
output_ref.data());
Expand Down Expand Up @@ -235,7 +234,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data(),
mapping_table.data());
Expand All @@ -246,7 +245,7 @@ int run_benchmark(
num_rows,
fused_embedding_table.data(),
indices.data(),
offsets.data(),
lengths.data(),
has_weight ? weights.data() : nullptr,
output.data(),
mapping_table.data());
Expand All @@ -259,7 +258,7 @@ int run_benchmark(
cache_evict(fused_embedding_table);
cache_evict(indices);
cache_evict(indices_32);
cache_evict(offsets);
cache_evict(lengths);
cache_evict(weights);
cache_evict(output);
}
Expand Down
13 changes: 6 additions & 7 deletions bench/RowwiseAdagradFusedBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ void run_benchmark(
// Generate lengths
uniform_int_distribution<int> length_distribution(
1, std::min(2 * average_len + 1, num_rows));
vector<int> offsets(batch_size + 1);
offsets[0] = 0;
vector<int> lengths(batch_size);
for (int i = 0; i < batch_size; ++i) {
offsets[i + 1] = offsets[i] + length_distribution(generator);
lengths[i] = length_distribution(generator);
}

// Compute the number of indices
int lengths_sum = offsets[batch_size];
int lengths_sum = accumulate(lengths.begin(), lengths.end(), 0);
cout << "lengths_sum " << lengths_sum << endl;

// Generate indices
Expand All @@ -93,7 +92,7 @@ void run_benchmark(
random_shuffle(container.begin(), container.end());
copy(
container.begin(),
container.begin() + (offsets[i + 1] - offsets[i]),
container.begin() + lengths[i],
back_inserter(indices));
}
copy(begin(indices), end(indices), back_inserter(indices_32));
Expand Down Expand Up @@ -131,7 +130,7 @@ void run_benchmark(
g.data(),
h.data(),
indices_32.data(),
offsets.data(),
lengths.data(),
epsilon,
lr);
} else {
Expand All @@ -143,7 +142,7 @@ void run_benchmark(
g.data(),
h.data(),
indices.data(),
offsets.data(),
lengths.data(),
epsilon,
lr);
}
Expand Down
Loading

0 comments on commit 7ed5f9f

Please sign in to comment.