VTKmDetectCUDAVersion.cu 1.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
//=============================================================================
//
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//
11
//  Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
12 13 14
//  Copyright 2015 UT-Battelle, LLC.
//  Copyright 2015 Los Alamos National Security.
//
15
//  Under the terms of Contract DE-NA0003525 with NTESS,
16 17 18 19 20 21
//  the U.S. Government retains certain rights in this software.
//  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
//  Laboratory (LANL), the U.S. Government retains certain rights in
//  this software.
//
//=============================================================================
22
#include <cstdio>
23 24 25 26 27
#include <cuda.h>
#include <cuda_runtime.h>
int main()
{
  int count = 0;
28 29 30 31
  if (cudaSuccess != cudaGetDeviceCount(&count))
    return 1;
  if (count == 0)
    return 1;
32 33 34

  int prev_arch = 0;
  for (int device = 0; device < count; ++device)
35
  {
36 37
    cudaDeviceProp prop;
    if (cudaSuccess == cudaGetDeviceProperties(&prop, device))
38
    {
39 40 41
      int arch = (prop.major * 10) + prop.minor;
      int compute_level = arch;
      //arch 21 has no equivalent compute level.
42 43 44 45
      if (compute_level == 21)
      {
        compute_level = 20;
      }
46 47

      //handle multiple cards of the same architecture
48 49 50 51
      if (arch == prev_arch)
      {
        continue;
      }
52
      prev_arch = arch;
53 54 55 56

      //we need to print out a semi-colon as this needs to be output
      //as a CMake list which is separated by semicolons
      printf("--generate-code=arch=compute_%d,code=sm_%d;", compute_level, arch);
57
    }
58
  }
59
  return 0;
60
}