-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjaccard.cpp
1120 lines (1041 loc) · 51.7 KB
/
jaccard.cpp
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Original CUDA Copyright (c) 2019-2021, NVIDIA CORPORATION.
* SYCL translation and edge-centric components Copyright (c) 2021-2022, Virginia Tech
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See NOTICE.md for detailed description of derivative portions and their origins
*/
/** ---------------------------------------------------------------------------*
* @brief The sygraph Jaccard core functionality
*
* @file jaccard.cpp
* ---------------------------------------------------------------------------**/
#ifndef STANDALONE
#include "graph.hpp"
#include "utilities/graph_utils.cuh"
#include <rmm/thrust_rmm_allocator.h>
#include <utilities/error.hpp>
#else
#ifdef INTEL_FPGA_EXT
// Sometimes it's this path (2022.0.2)
#include <sycl/ext/intel/fpga_extensions.hpp>
// Sometimes it's this path (2021.2.0)
//#include <CL/sycl/INTEL/fpga_extensions.hpp>
#endif
#include "jaccard.hpp"
#include "standalone_algorithms.hpp"
#include "standalone_csr.hpp"
#include <iostream>
#ifndef SYCL_DEVICE_ONLY
#define EMULATE_ATOMIC_ADD_FLOAT
#define EMULATE_ATOMIC_ADD_DOUBLE
#endif
#ifdef ICX
#define EMULATE_ATOMIC_ADD_DOUBLE
#endif
// From utilties/graph_utils.cuh
// FIXME Revisit the barriers and fences and local storage with subgroups
// FIXME revisit with SYCL group algorithms
template <typename count_t, typename index_t, typename value_t>
__inline__ value_t
parallel_prefix_sum(cl::sycl::nd_item<2> const &tid_info, count_t n,
cl::sycl::accessor<index_t, 1, cl::sycl::access::mode::read> ind,
count_t ind_off, cl::sycl::accessor<value_t, 1, cl::sycl::access::mode::read> w,
cl::sycl::accessor<value_t, 1, cl::sycl::access::mode::read_write,
cl::sycl::access::target::local>
shfl_temp) {
count_t i, j, mn;
value_t v, last;
value_t sum = 0.0;
bool valid;
// Parallel prefix sum (using __shfl)
mn = (((n + tid_info.get_local_range(1) - 1) / tid_info.get_local_range(1)) *
tid_info.get_local_range(1)); // n in multiple of blockDim.x
for (i = tid_info.get_local_id(1); i < mn; i += tid_info.get_local_range(1)) {
// All threads (especially the last one) must always participate
// in the shfl instruction, otherwise their sum will be undefined.
// So, the loop stopping condition is based on multiple of n in loop increments,
// so that all threads enter into the loop and inside we make sure we do not
// read out of bounds memory checking for the actual size n.
// check if the thread is valid
valid = i < n;
// Notice that the last thread is used to propagate the prefix sum.
// For all the threads, in the first iteration the last is 0, in the following
// iterations it is the value at the last thread of the previous iterations.
// get the value of the last thread
// FIXME: __shfl_sync
// FIXME make sure everybody is here
group_barrier(tid_info.get_group());
// write your current sum
// This is a 2D block, use a linear ID
shfl_temp[tid_info.get_local_linear_id()] = sum;
// FIXME make sure everybody has read from the top thread in the same Y-dimensional subgroup
group_barrier(tid_info.get_group());
last = shfl_temp[tid_info.get_local_range(1) - 1 +
(tid_info.get_local_range(1) * tid_info.get_local_id(0))];
// Move forward
// last = __shfl_sync(warp_full_mask(), sum, blockDim.x - 1, blockDim.x);
// if you are valid read the value from memory, otherwise set your value to 0
sum = (valid) ? w[ind[ind_off + i]] : 0.0;
// do prefix sum (of size warpSize=blockDim.x =< 32)
for (j = 1; j < tid_info.get_local_range(1); j *= 2) {
// FIXME: __shfl_up_warp
// FIXME make sure everybody is here
// Write your current sum
group_barrier(tid_info.get_group());
shfl_temp[tid_info.get_local_linear_id()] = sum;
// FIXME Force writes to finish
// read from tid-j
// Using the x-dimension local id for the conditional protects from overflows to other
// Y-subgroups Using the local_linear_id for the read saves us having to offset by x_range *
// y_id
group_barrier(tid_info.get_group());
if (tid_info.get_local_id(1) >= j) v = shfl_temp[tid_info.get_local_linear_id() - j];
// FIXME Force reads to finish
// v = __shfl_up_sync(warp_full_mask(), sum, j, blockDim.x);
if (tid_info.get_local_id(1) >= j) sum += v;
}
// shift by last
sum += last;
// notice that no __threadfence or __syncthreads are needed in this implementation
}
// get the value of the last thread (to all threads)
// FIXME: __shfl_sync
// FIXME make sure everybody is here
// write your current sum
// This is a 2D block, use a linear ID
group_barrier(tid_info.get_group());
shfl_temp[tid_info.get_local_linear_id()] = sum;
// FIXME make sure everybody has read from the top thread in the same Y-dimensional group
group_barrier(tid_info.get_group());
last = shfl_temp[tid_info.get_local_range(1) - 1 +
(tid_info.get_local_range(1) * tid_info.get_local_id(0))];
// Move forward
// last = __shfl_sync(warp_full_mask(), sum, blockDim.x - 1, blockDim.x);
return last;
}
// From RAFT at commit 048063dc08
constexpr inline int warp_size() {
return 32;
}
constexpr inline unsigned int warp_full_mask() {
return 0xffffffff;
}
// Kernels are implemented as functors or lambdas in SYCL
// Custom Thrust simplifications
template <typename T>
const void FillKernel<T>::operator()(cl::sycl::nd_item<1> tid_info) const {
// equivalent to: idx = threadIdx.x + blockIdx.x*blockIdx.x;
size_t idx = tid_info.get_global_id(0);
// equivalent to: incr = blockDim.x*gridDim.x;
size_t incr = tid_info.get_global_range(0);
for (; idx < n; idx += incr) {
ptr[idx] = value;
}
}
template <typename T>
const cl::sycl::event FillKernel<T>::invoke(size_t n, cl::sycl::buffer<T> &x, T value,
cl::sycl::queue &q) {
// FIXME: De-CUDA the MAX_KERNEL_THREADS and MAX_BLOCKS defines
size_t block = std::min((size_t)n, (size_t)CUDA_MAX_KERNEL_THREADS);
size_t grid = std::min((size_t)(n / block) + ((n % block) ? 1 : 0), (size_t)CUDA_MAX_BLOCKS);
// TODO, do we need to emulate their stream behavior?
cl::sycl::event ret_event;
try {
ret_event = q.submit([&](cl::sycl::handler &cgh) {
cl::sycl::accessor<T, 1, cl::sycl::access::mode::discard_write> x_acc =
x.template get_access<cl::sycl::access::mode::discard_write>(cgh, cl::sycl::range<1>(n));
FillKernel fill_kern(x_acc, value, n);
cgh.parallel_for(
cl::sycl::nd_range<1>{cl::sycl::range<1>{grid * block}, cl::sycl::range<1>{block}},
fill_kern);
});
} catch (sycl::exception e) {
std::cerr << "SYCL Exception during Fill enqueue\n\t" << e.what() << std::endl;
}
return ret_event;
}
#ifdef EMULATE_ATOMIC_ADD_FLOAT
// Inspired by the older CUDA C Programming Guide
float myAtomicAdd(cl::sycl::atomic<uint32_t> &address, float val) {
uint32_t old = address.load();
// uint64_t atomic_load
bool success = false;
do {
// old = atomicCAS(address_as_ull, assumed,
// __double_as_longlong(val +
// __longlong_as_double(assumed)));
// success = address.compare_exchange_strong(old,
// reintpret_cast<uint64_t>(val+reinterpret_cast<double>(old)));
float temp = val + *reinterpret_cast<float *>(&old);
// success = dummy.compare_exchange_strong(const_cast<uint64_t&>(old),
// *reinterpret_cast<uint64_t*>(&temp));
success = address.compare_exchange_strong(old, *reinterpret_cast<uint32_t *>(&temp));
// Note: uses integer comparison to avoid hang in case of NaN (since NaN != NaN)
} while (!success);
return *reinterpret_cast<float *>(&old);
}
#endif // EMULATE_ATOMIC_ADD_FLOAT
#ifdef EMULATE_ATOMIC_ADD_DOUBLE
// Inspired by the older CUDA C Programming Guide
double myAtomicAdd(cl::sycl::atomic<uint64_t> &address, double val) {
uint64_t old = address.load();
// uint64_t atomic_load
bool success = false;
do {
// old = atomicCAS(address_as_ull, assumed,
// __double_as_longlong(val +
// __longlong_as_double(assumed)));
// success = address.compare_exchange_strong(old,
// reintpret_cast<uint64_t>(val+reinterpret_cast<double>(old)));
double temp = val + *reinterpret_cast<double *>(&old);
// success = dummy.compare_exchange_strong(const_cast<uint64_t&>(old),
// *reinterpret_cast<uint64_t*>(&temp));
success = address.compare_exchange_strong(old, *reinterpret_cast<uint64_t *>(&temp));
// Note: uses integer comparison to avoid hang in case of NaN (since NaN != NaN)
} while (!success);
return *reinterpret_cast<double *>(&old);
}
#endif // EMULATE_ATOMIC_ADD_DOUBLE
#endif // STANDALONE
namespace sygraph {
namespace detail {
// Volume of neighboors (*weight_s)
template <bool weighted, typename vertex_t, typename edge_t, typename weight_t>
// Must be marked external since main.cpp uses it
extern SYCL_EXTERNAL const void
Jaccard_RowSumKernel<weighted, vertex_t, edge_t, weight_t>::operator()(
cl::sycl::nd_item<2> tid_info) const {
vertex_t row;
edge_t start, end, length;
weight_t sum;
vertex_t row_start = tid_info.get_global_id(0);
vertex_t row_incr = tid_info.get_global_range(0);
for (row = row_start; row < n; row += row_incr) {
start = csrPtr[row];
end = csrPtr[row + 1];
length = end - start;
// compute row sums
// Must be if constexpr so it doesn't try to evaluate v when it's a nullptr_t
if constexpr (weighted) {
sum = parallel_prefix_sum(tid_info, length, csrInd, start, v, shfl_temp);
if (tid_info.get_local_id(1) == 0) work[row] = sum;
} else {
work[row] = static_cast<weight_t>(length);
}
}
}
template <bool weighted, typename vertex_t, typename edge_t, typename weight_t>
const cl::sycl::event Jaccard_RowSumKernel<weighted, vertex_t, edge_t, weight_t>::invoke(
vertex_t n, edge_t e, cl::sycl::buffer<edge_t> &csrPtr, cl::sycl::buffer<vertex_t> &csrInd,
cl::sycl::buffer<weight_t> *weight_in, cl::sycl::buffer<weight_t> &work, cl::sycl::queue &q) {
// Needs to be 1 for barriers in warp intrinsic emulation
size_t y = 1;
// setup launch configuration
// SYCL: INVERT THE ORDER OF MULTI-DIMENSIONAL THREAD INDICES
cl::sycl::range<2> sum_local{y, 32};
cl::sycl::range<2> sum_global{std::min((size_t)(n + sum_local.get(0) - 1) / sum_local.get(0),
(size_t)vertex_t{CUDA_MAX_BLOCKS}) *
sum_local.get(0),
sum_local.get(1)};
cl::sycl::event sum_event;
try {
// launch kernel
sum_event = q.submit([&](cl::sycl::handler &cgh) {
cl::sycl::accessor<edge_t, 1, cl::sycl::access::mode::read> csrPtr_acc =
csrPtr.template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)n + 1});
cl::sycl::accessor<vertex_t, 1, cl::sycl::access::mode::read> csrInd_acc =
csrInd.template get_access<cl::sycl::access::mode::read>(cgh,
cl::sycl::range<1>{(size_t)e});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::discard_write> work_acc =
work.template get_access<cl::sycl::access::mode::discard_write>(
cgh, cl::sycl::range<1>{(size_t)n});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read_write,
cl::sycl::access::target::local>
shfl_temp(sum_local.get(0) * sum_local.get(1), cgh);
if constexpr (weighted) {
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read> weight_in_acc =
weight_in->template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)n});
Jaccard_RowSumKernel<true, vertex_t, edge_t, weight_t> sum_kernel(
n, csrPtr_acc, csrInd_acc, weight_in_acc, work_acc, shfl_temp);
cgh.parallel_for(cl::sycl::nd_range<2>{sum_global, sum_local}, sum_kernel);
} else {
Jaccard_RowSumKernel<false, vertex_t, edge_t, weight_t> sum_kernel(
n, csrPtr_acc, csrInd_acc, work_acc, shfl_temp);
cgh.parallel_for(cl::sycl::nd_range<2>{sum_global, sum_local}, sum_kernel);
}
});
// CUDA actually had a sync here, force a queue flush
q.wait();
} catch (sycl::exception e) {
std::cerr << "SYCL Exception during VC RowSum\n\t" << e.what() << std::endl;
}
return sum_event;
}
// Volume of intersections (*weight_i) and cumulated volume of neighboors (*weight_s)
template <bool weighted, typename vertex_t, typename edge_t, typename weight_t>
const void Jaccard_IsKernel<weighted, vertex_t, edge_t, weight_t>::operator()(
cl::sycl::nd_item<3> tid_info) const {
edge_t i, j, Ni, Nj;
vertex_t row, col;
vertex_t ref, cur, ref_col, cur_col, match;
weight_t ref_val;
vertex_t row_start = tid_info.get_global_id(0);
vertex_t row_incr = tid_info.get_global_range(0);
edge_t j_off = tid_info.get_global_id(1);
edge_t j_incr = tid_info.get_global_range(1);
edge_t i_off = tid_info.get_global_id(2);
edge_t i_incr = tid_info.get_global_range(2);
for (row = row_start; row < n; row += row_incr) {
for (j = csrPtr[row] + j_off; j < csrPtr[row + 1]; j += j_incr) {
col = csrInd[j];
// find which row has least elements (and call it reference row)
Ni = csrPtr[row + 1] - csrPtr[row];
Nj = csrPtr[col + 1] - csrPtr[col];
ref = (Ni < Nj) ? row : col;
cur = (Ni < Nj) ? col : row;
// compute new sum weights
weight_s[j] = work[row] + work[col];
// compute new intersection weights
// search for the element with the same column index in the reference row
for (i = csrPtr[ref] + i_off; i < csrPtr[ref + 1]; i += i_incr) {
match = -1;
ref_col = csrInd[i];
// Must be if constexpr so it doesn't try to evaluate v when it's a nullptr_t
if constexpr (weighted) {
ref_val = v[ref_col];
} else {
ref_val = 1.0;
}
// binary search (column indices are sorted within each row)
edge_t left = csrPtr[cur];
edge_t right = csrPtr[cur + 1] - 1;
while (left <= right) {
edge_t middle = (left + right) >> 1;
cur_col = csrInd[middle];
if (cur_col > ref_col) {
right = middle - 1;
} else if (cur_col < ref_col) {
left = middle + 1;
} else {
match = middle;
break;
}
}
// if the element with the same column index in the reference row has been found
if (match != -1) {
// FIXME: Update to SYCL 2020 atomic_refs
if constexpr (std::is_same<weight_t, double>::value) {
// if constexpr (typeid(weight_t) == typeid(double)) {
#ifdef EMULATE_ATOMIC_ADD_DOUBLE
cl::sycl::atomic<uint64_t> atom_weight{
cl::sycl::global_ptr<uint64_t>{(uint64_t *)&weight_i[j]}};
myAtomicAdd(atom_weight, ref_val);
#else
cl::sycl::atomic<weight_t> atom_weight{cl::sycl::global_ptr<weight_t>{&weight_i[j]}};
atom_weight.fetch_add(ref_val);
#endif
}
// if constexpr (typeid(weight_t) == typeid(float)) {
if constexpr (std::is_same<weight_t, float>::value) {
#ifdef EMULATE_ATOMIC_ADD_FLOAT
cl::sycl::atomic<uint32_t> atom_weight{
cl::sycl::global_ptr<uint32_t>{(uint32_t *)&weight_i[j]}};
myAtomicAdd(atom_weight, ref_val);
#else
cl::sycl::atomic<weight_t> atom_weight{cl::sycl::global_ptr<weight_t>{&weight_i[j]}};
atom_weight.fetch_add(ref_val);
#endif
}
// FIXME: Use the below with a sycl::atomic once hipSYCL supports the 2020 Floating
// atomics atomicAdd(&weight_i[j], ref_val);
}
}
}
}
}
template <bool weighted, typename vertex_t, typename edge_t, typename weight_t>
const cl::sycl::event Jaccard_IsKernel<weighted, vertex_t, edge_t, weight_t>::invoke(
vertex_t n, edge_t e, cl::sycl::buffer<edge_t> &csrPtr, cl::sycl::buffer<vertex_t> &csrInd,
cl::sycl::buffer<weight_t> *weight_in, cl::sycl::buffer<weight_t> &work,
cl::sycl::buffer<weight_t> &weight_i, cl::sycl::buffer<weight_t> &weight_s,
cl::sycl::queue &q) {
// Back to previous value since this doesn't require barriers
size_t y = 4;
// setup launch configuration
// SYCL: INVERT THE ORDER OF MULTI-DIMENSIONAL THREAD INDICES
// FIXME: De-CUDA the MAX_KERNEL_THREADS and MAX_BLOCKS defines
cl::sycl::range<3> is_local{8, y, 32 / y};
cl::sycl::range<3> is_global{std::min((size_t)(n + is_local.get(0) - 1) / is_local.get(0),
(size_t)vertex_t{CUDA_MAX_BLOCKS}) *
is_local.get(0),
1 * is_local.get(1), 1 * is_local.get(2)};
cl::sycl::event is_event;
try {
// launch kernel
// FIXME: Implement in SYCL lamda
is_event = q.submit([&](cl::sycl::handler &cgh) {
cl::sycl::accessor<edge_t, 1, cl::sycl::access::mode::read> csrPtr_acc =
csrPtr.template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)n + 1});
cl::sycl::accessor<vertex_t, 1, cl::sycl::access::mode::read> csrInd_acc =
csrInd.template get_access<cl::sycl::access::mode::read>(cgh,
cl::sycl::range<1>{(size_t)e});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read> work_acc =
work.template get_access<cl::sycl::access::mode::read>(cgh,
cl::sycl::range<1>{(size_t)n});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read_write> weight_i_acc =
weight_i.template get_access<cl::sycl::access::mode::read_write>(
cgh, cl::sycl::range<1>{(size_t)e});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::discard_write> weight_s_acc =
weight_s.template get_access<cl::sycl::access::mode::discard_write>(
cgh, cl::sycl::range<1>{(size_t)e});
if constexpr (weighted) {
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read> weight_in_acc =
weight_in->template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)n});
Jaccard_IsKernel<true, vertex_t, edge_t, weight_t> is_kernel(
n, csrPtr_acc, csrInd_acc, weight_in_acc, work_acc, weight_i_acc, weight_s_acc);
cgh.parallel_for(cl::sycl::nd_range<3>{is_global, is_local}, is_kernel);
} else {
Jaccard_IsKernel<false, vertex_t, edge_t, weight_t> is_kernel(
n, csrPtr_acc, csrInd_acc, work_acc, weight_i_acc, weight_s_acc);
cgh.parallel_for(cl::sycl::nd_range<3>{is_global, is_local}, is_kernel);
}
});
} catch (sycl::exception e) {
std::cerr << "SYCL Exception during VC Intersection\n\t" << e.what() << std::endl;
}
return is_event;
}
// Volume of intersections (*weight_i) and cumulated volume of neighboors (*weight_s)
// Using list of node pairs
template <bool weighted, typename vertex_t, typename edge_t, typename weight_t>
const void Jaccard_IsPairsKernel<weighted, vertex_t, edge_t, weight_t>::operator()(
cl::sycl::nd_item<3> tid_info) const {
edge_t i, idx, Ni, Nj, match;
vertex_t row, col, ref, cur, ref_col, cur_col;
weight_t ref_val;
for (idx = tid_info.get_global_id(0); idx < num_pairs; idx += tid_info.get_global_range(0)) {
row = first_pair[idx];
col = second_pair[idx];
// find which row has least elements (and call it reference row)
Ni = csrPtr[row + 1] - csrPtr[row];
Nj = csrPtr[col + 1] - csrPtr[col];
ref = (Ni < Nj) ? row : col;
cur = (Ni < Nj) ? col : row;
// compute new sum weights
weight_s[idx] = work[row] + work[col];
// compute new intersection weights
// search for the element with the same column index in the reference row
for (i = csrPtr[ref] + tid_info.get_global_id(2); i < csrPtr[ref + 1];
i += tid_info.get_global_range(2)) {
match = -1;
ref_col = csrInd[i];
if constexpr (weighted) {
ref_val = v[ref_col];
} else {
ref_val = 1.0;
}
// binary search (column indices are sorted within each row)
edge_t left = csrPtr[cur];
edge_t right = csrPtr[cur + 1] - 1;
while (left <= right) {
edge_t middle = (left + right) >> 1;
cur_col = csrInd[middle];
if (cur_col > ref_col) {
right = middle - 1;
} else if (cur_col < ref_col) {
left = middle + 1;
} else {
match = middle;
break;
}
}
// if the element with the same column index in the reference row has been found
if (match != -1) {
// FIXME: Update to SYCL 2020 atomic_refs
if constexpr (std::is_same<weight_t, double>::value) {
// if constexpr (typeid(weight_t) == typeid(double)) {
#ifdef EMULATE_ATOMIC_ADD_DOUBLE
cl::sycl::atomic<uint64_t> atom_weight{
cl::sycl::global_ptr<uint64_t>{(uint64_t *)&weight_i[i]}};
myAtomicAdd(atom_weight, ref_val);
#else
cl::sycl::atomic<weight_t> atom_weight{cl::sycl::global_ptr<weight_t>{&weight_i[i]}};
atom_weight.fetch_add(ref_val);
#endif
}
// if constexpr (typeid(weight_t) == typeid(float)) {
if constexpr (std::is_same<weight_t, float>::value) {
#ifdef EMULATE_ATOMIC_ADD_FLOAT
cl::sycl::atomic<uint32_t> atom_weight{
cl::sycl::global_ptr<uint32_t>{(uint32_t *)&weight_i[i]}};
myAtomicAdd(atom_weight, ref_val);
#else
cl::sycl::atomic<weight_t> atom_weight{cl::sycl::global_ptr<weight_t>{&weight_i[i]}};
atom_weight.fetch_add(ref_val);
#endif
}
// FIXME: Use the below with a sycl::atomic once hipSYCL supports the 2020 Floating
// atomics atomicAdd(&weight_i[j], ref_val);
}
}
}
}
template <bool weighted, typename vertex_t, typename edge_t, typename weight_t>
const cl::sycl::event Jaccard_IsPairsKernel<weighted, vertex_t, edge_t, weight_t>::invoke(
vertex_t n, edge_t num_pairs, cl::sycl::buffer<edge_t> &csrPtr,
cl::sycl::buffer<vertex_t> &csrInd, cl::sycl::buffer<vertex_t> &first_pair,
cl::sycl::buffer<vertex_t> &second_pair, cl::sycl::buffer<weight_t> *weight_in,
cl::sycl::buffer<weight_t> &work, cl::sycl::buffer<weight_t> &weight_i,
cl::sycl::buffer<weight_t> &weight_s,
cl::sycl::buffer<weight_t> &weight_j, cl::sycl::queue &q) {
// setup launch configuration
// FIXME: De-CUDA the MAX_KERNEL_THREADS and MAX_BLOCKS defines
cl::sycl::range<3> is_local{32, 1, 8};
cl::sycl::range<3> is_global{1 * is_local.get(0), 1 * is_local.get(1),
std::min((size_t)(n + is_local.get(2) - 1) / is_local.get(2),
(size_t)vertex_t{CUDA_MAX_BLOCKS}) *
is_local.get(2)};
cl::sycl::event ispairs_event;
try {
// launch kernel
// FIXME: Implement in SYCL lamda
ispairs_event = q.submit([&](cl::sycl::handler &cgh) {
cl::sycl::accessor<edge_t, 1, cl::sycl::access::mode::read> csrPtr_acc =
csrPtr.template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)n + 1});
cl::sycl::accessor<vertex_t, 1, cl::sycl::access::mode::read> csrInd_acc =
csrInd.template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)num_pairs});
cl::sycl::accessor<vertex_t, 1, cl::sycl::access::mode::read> first_pair_acc =
first_pair.template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)num_pairs});
cl::sycl::accessor<vertex_t, 1, cl::sycl::access::mode::read> second_pair_acc =
second_pair.template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)num_pairs});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read> work_acc =
work.template get_access<cl::sycl::access::mode::read>(cgh,
cl::sycl::range<1>{(size_t)n});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read_write> weight_i_acc =
weight_i.template get_access<cl::sycl::access::mode::read_write>(
cgh, cl::sycl::range<1>{(size_t)num_pairs});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::discard_write> weight_s_acc =
weight_s.template get_access<cl::sycl::access::mode::discard_write>(
cgh, cl::sycl::range<1>{(size_t)num_pairs});
;
if constexpr (weighted) {
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read> weight_in_acc =
weight_in->template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)num_pairs});
;
Jaccard_IsPairsKernel<true, vertex_t, edge_t, weight_t> is_kernel(
num_pairs, csrPtr_acc, csrInd_acc, first_pair_acc, second_pair_acc, weight_in_acc,
work_acc, weight_i_acc, weight_s_acc);
cgh.parallel_for(cl::sycl::nd_range<3>{is_global, is_local}, is_kernel);
} else {
Jaccard_IsPairsKernel<false, vertex_t, edge_t, weight_t> is_kernel(
num_pairs, csrPtr_acc, csrInd_acc, first_pair_acc, second_pair_acc, work_acc,
weight_i_acc, weight_s_acc);
cgh.parallel_for(cl::sycl::nd_range<3>{is_global, is_local}, is_kernel);
}
});
} catch (sycl::exception e) {
std::cerr << "SYCL Exception during VC IsPairs\n\t" << e.what() << std::endl;
}
return ispairs_event;
}
// Jaccard weights (*weight)
template <typename vertex_t, typename edge_t, typename weight_t>
const void
Jaccard_JwKernel<vertex_t, edge_t, weight_t>::operator()(cl::sycl::nd_item<1> tid_info) const {
edge_t j;
weight_t Wi, Ws, Wu;
for (j = tid_info.get_global_id(0); j < e; j += tid_info.get_global_range(0)) {
Wi = weight_i[j];
Ws = weight_s[j];
Wu = Ws - Wi;
weight_j[j] = (Wi / Wu);
}
}
template <typename vertex_t, typename edge_t, typename weight_t>
const cl::sycl::event Jaccard_JwKernel<vertex_t, edge_t, weight_t>::invoke(
edge_t e, cl::sycl::buffer<weight_t> &weight_i, cl::sycl::buffer<weight_t> &weight_s,
cl::sycl::buffer<weight_t> &weight_j, cl::sycl::queue &q) {
// setup launch configuration
cl::sycl::range<1> jw_local{std::min((size_t)e, (size_t)edge_t{CUDA_MAX_KERNEL_THREADS})};
cl::sycl::range<1> jw_global{std::min((size_t)(e + jw_local.get(0) - 1) / jw_local.get(0),
(size_t)edge_t{CUDA_MAX_BLOCKS}) *
jw_local.get(0)};
cl::sycl::event jw_event;
try {
// launch kernel
jw_event = q.submit([&](cl::sycl::handler &cgh) {
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read> weight_i_acc =
weight_i.template get_access<cl::sycl::access::mode::read>(cgh,
cl::sycl::range<1>{(size_t)e});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read> weight_s_acc =
weight_s.template get_access<cl::sycl::access::mode::read>(cgh,
cl::sycl::range<1>{(size_t)e});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::discard_write> weight_j_acc =
weight_j.template get_access<cl::sycl::access::mode::discard_write>(
cgh, cl::sycl::range<1>{(size_t)e});
Jaccard_JwKernel<vertex_t, edge_t, weight_t> jw_kernel(e, weight_i_acc, weight_s_acc,
weight_j_acc);
cgh.parallel_for(cl::sycl::nd_range<1>{jw_global, jw_local}, jw_kernel);
});
} catch (sycl::exception e) {
std::cerr << "SYCL Exception during VC Weights\n\t" << e.what() << std::endl;
}
return jw_event;
}
template <typename vertex_t, typename edge_t, typename weight_t>
const void
Jaccard_ec_scan<vertex_t, edge_t, weight_t>::operator()(cl::sycl::nd_item<1> tid_info) const {
edge_t j, i;
for (j = tid_info.get_global_id(0); j < n; j += tid_info.get_global_range(0)) {
for (i = csrPtr[j]; i < csrPtr[j + 1]; i++) {
dest_ind[i] = j;
weight_j[i] = 0;
}
}
}
template <typename vertex_t, typename edge_t, typename weight_t>
const cl::sycl::event Jaccard_ec_scan<vertex_t, edge_t, weight_t>::invoke(
edge_t e, vertex_t n, cl::sycl::buffer<edge_t> &csrPtr, cl::sycl::buffer<vertex_t> &dest_ind,
cl::sycl::buffer<weight_t> &weight_j, cl::sycl::queue &q) {
cl::sycl::range<1> local{std::min((size_t)n, (size_t)vertex_t{CUDA_MAX_KERNEL_THREADS})};
cl::sycl::range<1> global{
std::min((size_t)(n + local.get(0) - 1) / local.get(0), (size_t)vertex_t{CUDA_MAX_BLOCKS}) *
local.get(0)};
cl::sycl::event scan_event;
// Scan kernel to set up adjacency list
try {
scan_event = q.submit([&](cl::sycl::handler &cgh) {
cl::sycl::accessor<edge_t, 1, cl::sycl::access::mode::read> csrPtr_acc =
csrPtr.template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)n + 1});
cl::sycl::accessor<vertex_t, 1, cl::sycl::access::mode::read_write> dest_ind_acc =
dest_ind.template get_access<cl::sycl::access::mode::read_write>(
cgh, cl::sycl::range<1>{(size_t)e});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read_write> weight_j_acc =
weight_j.template get_access<cl::sycl::access::mode::read_write>(
cgh, cl::sycl::range<1>{(size_t)e});
Jaccard_ec_scan<vertex_t, edge_t, weight_t> escan_kernel(e, n, csrPtr_acc, dest_ind_acc,
weight_j_acc);
cgh.parallel_for(cl::sycl::nd_range<1>{global, local}, escan_kernel);
});
#ifdef DEBUG_2
q.wait();
#endif // DEBUG_2
} catch (sycl::exception e) {
std::cerr << "SYCL Exception during EC-Scan enqueue\n\t" << e.what() << std::endl;
}
return scan_event;
}
// Edge-centric-unweighted-kernel
template <typename vertex_t, typename edge_t, typename weight_t>
const void
Jaccard_ec_unweighted<vertex_t, edge_t, weight_t>::operator()(cl::sycl::nd_item<1> tid_info) const {
edge_t i, j, Ni, Nj, tid;
vertex_t row, col;
vertex_t ref, cur, ref_col, cur_col, match;
weight_t ref_val;
for (tid = tid_info.get_global_id(0); tid < e; tid += tid_info.get_global_range(0)) {
row = csrInd[tid];
col = dest_ind[tid];
// find which row has least elements (and call it reference row)
Ni = csrPtr[row + 1] - csrPtr[row];
Nj = csrPtr[col + 1] - csrPtr[col];
ref = (Ni < Nj) ? row : col;
cur = (Ni < Nj) ? col : row;
// compute new sum weights
for (i = csrPtr[ref]; i < csrPtr[ref + 1]; i++) {
ref_col = csrInd[i];
// binary search (column indices are sorted within each row)
edge_t left = csrPtr[cur];
edge_t right = csrPtr[cur + 1] - 1;
while (left <= right) {
edge_t middle = (left + right) >> 1;
cur_col = csrInd[middle];
if (cur_col > ref_col) {
right = middle - 1;
} else if (cur_col < ref_col) {
left = middle + 1;
} else {
weight_j[tid] = weight_j[tid] + 1;
break;
}
}
}
// compute JS
weight_j[tid] = weight_j[tid] / ((weight_t)(Ni + Nj) - weight_j[tid]);
}
}
template <typename vertex_t, typename edge_t, typename weight_t>
const cl::sycl::event Jaccard_ec_unweighted<vertex_t, edge_t, weight_t>::invoke(
edge_t e, vertex_t n, cl::sycl::buffer<edge_t> &csrPtr, cl::sycl::buffer<vertex_t> &csrInd,
cl::sycl::buffer<vertex_t> &dest_ind, cl::sycl::buffer<weight_t> &weight_j,
cl::sycl::queue &q) {
cl::sycl::range<1> local{std::min((size_t)e, (size_t)edge_t{CUDA_MAX_KERNEL_THREADS})};
cl::sycl::range<1> global{
std::min((size_t)(e + local.get(0) - 1) / local.get(0), (size_t)edge_t{CUDA_MAX_BLOCKS}) *
local.get(0)};
cl::sycl::event edgec_event;
try {
// Edge-centric kernel
edgec_event = q.submit([&](cl::sycl::handler &cgh) {
cl::sycl::accessor<edge_t, 1, cl::sycl::access::mode::read> csrPtr_acc =
csrPtr.template get_access<cl::sycl::access::mode::read>(
cgh, cl::sycl::range<1>{(size_t)n + 1});
cl::sycl::accessor<vertex_t, 1, cl::sycl::access::mode::read> csrInd_acc =
csrInd.template get_access<cl::sycl::access::mode::read>(cgh,
cl::sycl::range<1>{(size_t)e});
cl::sycl::accessor<vertex_t, 1, cl::sycl::access::mode::read> dest_ind_acc =
dest_ind.template get_access<cl::sycl::access::mode::read>(cgh,
cl::sycl::range<1>{(size_t)e});
cl::sycl::accessor<weight_t, 1, cl::sycl::access::mode::read_write> weight_j_acc =
weight_j.template get_access<cl::sycl::access::mode::read_write>(
cgh, cl::sycl::range<1>{(size_t)e});
Jaccard_ec_unweighted<vertex_t, edge_t, weight_t> ec_kernel(e, n, csrPtr_acc, csrInd_acc,
dest_ind_acc, weight_j_acc);
cgh.parallel_for(cl::sycl::nd_range<1>{global, local}, ec_kernel);
});
#ifdef DEBUG_2
q.wait();
#endif // DEBUG_2
} catch (sycl::exception e) {
std::cerr << "SYCL Exception during EC-unweighted enqueue\n\t" << e.what() << std::endl;
}
return edgec_event;
}
template <bool edge_centric, bool weighted, typename vertex_t, typename edge_t, typename weight_t>
int jaccard(vertex_t n, edge_t e, cl::sycl::buffer<edge_t> &csrPtr,
cl::sycl::buffer<vertex_t> &csrInd, cl::sycl::buffer<weight_t> *weight_in,
cl::sycl::buffer<weight_t> &work, cl::sycl::buffer<weight_t> &weight_i,
cl::sycl::buffer<weight_t> &weight_s, cl::sycl::buffer<vertex_t> &dest_ind,
cl::sycl::buffer<weight_t> &weight_j, cl::sycl::queue &q) {
if constexpr (edge_centric) { // Edge-Centric
cl::sycl::event scan_event =
Jaccard_ec_scan<vertex_t, edge_t, weight_t>::invoke(e, n, csrPtr, dest_ind, weight_j, q);
cl::sycl::event edgec_event = Jaccard_ec_unweighted<vertex_t, edge_t, weight_t>::invoke(
e, n, csrPtr, csrInd, dest_ind, weight_j, q);
#ifdef EVENT_PROFILE
try {
wait_and_print(scan, "ECScan")
} catch (sycl::exception e) {
std::cerr << "SYCL Exception while waiting for EC-scan\n\t" << e.what() << std::endl;
}
try {
wait_and_print(edgec, "ECUnweighted")
} catch (sycl::exception e) {
std::cerr << "SYCL Exception while waiting for EC-unweighted\n\t" << e.what() << std::endl;
}
#endif // EVENT_PROFILE
weight_t thresh = 0.00001;
int count = 0;
auto debug_res =
weight_j.template get_access<cl::sycl::access::mode::read>(cl::sycl::range<1>(e));
for (edge_t i = 0; i < e; i++) {
// std::cout << debug_res[i] << std::endl;
if (debug_res[i] > thresh) count++;
}
std::cout << "vertices " << n << "edges " << e << "non zero pairs " << count << std::endl;
} else { // Vertex-Centric
cl::sycl::event sum_event = Jaccard_RowSumKernel<weighted, vertex_t, edge_t, weight_t>::invoke(
n, e, csrPtr, csrInd, weight_in, work, q);
#ifdef DEBUG_2
// cl::sycl::queue debug = cl::sycl::queue(cl::sycl::cpu_selector());
std::cout << "DEBUG: Post-RowSum Work matrix of " << n << " elements" << std::endl;
{
// debug.submit([&](cl::sycl::handler &cgh){
auto debug_acc =
work.template get_access<cl::sycl::access::mode::read>(cl::sycl::range<1>(n));
for (int i = 0; i < n; i++) {
std::cout << debug_acc[i] << std::endl;
}
// });
}
#endif // DEBUG_2
cl::sycl::event fill_event = FillKernel<weight_t>::invoke(e, weight_i, weight_t{0.0}, q);
#ifdef DEBUG_2
q.wait();
std::cout << "DEBUG: Post-Fill Weight_i matrix of " << e << " elements" << std::endl;
{
// debug.submit([&](cl::sycl::handler &cgh){
auto debug_acc =
weight_i.template get_access<cl::sycl::access::mode::read>(cl::sycl::range<1>(n));
for (int i = 0; i < e; i++) {
std::cout << debug_acc[i] << std::endl;
}
// });
}
#endif // DEBUG_2
cl::sycl::event is_event = Jaccard_IsKernel<weighted, vertex_t, edge_t, weight_t>::invoke(
n, e, csrPtr, csrInd, weight_in, work, weight_i, weight_s, q);
#ifdef DEBUG_2
q.wait();
std::cout << "DEBUG: Post-IS Weight_i and Weight_s matrices of " << e << " elements"
<< std::endl;
{
// debug.submit([&](cl::sycl::handler &cgh){
auto debug_acc =
weight_i.template get_access<cl::sycl::access::mode::read>(cl::sycl::range<1>(n));
auto debug2_acc =
weight_s.template get_access<cl::sycl::access::mode::read>(cl::sycl::range<1>(n));
for (int i = 0; i < e; i++) {
std::cout << debug_acc[i] << " " << debug2_acc[i] << std::endl;
}
// });
}
#endif // DEBUG_2
cl::sycl::event jw_event =
Jaccard_JwKernel<vertex_t, edge_t, weight_t>::invoke(e, weight_i, weight_s, weight_j, q);
#ifdef DEBUG_2
q.wait();
#endif // DEBUG_2
#ifdef EVENT_PROFILE
try {
wait_and_print(sum, "VCRowSum")
} catch (sycl::exception e) {
std::cerr << "SYCL Exception while waiting for VC RowSum\n\t" << e.what() << std::endl;
}
try {
wait_and_print(fill, "VCFill")
} catch (sycl::exception e) {
std::cerr << "SYCL Exception while waiting for VC Fill\n\t" << e.what() << std::endl;
}
try {
wait_and_print(is, "VCIntersection")
} catch (sycl::exception e) {
std::cerr << "SYCL Exception while waiting for VC Intersection\n\t" << e.what() << std::endl;
}
try {
wait_and_print(jw, "VCJaccardWeight")
} catch (sycl::exception e) {
std::cerr << "SYCL Exception while waiting for VC Weights\n\t" << e.what() << std::endl;
}
#endif // EVENT_PROFILE
}
return 0;
}
template <bool weighted, typename vertex_t, typename edge_t, typename weight_t>
int jaccard_pairs(vertex_t n, edge_t num_pairs, cl::sycl::buffer<edge_t> &csrPtr,
cl::sycl::buffer<vertex_t> &csrInd, cl::sycl::buffer<vertex_t> &first_pair,
cl::sycl::buffer<vertex_t> &second_pair, cl::sycl::buffer<weight_t> *weight_in,
cl::sycl::buffer<weight_t> &work, cl::sycl::buffer<weight_t> &weight_i,
cl::sycl::buffer<weight_t> &weight_s,
cl::sycl::buffer<weight_t> &weight_j, cl::sycl::queue &q) {
Jaccard_RowSumKernel<weighted, vertex_t, edge_t, weight_t>::invoke(n, num_pairs, csrPtr, csrInd,
weight_in, work, q);
q.wait();
// NOTE: initilized weight_i vector with 0.0
// fill(num_pairs, weight_i, weight_t{0.0}, q);
Jaccard_IsPairsKernel<weighted, vertex_t, edge_t, weight_t>::invoke(
n, num_pairs, csrPtr, csrInd, first_pair, second_pair, weight_in, work, weight_i, weight_s,
q);
Jaccard_JwKernel<vertex_t, edge_t, weight_t>::invoke(num_pairs, weight_i, weight_s, weight_j, q);
return 0;
}
} // namespace detail
#ifndef DISABLE_WEIGHTED
template <bool edge_centric, typename VT, typename ET, typename WT>
void jaccard(GraphCSRView<VT, ET, WT> &graph, cl::sycl::buffer<WT> &weights,
cl::sycl::buffer<WT> &result, cl::sycl::queue &q) {
cl::sycl::buffer<WT> weight_i(cl::sycl::range<1>(graph.number_of_edges));
cl::sycl::buffer<WT> weight_s(cl::sycl::range<1>(graph.number_of_edges));
cl::sycl::buffer<WT> work(cl::sycl::range<1>(graph.number_of_vertices));
cl::sycl::buffer<VT> dest_ind(cl::sycl::range<1>(graph.number_of_edges));
sygraph::detail::jaccard<edge_centric, true, VT, ET, WT>(
graph.number_of_vertices, graph.number_of_edges, graph.offsets, graph.indices, &weights, work,
weight_i, weight_s, dest_ind, result, q);
// Buffers autodestruct at end of function scope
}
#endif // DISABLE_WEIGHTED
#ifndef DISABLE_UNWEIGHTED
template <bool edge_centric, typename VT, typename ET, typename WT>
void jaccard(GraphCSRView<VT, ET, WT> &graph, cl::sycl::buffer<WT> &result, cl::sycl::queue &q) {
cl::sycl::buffer<WT> weight_i(cl::sycl::range<1>(graph.number_of_edges));
cl::sycl::buffer<WT> weight_s(cl::sycl::range<1>(graph.number_of_edges));
cl::sycl::buffer<WT> work(cl::sycl::range<1>(graph.number_of_vertices));
cl::sycl::buffer<VT> dest_ind(cl::sycl::range<1>(graph.number_of_edges));
sygraph::detail::jaccard<edge_centric, false, VT, ET, WT>(
graph.number_of_vertices, graph.number_of_edges, graph.offsets, graph.indices, nullptr, work,
weight_i, weight_s, dest_ind, result, q);
// Buffers autodestruct at end of function scope
}
#endif // DISABLE_UNWEIGHTED
#ifndef DISABLE_LIST
#ifndef DISABLE_WEIGHTED
template <typename VT, typename ET, typename WT>
void jaccard_list(GraphCSRView<VT, ET, WT> &graph, cl::sycl::buffer<WT> &weights, ET num_pairs,
cl::sycl::buffer<VT> &first, cl::sycl::buffer<VT> &second,
cl::sycl::buffer<WT> &result, cl::sycl::queue &q) {
cl::sycl::buffer<WT> weight_i(cl::sycl::range<1>(graph.number_of_edges));
cl::sycl::buffer<WT> weight_s(cl::sycl::range<1>(graph.number_of_edges));
cl::sycl::buffer<WT> work(cl::sycl::range<1>(graph.number_of_vertices));
sygraph::detail::jaccard_pairs<true, VT, ET, WT>(graph.number_of_vertices, num_pairs,
graph.offsets, graph.indices, first, second,
&weights, work, weight_i, weight_s, result, q);
// Buffers autodestruct at end of function scope
}
#endif // DISABLE_WEIGHTED
#ifdef DISABLE_UNWEIGHTED
template <typename VT, typename ET, typename WT>
void jaccard_list(GraphCSRView<VT, ET, WT> &graph, ET num_pairs, cl::sycl::buffer<VT> &first,
cl::sycl::buffer<VT> &second, cl::sycl::buffer<WT> &result, cl::sycl::queue &q) {
cl::sycl::buffer<WT> weight_i(cl::sycl::range<1>(graph.number_of_edges));
cl::sycl::buffer<WT> weight_s(cl::sycl::range<1>(graph.number_of_edges));
cl::sycl::buffer<WT> work(cl::sycl::range<1>(graph.number_of_vertices));
sygraph::detail::jaccard_pairs<false, VT, ET, WT>(graph.number_of_vertices, num_pairs,
graph.offsets, graph.indices, first, second,
nullptr, work, weight_i, weight_s, result, q);
// Buffers autodestruct at end of function scope
}
#endif // DISABLE_UNWEIGHTED
#endif // DISABLE_LIST
#ifndef DISABLE_WEIGHTED
template void jaccard<true, int32_t, int32_t, float>(GraphCSRView<int32_t, int32_t, float> &,
cl::sycl::buffer<float> &,
cl::sycl::buffer<float> &, cl::sycl::queue &q);
template void jaccard<false, int32_t, int32_t, float>(GraphCSRView<int32_t, int32_t, float> &,
cl::sycl::buffer<float> &,
cl::sycl::buffer<float> &,
cl::sycl::queue &q);
#ifndef DISABLE_DP_INDEX
template void jaccard<true, int64_t, int64_t, float>(GraphCSRView<int64_t, int64_t, float> &,
cl::sycl::buffer<float> &,