Home | History | Annotate | Line # | Download | only in Basic
      1 //===--- Cuda.h - Utilities for compiling CUDA code  ------------*- C++ -*-===//
      2 //
      3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4 // See https://llvm.org/LICENSE.txt for license information.
      5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6 //
      7 //===----------------------------------------------------------------------===//
      8 
      9 #ifndef LLVM_CLANG_BASIC_CUDA_H
     10 #define LLVM_CLANG_BASIC_CUDA_H
     11 
     12 namespace llvm {
     13 class StringRef;
     14 class Twine;
     15 class VersionTuple;
     16 } // namespace llvm
     17 
     18 namespace clang {
     19 
     20 enum class CudaVersion {
     21   UNKNOWN,
     22   CUDA_70,
     23   CUDA_75,
     24   CUDA_80,
     25   CUDA_90,
     26   CUDA_91,
     27   CUDA_92,
     28   CUDA_100,
     29   CUDA_101,
     30   CUDA_102,
     31   CUDA_110,
     32   CUDA_111,
     33   CUDA_112,
     34   LATEST = CUDA_112,
     35   LATEST_SUPPORTED = CUDA_101,
     36 };
     37 const char *CudaVersionToString(CudaVersion V);
     38 // Input is "Major.Minor"
     39 CudaVersion CudaStringToVersion(const llvm::Twine &S);
     40 
     41 enum class CudaArch {
     42   UNUSED,
     43   UNKNOWN,
     44   SM_20,
     45   SM_21,
     46   SM_30,
     47   SM_32,
     48   SM_35,
     49   SM_37,
     50   SM_50,
     51   SM_52,
     52   SM_53,
     53   SM_60,
     54   SM_61,
     55   SM_62,
     56   SM_70,
     57   SM_72,
     58   SM_75,
     59   SM_80,
     60   SM_86,
     61   GFX600,
     62   GFX601,
     63   GFX602,
     64   GFX700,
     65   GFX701,
     66   GFX702,
     67   GFX703,
     68   GFX704,
     69   GFX705,
     70   GFX801,
     71   GFX802,
     72   GFX803,
     73   GFX805,
     74   GFX810,
     75   GFX900,
     76   GFX902,
     77   GFX904,
     78   GFX906,
     79   GFX908,
     80   GFX909,
     81   GFX90a,
     82   GFX90c,
     83   GFX1010,
     84   GFX1011,
     85   GFX1012,
     86   GFX1030,
     87   GFX1031,
     88   GFX1032,
     89   GFX1033,
     90   GFX1034,
     91   LAST,
     92 };
     93 
     94 static inline bool IsNVIDIAGpuArch(CudaArch A) {
     95   return A >= CudaArch::SM_20 && A < CudaArch::GFX600;
     96 }
     97 
     98 static inline bool IsAMDGpuArch(CudaArch A) {
     99   return A >= CudaArch::GFX600 && A < CudaArch::LAST;
    100 }
    101 
    102 const char *CudaArchToString(CudaArch A);
    103 const char *CudaArchToVirtualArchString(CudaArch A);
    104 
    105 // The input should have the form "sm_20".
    106 CudaArch StringToCudaArch(llvm::StringRef S);
    107 
    108 /// Get the earliest CudaVersion that supports the given CudaArch.
    109 CudaVersion MinVersionForCudaArch(CudaArch A);
    110 
    111 /// Get the latest CudaVersion that supports the given CudaArch.
    112 CudaVersion MaxVersionForCudaArch(CudaArch A);
    113 
    114 //  Various SDK-dependent features that affect CUDA compilation
    115 enum class CudaFeature {
    116   // CUDA-9.2+ uses a new API for launching kernels.
    117   CUDA_USES_NEW_LAUNCH,
    118   // CUDA-10.1+ needs explicit end of GPU binary registration.
    119   CUDA_USES_FATBIN_REGISTER_END,
    120 };
    121 
    122 CudaVersion ToCudaVersion(llvm::VersionTuple);
    123 bool CudaFeatureEnabled(llvm::VersionTuple, CudaFeature);
    124 bool CudaFeatureEnabled(CudaVersion, CudaFeature);
    125 
    126 } // namespace clang
    127 
    128 #endif
    129