ARM-software / vulkan-sdk

Github repository for the Vulkan SDK
Other
228 stars 49 forks source link

Why do write-after-read and read-after-read hazards only require execution dependencies to synchronize? #25

Closed flowerdancedatou closed 5 years ago

flowerdancedatou commented 5 years ago

Memory dependencies are used to solve data hazards, e.g. to ensure that write operations are visible to subsequent read operations (read-after-write hazard), as well as write-after-write hazards. Write-after-read and read-after-read hazards only require execution dependencies to synchronize.

Why? Can you help me? Thanks

AttilioProvenzano-ARM commented 5 years ago

Hi,

This is a complex topic to tackle, so it's useful to develop a simpler mental model of it.

Suppose we have a main memory that is relatively slow to access, so we'll want to use caches to reduce memory accesses to a minimum. In this scheme we would want to implement a write back policy so we keep written data in cache and only propagate them to the main memory when necessary.

Let us now suppose that we have a command buffer with asynchronous operations and we add execution dependencies. Here are the possible cases:

As you can see for the latter operations it is not enough to have an execution dependency, we have to add a memory dependency to guarantee that write operations are visible.

Hope that helps!

flowerdancedatou commented 5 years ago

Thank you very much!