17

The AVX512CD instruction families are: VPCONFLICT, VPLZCNT and VPBROADCASTM.

The Wikipedia section about these instruction says:

The instructions in AVX-512 conflict detection (AVX-512CD) are designed to help efficiently calculate conflict-free subsets of elements in loops that normally could not be safely vectorized.

What are some examples that show these instruction being useful in vectorizing loops? It would be helpful if answers will include scalar loops and their vectorized counterparts.

Thanks!

1

1 Answer 1

15

One example where the CD instructions might be useful is histogramming. For scalar code histogramming is just a simple loop like this:

load bin index
load bin count at index
increment bin count
store updated bin count at index

Normally you can't vectorize histogramming because you might have the same bin index more than once in a vector - you might naïvely try something like this:

load vector of N bin indices
perform gathered load using N bin indices to get N bin counts
increment N bin counts
store N updated bin counts using scattered store

but if any of the indices within a vector are the same then you get a conflict, and the resulting bin update will be incorrect.

So, CD instructions to the rescue:

load vector of N bin indices
use CD instruction to test for duplicate indices
set mask for all unique indices
while mask not empty
    perform masked gathered load using <N bin indices to get <N bin counts
    increment <N bin counts
    store <N updated bin counts using masked scattered store
    remove non-masked indices and update mask
end

In practice this example is quite inefficient and no better than scalar code, but there are other more compute-intensive examples where using the CD instructions seems to be worthwhile. Typically these will be simulations where the data elements are going to be updated in a non-deterministic fashion. One example (from the LAMMPS Molecular Dynamics Simulator) is referred to in the KNL book by Jeffers et al.

13
  • 2
    See also page 50 of Kirill Yukhin's slides from 2014. I posted some stuff about speeding up histogram-type problems with/without AVX512CD on a recent question. The usual trick of cloning your bins and totalling at the end can help avoid conflicts (and store-forwarding data dependency bottlenecks even for scalar). Oct 7, 2016 at 16:26
  • Thanks Peter - I hadn't seen those slides before - some interesting tidbits in there...
    – Paul R
    Oct 7, 2016 at 16:35
  • 1
    Section "16.2.3 Using AVX-512CD Instructions" of the Intel optimization manuals describes this exactly. See example "Example 16-4. Vectorized Histogram Update Using AVX-512CD". Is that where you got this idea? How do you know it's not really better than scalar? Have you tried it in practice with KNL?
    – Z boson
    Dec 27, 2016 at 18:06
  • @Zboson: No, I don't think I'd seen that (I think my main reference was the Jeffers book linked to above), but I did benchmark some of this stuff on KNL a few months back and it didn't seem to be too impressive. I ran out of time though, so may revisit it when I get a chance.
    – Paul R
    Dec 27, 2016 at 20:25
  • 1
    Maybe you can put your code here? I am thinking of trying to implement this with KNL. When did you get access to KNL?
    – Z boson
    Dec 27, 2016 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.