Lift
Library of parallel computing primitives for GPUs and multi-core CPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
compute_device_host.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 
36 #include <lift/types.h>
38 
39 namespace lift {
40 
41 // describes a CPU cache
42 struct cpu_cache
43 {
44  typedef enum {
45  null = 0, // invalid token
46  data, // data only cache
47  instruction, // instruction cache
48  unified, // unified (data + instruction) cache
49  } cache_type;
50 
54  uint32 total_size; // in bytes
55  uint32 line_size; // in bytes
56 };
57 
58 struct cpu_config
59 {
60  std::string name;
62  std::vector<cpu_cache> caches;
63 
64  // number of concurrent threads that can run on the CPU
65  // note that this value may be affected by the affinity mask for the process
67 
69  : name(),
71  caches(),
72  num_threads(0)
73  { }
74 };
75 
76 namespace __internal {
77 // the appropriate arch-specific implementation is chosen at compile-time by the build system
78 extern cpu_config identify_host_cpu(void);
79 } // namespace __internal
80 
82 {
84 
85  // this value is configurable; it is meant to hold the number of threads
86  // that are effectively enabled for this compute device
88 
91  {
92  if (num_threads == uint32(-1))
94  }
95 
96  virtual target_system get_system(void) override
97  {
98  return host;
99  }
100 
101  virtual void enable(void) override
102  { }
103 
104  virtual const char *get_name(void) override
105  {
106  return config.name.c_str();
107  }
108 
109  static bool runtime_initialize(std::string& ret)
110  {
111  ret = std::string("Intel TBB");
112  return true;
113  }
114 
116  {
118  return config.num_threads;
119  }
120 };
121 
122 } // namespace lift
virtual const char * get_name(void) override
uint32_t uint32
Definition: types.h:43
cpu_config identify_host_cpu(void)
std::vector< cpu_cache > caches
virtual target_system get_system(void) override
static bool runtime_initialize(std::string &ret)
virtual void enable(void) override
compute_device_host(uint32 num_threads=uint32(-1))
target_system
Definition: backends.h:36