Lift
Library of parallel computing primitives for GPUs and multi-core CPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
backends.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 namespace lift {
35 
37 {
40 };
41 
42 } // namespace lift
43 
44 #if defined(__CUDACC__)
45 
46 #include <thrust/device_vector.h>
47 
48 #include <thrust/system/cuda/vector.h>
49 
50 #endif
51 
52 #include <thrust/system/tbb/vector.h>
53 #include <thrust/execution_policy.h>
54 
55 namespace lift {
56 
57 template <target_system system>
59 { };
60 
61 
62 template <>
64 {
65  typedef thrust::system::cuda::tag tag;
66 
67  static inline decltype(thrust::cuda::par) execution_policy(void)
68  {
69  return thrust::cuda::par;
70  }
71 };
72 
73 template <>
75 {
76  typedef thrust::system::tbb::tag tag;
77 
78  static inline decltype(thrust::tbb::par) execution_policy(void)
79  {
80  return thrust::tbb::par;
81  }
82 };
83 
84 } // namespace lift
85 
86 // ugly macro hackery to force arbitrary device function / method instantiation
87 // note: we intentionally never instantiate device functions for the host system
88 #define __FUNC_CUDA(fun) void *ptr_cuda = (void *)fun<lift::cuda>;
89 #define __METHOD_CUDA(base, method) void *ptr_cuda = (void *)&base<lift::cuda>::method;
90 
91 #define __FUNC_TBB(fun) auto *ptr_TBB= (void *)fun<lift::host>;
92 #define __METHOD_TBB(base, method) auto ptr_TBB = (void *)&base<lift::host>::method;
93 
94 // free function instantiation
95 #define INSTANTIATE(fun) \
96  namespace __ ## fun ## __instantiation { \
97  __FUNC_CUDA(fun); \
98  __FUNC_TBB(fun); \
99  }
100 
101 // method instantiation
102 #define METHOD_INSTANTIATE(base, method) \
103  namespace __ ## base ## __ ## method ## __instantiation { \
104  __METHOD_CUDA(base, method); \
105  __METHOD_TBB(base, method); \
106  }
thrust::system::tbb::tag tag
Definition: backends.h:76
thrust::system::cuda::tag tag
Definition: backends.h:65
target_system
Definition: backends.h:36