[Openmp-commits] [PATCH] D131567: [Libomptarget][CUDA] Check CUDA compatibilty correctly

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Aug 10 06:59:34 PDT 2022


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, ye-luo, JonChesterfield, ronlieb, tianshilei1992.
Herald added subscribers: mattd, carlosgalvezp, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

We recently added support for multi-architecture binaries in
libomptarget. This is done by extracting the architecture from the
embedded image and comparing it with the major and minor version
supported by the current CUDA installation. Previously we just compared
these directly, which was not correct for binary compatibility. The CUDA
documentation states that we can consider any image with an equivalent
major or a greater or equal to minor compatible with the current image.
Change the check to use this new logic in the CUDA plugin.

Fixes #57049


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131567

Files:
  openmp/libomptarget/plugins/cuda/src/rtl.cpp


Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -10,6 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/ADT/StringRef.h"
+
 #include <algorithm>
 #include <cassert>
 #include <cstddef>
@@ -33,6 +35,8 @@
 
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 
+using namespace llvm;
+
 // Utility for retrieving and printing CUDA error string.
 #ifdef OMPTARGET_DEBUG
 #define CUDA_ERR_STRING(err)                                                   \
@@ -1529,13 +1533,14 @@
     return false;
 
   // A subarchitecture was not specified. Assume it is compatible.
-  if (!info->Arch)
+  if (!info || !info->Arch)
     return true;
 
   int32_t NumberOfDevices = 0;
   if (cuDeviceGetCount(&NumberOfDevices) != CUDA_SUCCESS)
     return false;
 
+  StringRef ArchStr = StringRef(info->Arch).drop_front(sizeof("sm_"));
   for (int32_t DeviceId = 0; DeviceId < NumberOfDevices; ++DeviceId) {
     CUdevice Device;
     if (cuDeviceGet(&Device, DeviceId) != CUDA_SUCCESS)
@@ -1551,8 +1556,12 @@
                              Device) != CUDA_SUCCESS)
       return false;
 
-    std::string ArchStr = "sm_" + std::to_string(Major) + std::to_string(Minor);
-    if (ArchStr != info->Arch)
+    // A cubin generated for a certain compute capability is supported to run on
+    // any GPU with the same major revision and same or higher minor revision of
+    // compute capability.
+    int32_t ImageMajor = ArchStr[0] - '0';
+    int32_t ImageMinor = ArchStr[1] - '0';
+    if (Major != ImageMajor || Minor < ImageMinor)
       return false;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131567.451446.patch
Type: text/x-patch
Size: 1773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220810/3fac7102/attachment.bin>


More information about the Openmp-commits mailing list