Lift
Library of parallel computing primitives for GPUs and multi-core CPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
compute_device_cuda.h
Go to the documentation of this file.
1 /*
2  * Lift
3  *
4  * Copyright (c) 2014-2015, NVIDIA CORPORATION
5  * Copyright (c) 2015, Nuno Subtil <subtil@gmail.com>
6  * Copyright (c) 2015, Roche Molecular Systems, Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * * Neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #pragma once
33 
34 #include <vector>
35 #include <string>
36 
38 
39 namespace lift {
40 
42 {
43  int device;
44  char *device_name;
48 
50  : device(-1),
51  device_name(nullptr),
52  total_memory(uint64(-1)),
55  { }
56 
57  cuda_device_config(int dev);
58 
59  // enumerate the GPUs that match a set of minimum requirements
60  // returns false if an error occurs
61  static bool enumerate_gpus(std::vector<cuda_device_config>& devices,
62  std::string& error,
63  const cuda_device_config& requirements = cuda_device_config());
64 };
65 
67 {
69 
71  : config(config)
72  { }
73 
74  virtual target_system get_system(void) override
75  {
76  return cuda;
77  }
78 
79  virtual void enable(void) override
80  {
81  cudaSetDevice(config.device);
82  }
83 
84  virtual const char *get_name(void) override
85  {
86  return config.device_name;
87  }
88 
89  static bool runtime_initialize(std::string& ret);
90 };
91 
92 } // namespace lift
virtual void enable(void) override
virtual const char * get_name(void) override
uint64_t uint64
Definition: types.h:45
virtual target_system get_system(void) override
const cuda_device_config config
static bool enumerate_gpus(std::vector< cuda_device_config > &devices, std::string &error, const cuda_device_config &requirements=cuda_device_config())
target_system
Definition: backends.h:36
static bool runtime_initialize(std::string &ret)
compute_device_cuda(const cuda_device_config &config)