domains.h
5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* domains.h
*
* Created on: 06/01/2017
* Author: Pedro
*/
#ifndef SRC_DOMAINS_H_
#define SRC_DOMAINS_H_
// Host configuration
#ifndef __OPENCL_VERSION__
#include <stdbool.h>
#include <stddef.h>
#include <sys/types.h>
#include "CL/cl.h"
#include "CL/cl_platform.h"
// when interval domains are used
typedef cl_ushort2 interval; // [16-bits;16-bits] <-> [min,max]
#ifndef BITS
#define BITS 1024 // Bitmap size used on host
#endif
#ifndef H_WORD
#define H_WORD 64 // Size of words used on host
#endif
// host word parameters
#if H_WORD < 33
#define H_ONE 1U // 32 bits bitmap with value 1 in host
#define H_DIV 5 // right shift value to apply division to 32 bits bitmap in host
#define H_WORD_TYPE cl_uint // single 32 bits word bitmap type in host
#else
#define H_ONE 1ULL // 64 bits bitmap with value 1 in host in host
#define H_DIV 6 // right shift value to apply division to 64 bits bitmap in host
#define H_WORD_TYPE cl_ulong // single 64 bits word bitmap type in host
#endif
#define H_ALL_ONES ((H_WORD_TYPE) -1) // 32 or 64 bits bitmap fill with 1 in host
#if BITS < 33
#define H_N_WORDS 1 // number of words that represent the bitmap (CSP variable domain) in host
#define H_BITS 32 // number of bits of one bitmap word in host
#elif BITS < 65
#if H_WORD == 64
#define H_N_WORDS 1 // number of words that represent the bitmap (CSP variable domain) in host
#else
#define H_N_WORDS 2 // number of words that represent the bitmap (CSP variable domain) in host
#endif
#define H_BITS 64 // number of bits of one bitmap word in host
#else
#if (BITS % 64) > 0
#define H_BITS (BITS / 64 * 64 + 64) // number of bits of one bitmap word in host
#else
#define H_BITS (BITS / 64 * 64) // number of bits of one bitmap word in host
#endif
#define H_N_WORDS H_BITS / H_WORD // number of words that represent the bitmap (CSP variable domain) in host
#endif
#if H_N_WORDS == 1
typedef H_WORD_TYPE bitmap; // bitmap of type cl_uint or cl_ulong in host
#else
typedef H_WORD_TYPE bitmap[H_N_WORDS]; // bitmap with an array of cl_uint or cl_ulong in host
#endif
// never used. Just for compilation and syntax correction
#define CL_BITMAP 0
#define CL_INTERVAL 1
#define CL_D_TYPE CL_BITMAP
#define DOMAIN_ cl_bitmap
#define CL_D_MIN 0
// 32 bits 1 word
#define CL_WORD 32
#define CL_BITS 32
#define CL_D_MAX 32
#define CL_ONE_ 1U
#define CL_DIV 5
#define CL_REM 31
#define CL_N_WORDS 1
#define CL_WORD_TYPE cl_uint
typedef CL_WORD_TYPE cl_bitmap;
/*
// 64 bits 1 word
#define CL_WORD 64
#define CL_BITS 64
#define CL_D_MAX 64
#define CL_ONE_ 1UL
#define CL_DIV 6
#define CL_REM 63
#define CL_N_WORDS 1
#define CL_WORD_TYPE cl_ulong
typedef CL_WORD_TYPE cl_bitmap;
*/
/*
// 64 bits 2 words
#define CL_WORD 64
#define CL_BITS 128
#define CL_D_MAX 128
#define CL_ONE_ 1UL
#define CL_DIV 6
#define CL_REM 63
#define CL_N_WORDS 2
#define CL_WORD_TYPE cl_ulong
typedef CL_WORD_TYPE cl_bitmap[CL_N_WORDS];
*/
#define CL_ALL_ONES ((CL_WORD_TYPE) -1)
// Device configuration (used during kernel compilation)
#else
// Choose domains size on OpenCL kernel compilation
// host word parameters
#if CL_WORD < 33
#define CL_ONE_ 1U // 32 bits bitmap with value 1 in device
#define CL_DIV 5 // right shift value to apply division to 32 bits bitmap in device
#define CL_REM 31 // right shift value to apply multiplication to 32 bits bitmap in device
#define CL_WORD_TYPE uint // single32 bits word bitmap type in device
#else
#define CL_ONE_ 1UL // 64 bits bitmap with value 1 in device
#define CL_DIV 6 // right shift value to apply division to 64 bits bitmap in device
#define CL_REM 63 // right shift value to apply multiplication to 64 bits bitmap in device
#define CL_WORD_TYPE ulong // single 64 bits word bitmap type in device
#endif
#define CL_ALL_ONES ((CL_WORD_TYPE) -1) // 32 or 64 bits bitmap fill with 1 in device
#if CL_BITS < 33
#define CL_N_WORDS 1 // number of words that represent the bitmap (CSP variable domain) in host
#elif CL_BITS < 65
#if CL_WORD == 32
#define CL_N_WORDS 2 // number of words that represent the bitmap (CSP variable domain) in host
#else
#define CL_N_WORDS 1 // number of words that represent the bitmap (CSP variable domain) in host
#endif
#else
#define CL_N_WORDS (CL_BITS / CL_WORD) // number of words that represent the bitmap (CSP variable domain) in device
#endif
#if CL_N_WORDS == 1
typedef CL_WORD_TYPE cl_bitmap; // single 32 or 64 bits word bitmap type in device
#else
typedef CL_WORD_TYPE cl_bitmap[CL_N_WORDS]; // single 64 bits word bitmap type in device
#endif
// types of representation of the domain of the CSP variables in the device
#define CL_BITMAP 0 // bitmaps
#define CL_INTERVAL 1 // single interval [16-bits;16-bits] = [min;max]
// default type of representation of the domain of the CSP variables in the device
#ifndef CL_D_TYPE
#define CL_D_TYPE CL_BITMAP
#endif
#if CL_D_TYPE == CL_BITMAP // bitmap representation structures
#define DOMAIN_ cl_bitmap
#define VARS cl_var_bitmap
#define VARS_PROP cl_var_p_bitmap
#elif CL_D_TYPE == CL_INTERVAL // interval representation structures
typedef ushort2 interval;
#define DOMAIN_ interval
#define VARS cl_var_interval
#define VARS_PROP cl_var_p_interval
#endif
// default maximum domain value
#ifndef CL_D_MAX
#define CL_D_MAX 32
#endif
// default minimum domain value
#ifndef CL_D_MIN
#define CL_D_MIN 0
#endif
#endif
#endif /* SRC_DOMAINS_H_ */