PyQrackIsing 8.13.1__tar.gz → 8.14.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyqrackising-8.13.1/pyqrackising.egg-info → pyqrackising-8.14.0}/PKG-INFO +1 -1
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyproject.toml +1 -1
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/kernels.cl +333 -9
- pyqrackising-8.14.0/pyqrackising/maxcut_tfim.py +433 -0
- pyqrackising-8.14.0/pyqrackising/maxcut_tfim_sparse.py +400 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/maxcut_tfim_util.py +60 -3
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/spin_glass_solver.py +8 -30
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/spin_glass_solver_sparse.py +6 -11
- {pyqrackising-8.13.1 → pyqrackising-8.14.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/setup.py +1 -1
- pyqrackising-8.13.1/pyqrackising/maxcut_tfim.py +0 -243
- pyqrackising-8.13.1/pyqrackising/maxcut_tfim_sparse.py +0 -238
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/LICENSE.md +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/MANIFEST.in +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/README.md +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/__init__.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/maxcut_tfim_streaming.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/tsp.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-8.13.1 → pyqrackising-8.14.0}/setup.cfg +0 -0
|
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
|
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "pyqrackising"
|
|
13
|
-
version = "8.
|
|
13
|
+
version = "8.14.0"
|
|
14
14
|
requires-python = ">=3.8"
|
|
15
15
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
16
16
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -48,7 +48,6 @@ real1 bootstrap_worker(__constant char* theta, __global const real1* G_m, __cons
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
__kernel void bootstrap(
|
|
51
|
-
uint prng_seed,
|
|
52
51
|
__global const real1* G_m,
|
|
53
52
|
__constant char* best_theta,
|
|
54
53
|
__constant int* indices_array,
|
|
@@ -62,6 +61,7 @@ __kernel void bootstrap(
|
|
|
62
61
|
const int k = args[1];
|
|
63
62
|
const int combo_count = args[2];
|
|
64
63
|
const bool is_spin_glass = args[3];
|
|
64
|
+
uint prng_seed = (uint)args[4];
|
|
65
65
|
int i = get_global_id(0);
|
|
66
66
|
|
|
67
67
|
// The inputs are chaotic, and this doesn't need to be high-quality, just uniform.
|
|
@@ -142,7 +142,6 @@ real1 bootstrap_worker_sparse(__constant char* theta, __global const real1* G_da
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
__kernel void bootstrap_sparse(
|
|
145
|
-
uint prng_seed,
|
|
146
145
|
__global const real1* G_data,
|
|
147
146
|
__global const uint* G_rows,
|
|
148
147
|
__global const uint* G_cols,
|
|
@@ -158,6 +157,7 @@ __kernel void bootstrap_sparse(
|
|
|
158
157
|
const int k = args[1];
|
|
159
158
|
const int combo_count = args[2];
|
|
160
159
|
const bool is_spin_glass = args[3];
|
|
160
|
+
uint prng_seed = (uint)args[4];
|
|
161
161
|
int i = get_global_id(0);
|
|
162
162
|
|
|
163
163
|
prng_seed ^= (uint)i;
|
|
@@ -235,8 +235,8 @@ real1 bootstrap_worker_segmented(
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
for (int v = u + 1; v < n; ++v) {
|
|
238
|
-
size_t flat_idx = u_offset + v;
|
|
239
|
-
real1 val = get_G_m(G_m, flat_idx, segment_size);
|
|
238
|
+
const size_t flat_idx = u_offset + v;
|
|
239
|
+
const real1 val = get_G_m(G_m, flat_idx, segment_size);
|
|
240
240
|
|
|
241
241
|
bool v_bit = theta[v];
|
|
242
242
|
for (int x = 0; x < k; ++x) {
|
|
@@ -259,7 +259,6 @@ real1 bootstrap_worker_segmented(
|
|
|
259
259
|
|
|
260
260
|
|
|
261
261
|
__kernel void bootstrap_segmented(
|
|
262
|
-
uint prng_seed,
|
|
263
262
|
__global const real1* G_m0,
|
|
264
263
|
__global const real1* G_m1,
|
|
265
264
|
__global const real1* G_m2,
|
|
@@ -278,7 +277,8 @@ __kernel void bootstrap_segmented(
|
|
|
278
277
|
const int k = args[1];
|
|
279
278
|
const int combo_count = args[2];
|
|
280
279
|
const bool is_spin_glass = args[3];
|
|
281
|
-
|
|
280
|
+
uint prng_seed = (uint)args[4];
|
|
281
|
+
const int segment_size = args[5];
|
|
282
282
|
int i = get_global_id(0);
|
|
283
283
|
|
|
284
284
|
prng_seed ^= (uint)i;
|
|
@@ -350,7 +350,7 @@ real1 bootstrap_worker_sparse_segmented(
|
|
|
350
350
|
|
|
351
351
|
for (uint col = row_start; col < row_end; ++col) {
|
|
352
352
|
const int v = G_cols[col];
|
|
353
|
-
real1 val = get_G_m(G_data, col, segment_size);
|
|
353
|
+
const real1 val = get_G_m(G_data, col, segment_size);
|
|
354
354
|
|
|
355
355
|
bool v_bit = theta[v];
|
|
356
356
|
for (int x = 0; x < k; ++x) {
|
|
@@ -372,7 +372,6 @@ real1 bootstrap_worker_sparse_segmented(
|
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
__kernel void bootstrap_sparse_segmented(
|
|
375
|
-
uint prng_seed,
|
|
376
375
|
__global const real1* G_data0,
|
|
377
376
|
__global const real1* G_data1,
|
|
378
377
|
__global const real1* G_data2,
|
|
@@ -393,7 +392,8 @@ __kernel void bootstrap_sparse_segmented(
|
|
|
393
392
|
const int k = args[1];
|
|
394
393
|
const int combo_count = args[2];
|
|
395
394
|
const bool is_spin_glass = args[3];
|
|
396
|
-
|
|
395
|
+
uint prng_seed = (uint)args[4];
|
|
396
|
+
const int segment_size = args[5];
|
|
397
397
|
int i = get_global_id(0);
|
|
398
398
|
|
|
399
399
|
prng_seed ^= (uint)i;
|
|
@@ -438,3 +438,327 @@ __kernel void bootstrap_sparse_segmented(
|
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
inline bool get_bit(__constant uint* theta, const size_t u) {
|
|
442
|
+
return (theta[u >> 5U] >> (u & 31U)) & 1U;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
real1 cut_worker(__constant uint* theta, __global const real1* G_m, const int n, const bool is_spin_glass) {
|
|
446
|
+
real1 energy = ZERO_R1;
|
|
447
|
+
const size_t n_st = (size_t)n;
|
|
448
|
+
for (int u = 0; u < n; ++u) {
|
|
449
|
+
const size_t u_offset = u * n_st;
|
|
450
|
+
const bool u_bit = get_bit(theta, u);
|
|
451
|
+
for (int v = u + 1; v < n; ++v) {
|
|
452
|
+
const real1 val = G_m[u_offset + v];
|
|
453
|
+
const bool v_bit = get_bit(theta, v);
|
|
454
|
+
if (u_bit != v_bit) {
|
|
455
|
+
energy += val;
|
|
456
|
+
} else if (is_spin_glass) {
|
|
457
|
+
energy -= val;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return energy;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
__kernel void calculate_cut(
|
|
466
|
+
__global const real1* G_m,
|
|
467
|
+
__constant uint* theta,
|
|
468
|
+
__constant int* args, // args[0] = n, args[1] = k
|
|
469
|
+
__global real1* max_energy_ptr, // output: per-group min energy
|
|
470
|
+
__global int* max_index_ptr, // output: per-group best index (i)
|
|
471
|
+
__local real1* loc_energy, // local memory buffer
|
|
472
|
+
__local int* loc_index // local memory buffer
|
|
473
|
+
) {
|
|
474
|
+
const int n = args[0];
|
|
475
|
+
const int n32 = (n + 31) >> 5U;
|
|
476
|
+
const int shots = args[1];
|
|
477
|
+
const bool is_spin_glass = args[2];
|
|
478
|
+
int i = get_global_id(0);
|
|
479
|
+
|
|
480
|
+
real1 best_energy = -INFINITY;
|
|
481
|
+
int best_i = i;
|
|
482
|
+
|
|
483
|
+
for (; i < shots; i += MAX_PROC_ELEM) {
|
|
484
|
+
const int j = i * n32;
|
|
485
|
+
const real1 energy = cut_worker(theta + j, G_m, n, is_spin_glass);
|
|
486
|
+
if (energy > best_energy) {
|
|
487
|
+
best_energy = energy;
|
|
488
|
+
best_i = i;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const int lt_id = get_local_id(0);
|
|
493
|
+
const int lt_size = get_local_size(0);
|
|
494
|
+
|
|
495
|
+
loc_energy[lt_id] = best_energy;
|
|
496
|
+
loc_index[lt_id] = best_i;
|
|
497
|
+
|
|
498
|
+
// Reduce within workgroup
|
|
499
|
+
for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
|
|
500
|
+
barrier(CLK_LOCAL_MEM_FENCE);
|
|
501
|
+
if (lt_id < offset) {
|
|
502
|
+
real1 hid_energy = loc_energy[lt_id + offset];
|
|
503
|
+
real1 lid_energy = loc_energy[lt_id];
|
|
504
|
+
if (hid_energy > lid_energy) {
|
|
505
|
+
loc_energy[lt_id] = hid_energy;
|
|
506
|
+
loc_index[lt_id] = loc_index[lt_id + offset];
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// Write out per-group result
|
|
512
|
+
if (lt_id == 0) {
|
|
513
|
+
max_energy_ptr[get_group_id(0)] = loc_energy[0];
|
|
514
|
+
max_index_ptr[get_group_id(0)] = loc_index[0];
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
real1 cut_worker_sparse(__constant uint* theta, __global const real1* G_data, __global const uint* G_rows, __global const uint* G_cols, const int n, const bool is_spin_glass) {
|
|
519
|
+
real1 energy = ZERO_R1;
|
|
520
|
+
for (int u = 0; u < n; ++u) {
|
|
521
|
+
const bool u_bit = get_bit(theta, u);
|
|
522
|
+
const size_t mCol = G_rows[u + 1];
|
|
523
|
+
for (int col = G_rows[u]; col < mCol; ++col) {
|
|
524
|
+
const int v = G_cols[col];
|
|
525
|
+
const real1 val = G_data[col];
|
|
526
|
+
const bool v_bit = get_bit(theta, v);
|
|
527
|
+
if (u_bit != v_bit) {
|
|
528
|
+
energy += val;
|
|
529
|
+
} else if (is_spin_glass) {
|
|
530
|
+
energy -= val;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return energy;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
__kernel void calculate_cut_sparse(
|
|
539
|
+
__global const real1* G_data,
|
|
540
|
+
__global const uint* G_rows,
|
|
541
|
+
__global const uint* G_cols,
|
|
542
|
+
__constant uint* theta,
|
|
543
|
+
__constant int* args, // args[0] = n, args[1] = k
|
|
544
|
+
__global real1* max_energy_ptr, // output: per-group min energy
|
|
545
|
+
__global int* max_index_ptr, // output: per-group best index (i)
|
|
546
|
+
__local real1* loc_energy, // local memory buffer
|
|
547
|
+
__local int* loc_index // local memory buffer
|
|
548
|
+
) {
|
|
549
|
+
const int n = args[0];
|
|
550
|
+
const int shots = args[1];
|
|
551
|
+
const bool is_spin_glass = args[2];
|
|
552
|
+
int i = get_global_id(0);
|
|
553
|
+
|
|
554
|
+
real1 best_energy = -INFINITY;
|
|
555
|
+
int best_i = i;
|
|
556
|
+
|
|
557
|
+
for (; i < shots; i += MAX_PROC_ELEM) {
|
|
558
|
+
const int j = (i * n + 31U) >> 5U;
|
|
559
|
+
const real1 energy = cut_worker_sparse(theta + j, G_data, G_rows, G_cols, n, is_spin_glass);
|
|
560
|
+
if (energy > best_energy) {
|
|
561
|
+
best_energy = energy;
|
|
562
|
+
best_i = i;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
const int lt_id = get_local_id(0);
|
|
567
|
+
const int lt_size = get_local_size(0);
|
|
568
|
+
|
|
569
|
+
loc_energy[lt_id] = best_energy;
|
|
570
|
+
loc_index[lt_id] = best_i;
|
|
571
|
+
|
|
572
|
+
// Reduce within workgroup
|
|
573
|
+
for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
|
|
574
|
+
barrier(CLK_LOCAL_MEM_FENCE);
|
|
575
|
+
if (lt_id < offset) {
|
|
576
|
+
real1 hid_energy = loc_energy[lt_id + offset];
|
|
577
|
+
real1 lid_energy = loc_energy[lt_id];
|
|
578
|
+
if (hid_energy > lid_energy) {
|
|
579
|
+
loc_energy[lt_id] = hid_energy;
|
|
580
|
+
loc_index[lt_id] = loc_index[lt_id + offset];
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Write out per-group result
|
|
586
|
+
if (lt_id == 0) {
|
|
587
|
+
max_energy_ptr[get_group_id(0)] = loc_energy[0];
|
|
588
|
+
max_index_ptr[get_group_id(0)] = loc_index[0];
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
real1 cut_worker_segmented(
|
|
593
|
+
__constant uint* theta,
|
|
594
|
+
__global const real1** G_m,
|
|
595
|
+
const int n,
|
|
596
|
+
const int segment_size,
|
|
597
|
+
const bool is_spin_glass
|
|
598
|
+
) {
|
|
599
|
+
real1 energy = ZERO_R1;
|
|
600
|
+
const size_t n_st = (size_t)n;
|
|
601
|
+
|
|
602
|
+
for (int u = 0; u < n; ++u) {
|
|
603
|
+
const size_t u_offset = u * n_st;
|
|
604
|
+
const bool u_bit = get_bit(theta, u);
|
|
605
|
+
for (int v = u + 1; v < n; ++v) {
|
|
606
|
+
const size_t flat_idx = u_offset + v;
|
|
607
|
+
const real1 val = get_G_m(G_m, flat_idx, segment_size);
|
|
608
|
+
const bool v_bit = get_bit(theta, v);
|
|
609
|
+
if (u_bit != v_bit) {
|
|
610
|
+
energy += val;
|
|
611
|
+
} else if (is_spin_glass) {
|
|
612
|
+
energy -= val;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
return energy;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
__kernel void calculate_cut_segmented(
|
|
622
|
+
__global const real1* G_m0,
|
|
623
|
+
__global const real1* G_m1,
|
|
624
|
+
__global const real1* G_m2,
|
|
625
|
+
__global const real1* G_m3,
|
|
626
|
+
__constant uint* theta,
|
|
627
|
+
__constant int* args, // args[0]=n, args[1]=k, args[2]=combo_count, args[3]=segment_size
|
|
628
|
+
__global real1* max_energy_ptr,
|
|
629
|
+
__global int* max_index_ptr,
|
|
630
|
+
__local real1* loc_energy,
|
|
631
|
+
__local int* loc_index
|
|
632
|
+
) {
|
|
633
|
+
__global const real1* G_m[4] = { G_m0, G_m1, G_m2, G_m3 };
|
|
634
|
+
|
|
635
|
+
const int n = args[0];
|
|
636
|
+
const int shots = args[1];
|
|
637
|
+
const bool is_spin_glass = args[2];
|
|
638
|
+
const int segment_size = args[3];
|
|
639
|
+
int i = get_global_id(0);
|
|
640
|
+
|
|
641
|
+
real1 best_energy = -INFINITY;
|
|
642
|
+
int best_i = i;
|
|
643
|
+
|
|
644
|
+
for (; i < shots; i += MAX_PROC_ELEM) {
|
|
645
|
+
const int j = (i * n + 31U) >> 5U;
|
|
646
|
+
const real1 energy = cut_worker_segmented(theta + j, G_m, n, segment_size, is_spin_glass);
|
|
647
|
+
if (energy > best_energy) {
|
|
648
|
+
best_energy = energy;
|
|
649
|
+
best_i = i;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
const int lt_id = get_local_id(0);
|
|
654
|
+
const int lt_size = get_local_size(0);
|
|
655
|
+
|
|
656
|
+
loc_energy[lt_id] = best_energy;
|
|
657
|
+
loc_index[lt_id] = best_i;
|
|
658
|
+
|
|
659
|
+
for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
|
|
660
|
+
barrier(CLK_LOCAL_MEM_FENCE);
|
|
661
|
+
if (lt_id < offset) {
|
|
662
|
+
real1 hid_energy = loc_energy[lt_id + offset];
|
|
663
|
+
real1 lid_energy = loc_energy[lt_id];
|
|
664
|
+
if (hid_energy > lid_energy) {
|
|
665
|
+
loc_energy[lt_id] = hid_energy;
|
|
666
|
+
loc_index[lt_id] = loc_index[lt_id + offset];
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (lt_id == 0) {
|
|
672
|
+
max_energy_ptr[get_group_id(0)] = loc_energy[0];
|
|
673
|
+
max_index_ptr[get_group_id(0)] = loc_index[0];
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
real1 cut_worker_sparse_segmented(
|
|
678
|
+
__constant uint* theta,
|
|
679
|
+
__global const real1** G_data,
|
|
680
|
+
__global const uint* G_rows,
|
|
681
|
+
__global const uint* G_cols,
|
|
682
|
+
const int n,
|
|
683
|
+
const int segment_size,
|
|
684
|
+
const bool is_spin_glass
|
|
685
|
+
) {
|
|
686
|
+
real1 energy = ZERO_R1;
|
|
687
|
+
|
|
688
|
+
for (int u = 0; u < n; ++u) {
|
|
689
|
+
const bool u_bit = get_bit(theta, u);
|
|
690
|
+
const uint row_start = G_rows[u];
|
|
691
|
+
const uint row_end = G_rows[u + 1];
|
|
692
|
+
|
|
693
|
+
for (uint col = row_start; col < row_end; ++col) {
|
|
694
|
+
const int v = G_cols[col];
|
|
695
|
+
const real1 val = get_G_m(G_data, col, segment_size);
|
|
696
|
+
const bool v_bit = get_bit(theta, v);
|
|
697
|
+
if (u_bit != v_bit) {
|
|
698
|
+
energy += val;
|
|
699
|
+
} else if (is_spin_glass) {
|
|
700
|
+
energy -= val;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return energy;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
__kernel void calculate_cut_sparse_segmented(
|
|
709
|
+
__global const real1* G_data0,
|
|
710
|
+
__global const real1* G_data1,
|
|
711
|
+
__global const real1* G_data2,
|
|
712
|
+
__global const real1* G_data3,
|
|
713
|
+
__global const uint* G_rows,
|
|
714
|
+
__global const uint* G_cols,
|
|
715
|
+
__constant uint* theta,
|
|
716
|
+
__constant int* args, // args[0] = n, args[1] = k, args[2] = combo_count, args[3] = segment_size
|
|
717
|
+
__global real1* max_energy_ptr,
|
|
718
|
+
__global int* max_index_ptr,
|
|
719
|
+
__local real1* loc_energy,
|
|
720
|
+
__local int* loc_index
|
|
721
|
+
) {
|
|
722
|
+
__global const real1* G_data[4] = { G_data0, G_data1, G_data2, G_data3 };
|
|
723
|
+
|
|
724
|
+
const int n = args[0];
|
|
725
|
+
const int shots = args[1];
|
|
726
|
+
const bool is_spin_glass = args[2];
|
|
727
|
+
const int segment_size = args[3];
|
|
728
|
+
int i = get_global_id(0);
|
|
729
|
+
|
|
730
|
+
real1 best_energy = -INFINITY;
|
|
731
|
+
int best_i = i;
|
|
732
|
+
|
|
733
|
+
for (; i < shots; i += MAX_PROC_ELEM) {
|
|
734
|
+
const int j = (i * n + 31U) >> 5U;
|
|
735
|
+
const real1 energy = cut_worker_sparse_segmented(theta + j, G_data, G_rows, G_cols, n, segment_size, is_spin_glass);
|
|
736
|
+
if (energy > best_energy) {
|
|
737
|
+
best_energy = energy;
|
|
738
|
+
best_i = i;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
const int lt_id = get_local_id(0);
|
|
743
|
+
const int lt_size = get_local_size(0);
|
|
744
|
+
|
|
745
|
+
loc_energy[lt_id] = best_energy;
|
|
746
|
+
loc_index[lt_id] = best_i;
|
|
747
|
+
|
|
748
|
+
for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
|
|
749
|
+
barrier(CLK_LOCAL_MEM_FENCE);
|
|
750
|
+
if (lt_id < offset) {
|
|
751
|
+
real1 hid_energy = loc_energy[lt_id + offset];
|
|
752
|
+
real1 lid_energy = loc_energy[lt_id];
|
|
753
|
+
if (hid_energy > lid_energy) {
|
|
754
|
+
loc_energy[lt_id] = hid_energy;
|
|
755
|
+
loc_index[lt_id] = loc_index[lt_id + offset];
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
if (lt_id == 0) {
|
|
761
|
+
max_energy_ptr[get_group_id(0)] = loc_energy[0];
|
|
762
|
+
max_index_ptr[get_group_id(0)] = loc_index[0];
|
|
763
|
+
}
|
|
764
|
+
}
|