-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkernel.cu
761 lines (689 loc) · 23.7 KB
/
kernel.cu
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
#define GPU_HOST_ATTR __device__ __host__
#include <cuda_runtime.h>
#include <cuda.h>
#include <stdio.h>
#include <stdint.h>
#include <gpusat_types.h>
#include "kernel.h"
// TODO: get rid of RunMeta
namespace gpusat {
__device__ int64_t get_global_id(uint64_t minId, uint64_t maxId) {
// TODO: y and z
int64_t id = blockDim.x * blockIdx.x + threadIdx.x + minId;
if (id >= maxId) {
return -1;
}
return id;
}
/**
* combines two tree structure into one
*
* @param numVars
* the number of variables in the bag
* @param tree
* a pointer to the tree structure which will receive all the models from the other tree
* @param solutions_old
* a pointer to the old tree structure
* @param treeSize
* the number of nodes in the tree
* @param startId
* the start id of the current node
*/
__global__ void combineTree(
TreeSolution<GpuOnly>* to,
const TreeSolution<GpuOnly>* from
) {
// this is is relative to the <from>-tree
int64_t id = get_global_id(from->minId(), from->maxId());
if (id < 0) {
return;
}
double val = from->solutionCountFor(id);
if (val > 0) {
to->setCount(id, val);
}
}
/**
* Operation to solve a Introduce node in the decomposition.
*
* @param variables
* the ids of the variables in the current bag
* @param edge
* the number of models for each assignment of the next bag
* @param edgeVariables
* variables in the next bag
* @param minId
* the start id of the last bag
* @param maxId
* the end id of the last bag
* @param weights
* the variables weights for weighted model counting
* @param id
* the id for which the introduce should be solved
* @return
* the model count
*/
template<class T>
__device__ double solveIntroduce_(
GPUVars variables,
const T& edge,
GPUVars edgeVariables,
double *weights,
int64_t id
) {
int64_t otherId = 0;
int64_t a = 0, b = 0;
double weight = 1.0;
for (b = 0; b < edgeVariables.count && a < variables.count; b++) {
while ((variables.vars[a] != edgeVariables.vars[b])) {
a++;
}
otherId = otherId | (((id >> a) & 1) << b);
a++;
};
//weighted model count
if (weights != 0) {
for (b = 0, a = 0; a < variables.count; a++) {
if (edgeVariables.vars == 0 || (variables.vars[a] != edgeVariables.vars[b])) {
weight *= weights[((id >> a) & 1) > 0 ? variables.vars[a] * 2 : variables.vars[a] * 2 + 1];
}
if (edgeVariables.vars != 0 && (variables.vars[a] == edgeVariables.vars[b]) && (b < (edgeVariables.count - 1))) {
b++;
}
}
}
if (edge.hasData() && otherId >= edge.minId() && otherId < edge.maxId()) {
return max(edge.solutionCountFor(otherId) * weight, 0.0);
} else if (!edge.hasData() && otherId >= edge.minId() && otherId < edge.maxId()) {
return 0.0;
} else {
// prevent inclusion of this branch
return -1.0;
}
}
/**
* Operation to check if an assignment satisfies the clauses of a SAT formula.
*
* @param clauses
* the clauses in the SAT formula
* @param numVarsC
* array containing the number of Variables in each clause
* @param numclauses
* the number of clauses in the sat formula
* @param id
* the id of the thread - used to get the variable assignment
* @param variables
* a vector containing the ids of the variables
* @return
* 1 - if the assignment satisfies the formula
* 0 - if the assignment doesn't satisfy the formula
*/
__device__ int checkBag(uint64_t *clauses, long numClauses, int64_t id, GPUVars variables) {
uint64_t unsigned_id = abs(id);
for (long i = 0; i < numClauses; i++) {
uint64_t c_vars = clauses[2*i];
uint64_t c_neg = clauses[2*i+1];
if (((unsigned_id^c_neg) & c_vars) == 0) {
return 0;
}
}
return 1;
}
/**
* Operation to solve a Join node in the decomposition.
*
* @param solutions
* the number of solutions of the join
* @param edge1
* contains the number of solutions in the first edge
* @param edge2
* contains the number of solutions in the second edge
* @param variables
* the variables in the join bag
* @param edgeVariables1
* the variables in the bag of the first edge
* @param edgeVariables2
* the variables in the bag of the second edge
* @param numV
* the number of variables in the join bag
* @param minId1
* the start id of the first edge
* @param maxId1
* the end id of the first edge
* @param minId2
* the start id of the second edge
* @param maxId2
* the end id of the second edge
* @param startIDNode
* the start id of the current node
* @param weights
* the variable weights for weighted model counting
* @param sols
* the number of assignments which lead to a solution
* @param value
* correction value for the exponents
* @param exponent
* the max exponent of this run
*/
template <class T, class E1, class E2>
__global__ void solveJoin(
T* solution,
E1* edge1,
E2* edge2,
GPUVars variables,
GPUVars edgeVariables1,
GPUVars edgeVariables2,
//int64_t startIDNode,
//int64_t startIDEdge1,
//int64_t startIDEdge2,
double *weights,
//uint64_t *sols,
double value,
int32_t *exponent,
const SolveConfig cfg
) {
int64_t id = get_global_id(solution->minId(), solution->maxId());
if (id < 0) {
return;
}
double edge1_solutions = -1.0;
double edge2_solutions = -1.0;
double weight = 1.0;
if (edge1 != nullptr) {
edge1_solutions = solveIntroduce_(variables, *edge1, edgeVariables1, weights, id);
}
if (edge2 != nullptr) {
edge2_solutions = solveIntroduce_(variables, *edge2, edgeVariables2, weights, id);
}
// weighted model count
if (weights != 0) {
for (long a = 0; a < variables.count; a++) {
weight *= weights[((id >> a) & 1) > 0 ? variables.vars[a] * 2 : variables.vars[a] * 2 + 1];
}
}
double solution_value = -1.0;
// indicates that this value is incomplete
// and should not yet be used to derive a possible exponent
bool value_incomplete = false;
// do both edges have an entry for edge1 and edge2?
if (edge1_solutions >= 0.0 && edge2_solutions >= 0.0) {
// only store a solution if both edges have a count > 0
if (edge1_solutions > 0.0 && edge2_solutions > 0.0) {
solution->setSatisfiability(true);
// we do not need to consider the old solution
// count in this bag, because each id can only occur
// in an edge node once, and here the id occurs for both edges.
solution_value = edge1_solutions * edge2_solutions / weight;
//atomicAdd(sols, 1);
if (!cfg.no_exponent) {
solution_value /= value;
}
}
// we need to consider individual edges and maybe look
// at we have already stored for the current id.
} else if (edge1_solutions >= 0.0 || edge2_solutions >= 0.0) {
double oldVal = solution->solutionCountFor(id);
// if the solution was not present before, multiply with one.
if (oldVal < 0.0) {
value_incomplete = true;
oldVal = 1.0;
}
// In order to not use weight and value twice,
// move them to different branches of the calculation.
// If one edge is 0, the whole will be 0 anyway.
// edge 1 has the solution
if (edge1_solutions > 0.0) {
// use weight here
solution_value = edge1_solutions * oldVal / weight;
} else if (edge2_solutions > 0.0) {
solution_value = edge2_solutions * oldVal;
// use value here
if (!cfg.no_exponent) {
solution_value /= value;
}
} else {
solution_value = 0.0;
}
}
// if we found solutions, store them
if (solution_value >= 0.0) {
solution->setCount(id, solution_value);
if (!value_incomplete) {
solution->setSatisfiability(true);
if (!cfg.no_exponent) {
atomicMax(exponent, ilogb(solution_value));
}
}
}
}
/**
* Operation to solve an Introduce
*
* @param clauses
* the clauses in the sat formula
* @param numVarsC
* the number of variables for each clause
* @param numclauses
* the number of clauses
* @param variables
* the ids of the variables in the current bag
* @param edge
* the number of models for each assignment of the last bags
* @param edgeVariables
* variables of the last bag
* @param minId
* the start id of the last bag
* @param maxId
* the end id of the last bag
* @param weights
* the variables weights for weighted model counting
* @param id
* the id for which the introduce should be solved
* @return
* the model count
*/
template <class T>
__device__ double solveIntroduceF(
uint64_t *clauses,
long numclauses,
GPUVars variables,
const T* edge,
GPUVars edgeVariables,
double *weights,
long id
) {
double tmp;
if (edge != nullptr && edge->hasData()) {
// get solutions count edge
tmp = solveIntroduce_(variables, *edge, edgeVariables, weights, id);
} else {
// no edge - solve leaf
tmp = 1.0;
//weighted model count
if (weights != 0) {
for (long i = 0; i < variables.count; i++) {
tmp *= weights[((id >> i) & 1) > 0 ? variables.vars[i] * 2 : variables.vars[i] * 2 + 1];
}
}
}
if (tmp > 0.0) {
// check if assignment satisfies the given clauses
int sat = checkBag(clauses, numclauses, id, variables);
if (sat != 1) {
return 0.0;
} else {
return tmp;
}
} else {
return 0.0;
}
}
/**
* Operation to solve a Introduce and Forget node in the decomposition.
*
* @param solsF
* the number of models for each assignment
* @param varsForget
* the variables after the forget operation
* @param solsE
* the solutions from the last node
* @param lastVars
* the variables from the alst oepration
* @param combinations
* the number of assignments for which we have to collect the model counts
* @param minIdE
* start id of the chunk from the last node
* @param maxIdE
* end id of the chunk from the last node
* @param startIDF
* start id of the chung from the current node
* @param sols
* the number of assignments which lead to a solution
* @param varsI
* the variables after the introduce
* @param clauses
* the clauses which only contain variables from the introduce operation
* @param numclauses
* the number of clauses
* @param weights
* the variables weights for weighted model counting
* @param exponent
* the max exponent of this run
* @param value
* correction value for the exponents
*/
template <class T, class E>
__global__ void solveIntroduceForget(
T* solsF,
GPUVars varsForget,
const E* solsE,
GPUVars lastVars,
uint64_t combinations,
GPUVars varsIntroduce,
uint64_t *clauses,
long numclauses,
double *weights,
int32_t *exponent,
double value,
const SolveConfig cfg
) {
int64_t id = get_global_id(solsF->minId(), solsF->maxId());
if (id < 0) {
return;
}
if (varsIntroduce.count != varsForget.count) {
double tmp = 0;
long templateId = 0;
// generate templateId
for (long i = 0, a = 0; i < varsIntroduce.count && a < varsForget.count; i++) {
if (varsIntroduce.vars[i] == varsForget.vars[a]) {
templateId = templateId | (((id >> a) & 1) << i);
a++;
}
}
// iterate though all corresponding edge solutions
for (long i = 0; i < combinations; i++) {
long b = 0, otherId = templateId;
for (long a = 0; a < varsIntroduce.count; a++) {
if (b >= varsForget.count || varsIntroduce.vars[a] != varsForget.vars[b]) {
otherId = otherId | (((i >> (a - b)) & 1) << a);
} else {
b++;
}
}
tmp += solveIntroduceF(clauses, numclauses, varsIntroduce, solsE, lastVars, weights, otherId);
}
if (tmp > 0) {
double last = solsF->solutionCountFor(id);
last = max(last, 0.0);
if (!cfg.no_exponent) {
solsF->setCount(id, (tmp / value + last));
atomicMax(exponent, ilogb((tmp / value + last)));
assert(*exponent != FP_ILOGB0);
} else {
solsF->setCount(id, (tmp + last));
}
solsF->setSatisfiability(true);
}
} else {
// no forget variables, only introduce
double tmp = solveIntroduceF(clauses, numclauses, varsIntroduce, solsE, lastVars, weights, id);
if (tmp > 0) {
double last = solsF->solutionCountFor(id);
last = max(last, 0.0);
if (!cfg.no_exponent) {
solsF->setCount(id, (tmp / value + last));
atomicMax(exponent, ilogb((tmp / value + last)));
assert(*exponent != FP_ILOGB0);
} else {
solsF->setCount(id, (tmp + last));
}
solsF->setSatisfiability(true);
}
}
}
/**
* Clones a solution bag to the GPU,
* this clone uses the data of the <CudaMem> bag it was cloned from
* and does not own it.
*/
template <template<typename> typename T>
std::unique_ptr<T<GpuOnly>, CudaMem> gpuClone(const T<CudaMem>& owner) {
static_assert(sizeof(T<CudaMem>) == sizeof(T<GpuOnly>));
// Note that since clone is malloc'ed here,
// its destructor will not be called.
T<GpuOnly>* clone = nullptr;
gpuErrchk(cudaMalloc(&clone, sizeof(T<GpuOnly>)));
assert(clone != nullptr);
gpuErrchk(cudaMemcpy(clone, &owner, sizeof(T<GpuOnly>), cudaMemcpyHostToDevice));
return std::unique_ptr<T<GpuOnly>, CudaMem>(clone);
}
TreeSolution<CudaMem> combineTreeWrapper(
TreeSolution<CudaMem>& to_owner,
const TreeSolution<CudaMem>& from_owner
) {
auto to_gpu = gpuClone(to_owner);
auto from_gpu = gpuClone(from_owner);
int64_t threadsPerBlock = 512;
int64_t threads = from_owner.maxId() - from_owner.minId();
int64_t blocksPerGrid = (threads + threadsPerBlock - 1) / threadsPerBlock;
combineTree<<<blocksPerGrid, threadsPerBlock>>>(to_gpu.get(), from_gpu.get());
gpuErrchk(cudaDeviceSynchronize());
update(to_owner, to_gpu);
return std::move(to_owner);
}
void solveJoinWrapper(
CudaSolutionVariant& solution_variant,
const std::optional<CudaSolutionVariant>& edge1,
const std::optional<CudaSolutionVariant>& edge2,
GPUVars variables,
GPUVars edgeVariables1,
GPUVars edgeVariables2,
double *weights,
double value,
int32_t *exponent,
const SolveConfig cfg
) {
int64_t threadsPerBlock = 512;
int64_t threads = maxId(solution_variant) - minId(solution_variant);
int64_t blocksPerGrid = (threads + threadsPerBlock - 1) / threadsPerBlock;
assert(edge1.has_value() || edge2.has_value());
std::visit([&](auto& solution) {
auto solution_gpu = gpuClone(solution);
auto single_edge1_join = [&](const CudaSolutionVariant& edge) {
std::visit([&](const auto &edge_owner) {
auto edge_gpu = gpuClone(edge_owner);
solveJoin<<<blocksPerGrid, threadsPerBlock>>>(
solution_gpu.get(),
edge_gpu.get(),
(decltype(edge_gpu.get()))nullptr,
variables,
edgeVariables1,
edgeVariables2,
weights,
value,
exponent,
cfg
);
gpuErrchk(cudaDeviceSynchronize());
}, edge);
};
auto single_edge2_join = [&](const CudaSolutionVariant& edge) {
std::visit([&](const auto &edge_owner) {
auto edge_gpu = gpuClone(edge_owner);
solveJoin<<<blocksPerGrid, threadsPerBlock>>>(
solution_gpu.get(),
(decltype(edge_gpu.get()))nullptr,
edge_gpu.get(),
variables,
edgeVariables1,
edgeVariables2,
weights,
value,
exponent,
cfg
);
gpuErrchk(cudaDeviceSynchronize());
}, edge);
};
auto double_edge_join = [&](const CudaSolutionVariant& e1, const CudaSolutionVariant& e2) {
std::visit([&](const auto &e1_owner) {
auto e1_gpu = gpuClone(e1_owner);
std::visit([&](const auto &e2_owner) {
auto e2_gpu = gpuClone(e2_owner);
solveJoin<<<blocksPerGrid, threadsPerBlock>>>(
solution_gpu.get(),
e1_gpu.get(),
e2_gpu.get(),
variables,
edgeVariables1,
edgeVariables2,
weights,
value,
exponent,
cfg
);
gpuErrchk(cudaDeviceSynchronize());
}, e2);
}, e1);
};
if (edge1.has_value() && !edge2.has_value()) {
single_edge1_join(edge1.value());
} else if (!edge1.has_value() && edge2.has_value()) {
single_edge2_join(edge2.value());
} else {
assert(edge1.has_value() && edge2.has_value());
double_edge_join(edge1.value(), edge2.value());
}
update(solution, solution_gpu);
}, solution_variant);
}
void introduceForgetWrapper(
CudaSolutionVariant& solution_owner,
GPUVars varsForget,
const std::optional<CudaSolutionVariant>& edge,
GPUVars lastVars,
GPUVars varsIntroduce,
// FIXME: Move this static information to GPU once.
uint64_t *clauses,
long numclauses,
double *weights,
int32_t *exponent,
double previous_value,
const SolveConfig cfg
) {
int64_t threadsPerBlock = 512;
int64_t threads = maxId(solution_owner) - minId(solution_owner);
int64_t blocksPerGrid = (threads + threadsPerBlock - 1) / threadsPerBlock;
uint64_t combinations = (uint64_t) pow(2, varsIntroduce.count - varsForget.count);
std::visit([&](auto& solsF) {
auto solution_gpu = gpuClone(solsF);
// leaf node
if (!edge.has_value()) {
solveIntroduceForget<<<blocksPerGrid, threadsPerBlock>>>(
solution_gpu.get(),
varsForget,
(decltype(solution_gpu.get()))nullptr,
lastVars,
combinations,
varsIntroduce,
clauses,
numclauses,
weights,
exponent,
previous_value,
cfg
);
gpuErrchk(cudaDeviceSynchronize());
} else {
std::visit([&](const auto& solsE) {
auto edge_gpu = gpuClone(solsE);
solveIntroduceForget<<<blocksPerGrid, threadsPerBlock>>>(
solution_gpu.get(),
varsForget,
edge_gpu.get(),
lastVars,
combinations,
varsIntroduce,
clauses,
numclauses,
weights,
exponent,
previous_value,
cfg
);
gpuErrchk(cudaDeviceSynchronize());
}, edge.value());
}
update(solsF, solution_gpu);
}, solution_owner);
}
// memory initialization for the ArraySolution
void meminit(ArraySolution<CudaMem>& sol, size_t from, size_t to) {
auto start = thrust::device_ptr<decltype(sol.initializer())>(sol.data());
thrust::fill(start + from, start + to, sol.initializer());
}
// memory initialization for the TreeSolution
void meminit(TreeSolution<CudaMem>& sol, size_t from, size_t to) {
// make sure that we can simplyfy to a memset
assert(sol.initializer().empty == 0);
static_assert(std::is_same<decltype(sol.initializer().empty), uint64_t>::value);
gpuErrchk(cudaMemset(sol.data() + from, 0, (to - from) * sol.elementSize()));
}
/**
* Returns a solution bag that lives on the CPU
* but owns GPU data copied from the input bag.
*/
template <template<typename> typename T>
T<CudaMem> gpuOwner(const T<CpuMem>& orig, size_t reserve) {
// copy parameters
T<CudaMem> gpu(orig, nullptr, 0);
gpu.setDataStructureSize(gpu.dataStructureSize() + reserve);
// allocate GPU memory
gpu.allocate();
if (orig.hasData()) {
// copy data structure
gpuErrchk(cudaMemcpy(
gpu.data(),
orig.data(),
orig.dataStructureSize() * orig.elementSize(),
cudaMemcpyHostToDevice
));
// reserve additional elements if desired
if (reserve) {
meminit(gpu, orig.dataStructureSize(), gpu.dataStructureSize());
}
} else {
meminit(gpu, 0, gpu.dataStructureSize());
}
return gpu;
}
// Explicitly instantiate for all datastructures
// To ensure the compiler does not optimize them out.
template ArraySolution<CudaMem> gpuOwner(const ArraySolution<CpuMem>&, size_t);
template TreeSolution<CudaMem> gpuOwner(const TreeSolution<CpuMem>&, size_t);
CudaSolutionVariant gpuOwner(const SolutionVariant& orig, size_t reserve) {
return std::visit([&](auto& sol) -> CudaSolutionVariant {
return std::variant<TreeSolution<CudaMem>, ArraySolution<CudaMem>>(std::move(gpuOwner(sol, reserve)));
}, orig);
}
/**
* Returns a solution bag that is constructed
* (copied) from a bag tat owns GPU data.
*/
template <template<typename> typename T>
T<CpuMem> cpuCopy(const T<CudaMem>& gpu, size_t reserve) {
// copy parameters
T<CpuMem> cpu(gpu, nullptr, 0);
cpu.setDataStructureSize(cpu.dataStructureSize() + reserve);
// allocate CPU memory
cpu.allocate();
gpuErrchk(cudaDeviceSynchronize());
assert(gpu.hasData());
// copy data structure
gpuErrchk(cudaMemcpy(
cpu.data(),
gpu.data(),
gpu.dataStructureSize() * gpu.elementSize(),
cudaMemcpyDeviceToHost
));
// reserve additional elements if desired
if (reserve) {
std::fill(
cpu.data() + gpu.dataStructureSize(),
cpu.data() + cpu.dataStructureSize(),
cpu.initializer()
);
}
return cpu;
}
// Explicitly instantiate for all datastructures
// To ensure the compiler does not optimize them out.
template ArraySolution<CpuMem> cpuCopy(const ArraySolution<CudaMem>&, size_t);
template TreeSolution<CpuMem> cpuCopy(const TreeSolution<CudaMem>&, size_t);
SolutionVariant cpuCopy(const CudaSolutionVariant& gpu, size_t reserve) {
return std::visit([&](const auto& gpu_sol) -> SolutionVariant {
return SolutionVariant(std::move(cpuCopy(gpu_sol, reserve)));
}, gpu);
}
}