skozilla / word2vec

Automatically exported from code.google.com/p/word2vec
Apache License 2.0
0 stars 0 forks source link

word2vec.c: Minor tweak to reduce CPU pipeline stalls (3% gain) #36

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The perf utility reported a bottleneck in this area, where it's waiting for the 
'target' variable to be finalized. By computing the next value of target early, 
overall performance is increased by about 3% on a small (128MB) training file.

add next_target next to target in the variable list.

Then in the two negative sampling blocks:
...
          if (d == 0) {
            target = word;
            label = 1;
            next_random = next_random * (unsigned long long)25214903917 + 11;
            next_target = table[(next_random >> 16) % table_size];
          } else {
            target = next_target;
            if (target == 0) target = next_random % (vocab_size - 1) + 1;
            next_random = next_random * (unsigned long long)25214903917 + 11;
            next_target = table[(next_random >> 16) % table_size];
            if (target == word) continue;
            label = 0;
          }
...

Original issue reported on code.google.com by chad.p...@gmail.com on 22 Jul 2015 at 6:40

GoogleCodeExporter commented 9 years ago
Potentially disregard, might not be valid.  But there are a ton of pipeline 
stalls in word2vec.

One thing that might have similar effect is to move next_random's value-getting 
after using the value for target.

Original comment by chad.p...@gmail.com on 22 Jul 2015 at 4:05