[llvm] [RFC][AMDGPU] Add vulkan:private/nonprivate MMRAs support (PR #78573)

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 22:13:31 PDT 2024


================
@@ -679,15 +713,39 @@ class SIMemoryLegalizer final : public MachineFunctionPass {
   bool runOnMachineFunction(MachineFunction &MF) override;
 };
 
-} // end namespace anonymous
-
-void SIMemOpAccess::reportUnsupported(const MachineBasicBlock::iterator &MI,
-                                      const char *Msg) const {
+void reportUnsupported(const MachineBasicBlock::iterator &MI, const char *Msg,
+                       bool Warn = false) {
   const Function &Func = MI->getParent()->getParent()->getFunction();
-  DiagnosticInfoUnsupported Diag(Func, Msg, MI->getDebugLoc());
+  DiagnosticInfoUnsupported Diag(Func, Msg, MI->getDebugLoc(),
+                                 Warn ? DS_Warning : DS_Error);
   Func.getContext().diagnose(Diag);
 }
 
+} // namespace
+
+VulkanOpKind SIMemOpAccess::getVulkanOpKind(const MachineInstr &MI) const {
+  VulkanOpKind VKOK = VulkanOpKind::None;
+
+  if (auto MMRA = MMRAMetadata(MI.getMMRAMetadata())) {
+    if (MMRA.hasTag("vulkan", "private"))
+      return VulkanOpKind::Private;
+    else if (MMRA.hasTag("vulkan", "nonprivate"))
+      return VulkanOpKind::NonPrivate;
+  }
+
+  // Don't cry if amdgcn-force-vulkan-memorymodel=0, that way it can be used as
+  // an escape hatch to force-ignore vulkan MMRAs.
+  if (!HasVulkanMM && VKOK != VulkanOpKind::None &&
+      ForceVulkanMM != cl::BOU_FALSE) {
+    report_fatal_error(
+        "vulkan:private/nonprivate annotations can only be honored if the "
+        "Vulkan memory model is enabled. Strip vulkan MMRAs or disable the "
+        "Vulkan memory model using -amdgcn-force-vulkan-memorymodel=0");
+  }
----------------
ssahasra wrote:

If we go by the MMRA spec when we implement Vulkan private/nonprivate in CodeGen, every non-SPIRV program targetting AMDGPU will have really bad performance. This is because currently we cache every memory access by default, but in a world where MMRAs already existed, whether to cache a memory access is an optimization. If no tag is present, then the access should not be cached in this alternate reality.

For now, this behaviour will get enabled if the user opts into the vulkan memory model:

- Memory accesses with no Vulkan tag are not cached because that is the safest option.
- Those marked private may be cached.
- Those marked non-private must not be cached.

https://github.com/llvm/llvm-project/pull/78573


More information about the llvm-commits mailing list