forked from N-BodyShop/changa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHostCUDA.cu
2663 lines (2308 loc) · 93.1 KB
/
HostCUDA.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
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
#ifdef _WIN32
#define NOMINMAX
#endif
#ifdef HAPI_MEMPOOL
#define GPU_MEMPOOL
#endif
#ifdef HAPI_INSTRUMENT_WRS
#define GPU_INSTRUMENT_WRS
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
// #include <cutil.h>
#include <assert.h>
#include "CudaFunctions.h"
#include "CUDAMoments.cu"
#include "HostCUDA.h"
#include "EwaldCUDA.h"
#include "hapi.h"
#include "cuda_typedef.h"
#include "cuda/intrinsics/voting.hu"
#include "cuda/intrinsics/shfl.hu"
#ifdef GPU_LOCAL_TREE_WALK
#include "codes.h"
#endif //GPU_LOCAL_TREE_WALK
#ifdef HAPI_TRACE
# define HAPI_TRACE_BEGIN() double trace_start_time = CmiWallTimer()
# define HAPI_TRACE_END(ID) traceUserBracketEvent(ID, trace_start_time, CmiWallTimer())
#else
# define HAPI_TRACE_BEGIN() /* */
# define HAPI_TRACE_END(ID) /* */
#endif
#define cudaChk(code) cudaErrorDie(code, #code, __FILE__, __LINE__)
inline void cudaErrorDie(cudaError_t retCode, const char* code,
const char* file, int line) {
if (retCode != cudaSuccess) {
fprintf(stderr, "Fatal CUDA Error %s at %s:%d.\nReturn value %d from '%s'.",
cudaGetErrorString(retCode), file, line, retCode, code);
abort();
}
}
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
#include "converse.h"
#endif
__device__ __constant__ EwaldReadOnlyData cachedData[1];
__device__ __constant__ EwtData ewt[NEWH];
//__constant__ constantData[88];
//
//
#ifdef HAPI_TRACE
extern "C" void traceUserBracketEvent(int e, double beginT, double endT);
extern "C" double CmiWallTimer();
#endif
void allocatePinnedHostMemory(void **ptr, size_t size){
if(size <= 0){
*((char **)ptr) = NULL;
#ifdef CUDA_PRINT_ERRORS
printf("allocatePinnedHostMemory: 0 size!\n");
#endif
assert(0);
return;
}
#ifdef HAPI_MEMPOOL
hapiMallocHost(ptr, size, true);
#else
hapiMallocHost(ptr, size, false);
#endif
#ifdef CUDA_PRINT_ERRORS
printf("allocatePinnedHostMemory: %s size: %zu\n", cudaGetErrorString( cudaGetLastError() ), size);
#endif
}
void freePinnedHostMemory(void *ptr){
if(ptr == NULL){
#ifdef CUDA_PRINT_ERRORS
printf("freePinnedHostMemory: NULL ptr!\n");
#endif
assert(0);
return;
}
#ifdef HAPI_MEMPOOL
hapiFreeHost(ptr, true);
#else
hapiFreeHost(ptr, false);
#endif
#ifdef CUDA_PRINT_ERRORS
printf("freePinnedHostMemory: %s\n", cudaGetErrorString( cudaGetLastError() ));
#endif
}
/******************* Transfers ******************/
void run_DM_TRANSFER_LOCAL(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("DM_TRANSFER_LOCAL KERNELSELECT\n");
printf("mom: 0x%x\n", devBuffers[LOCAL_MOMENTS]);
printf("cores: 0x%x\n", devBuffers[LOCAL_PARTICLE_CORES]);
printf("vars: 0x%x\n", devBuffers[LOCAL_PARTICLE_VARS]);
#endif
}
void run_DM_TRANSFER_REMOTE_CHUNK(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("DM_TRANSFER_REMOTE_CHUNK, %d KERNELSELECT\n", wr->buffers[REMOTE_MOMENTS_IDX].transfer_to_device);
#endif
}
void run_DM_TRANSFER_FREE_LOCAL(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("DM_TRANSFER_FREE_LOCAL KERNELSELECT\n");
printf("buffers:\nlocal_particles: (0x%x)\nlocal_particle_vars: (0x%x)\nlocal_moments: (0x%x)\n",
devBuffers[LOCAL_PARTICLE_CORES],
devBuffers[LOCAL_PARTICLE_VARS],
devBuffers[LOCAL_MOMENTS]
);
#endif
}
/// @brief queue work request to tranfer local moments and particles to GPU
/// @param moments array of moments
/// @param nMoments
/// @param compactParts Array of particles
/// @param nCompactParts
/// @param mype Only used for debugging
#ifdef HAPI_INSTRUMENT_WRS
void DataManagerTransferLocalTree(void *moments, size_t sMoments,
void *compactParts, size_t sCompactParts,
void *varParts, size_t sVarParts,
int mype, char phase, void *wrCallback) {
#else
void DataManagerTransferLocalTree(void *moments, size_t sMoments,
void *compactParts, size_t sCompactParts,
void *varParts, size_t sVarParts,
int mype, void *wrCallback) {
#endif
hapiWorkRequest* transferKernel = hapiCreateWorkRequest();
transferKernel->addBuffer(moments, sMoments, (sMoments > 0), false,
false, LOCAL_MOMENTS);
transferKernel->addBuffer(compactParts, sCompactParts,
(sCompactParts > 0), false, false,
LOCAL_PARTICLE_CORES);
transferKernel->addBuffer(varParts, sVarParts, (sVarParts > 0), false,
false, LOCAL_PARTICLE_VARS);
transferKernel->setDeviceToHostCallback(wrCallback);
#ifdef HAPI_TRACE
transferKernel->setTraceName("xferLocal");
#endif
transferKernel->setRunKernel(run_DM_TRANSFER_LOCAL);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) DM LOCAL TREE moments %zu (%d) partcores %zu (%d) partvars %zu (%d)\n",
CmiMyPe(),
transferKernel->buffers[LOCAL_MOMENTS_IDX].size,
transferKernel->buffers[LOCAL_MOMENTS_IDX].transfer_to_device,
transferKernel->buffers[LOCAL_PARTICLE_CORES_IDX].size,
transferKernel->buffers[LOCAL_PARTICLE_CORES_IDX].transfer_to_device,
transferKernel->buffers[LOCAL_PARTICLE_VARS_IDX].size,
transferKernel->buffers[LOCAL_PARTICLE_VARS_IDX].transfer_to_device
);
#endif
#ifdef HAPI_INSTRUMENT_WRS
transferKernel->chare_index = mype;
transferKernel->comp_type = DM_TRANSFER_LOCAL;
transferKernel->comp_phase = phase;
#endif
hapiEnqueue(transferKernel);
}
#ifdef HAPI_INSTRUMENT_WRS
void DataManagerTransferRemoteChunk(void *moments, size_t sMoments,
void *compactParts, size_t sCompactParts,
int mype, char phase, void *wrCallback) {
#else
void DataManagerTransferRemoteChunk(void *moments, size_t sMoments,
void *compactParts, size_t sCompactParts,
void *wrCallback) {
#endif
hapiWorkRequest* transferKernel = hapiCreateWorkRequest();
transferKernel->addBuffer(moments, sMoments, (sMoments > 0), false, false,
REMOTE_MOMENTS);
transferKernel->addBuffer(compactParts, sCompactParts, (sCompactParts > 0),
false, false, REMOTE_PARTICLE_CORES);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) DM REMOTE CHUNK moments %zu (%d) partcores %zu (%d)\n",
CmiMyPe(),
transferKernel->buffers[REMOTE_MOMENTS_IDX].size,
transferKernel->buffers[REMOTE_MOMENTS_IDX].transfer_to_device,
transferKernel->buffers[REMOTE_PARTICLE_CORES_IDX].size,
transferKernel->buffers[REMOTE_PARTICLE_CORES_IDX].transfer_to_device
);
#endif
transferKernel->setDeviceToHostCallback(wrCallback);
#ifdef HAPI_TRACE
transferKernel->setTraceName("xferRemote");
#endif
transferKernel->setRunKernel(run_DM_TRANSFER_REMOTE_CHUNK);
#ifdef HAPI_INSTRUMENT_WRS
transferKernel->chare_index = mype;
transferKernel->comp_type = DM_TRANSFER_REMOTE_CHUNK;
transferKernel->comp_phase = phase;
#endif
hapiEnqueue(transferKernel);
}
/************** Gravity *****************/
void run_TP_GRAVITY_LOCAL(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
ParameterStruct *ptr = (ParameterStruct *)wr->getUserData();
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("TP_GRAVITY_LOCAL KERNELSELECT buffers:\nlocal_particles: (0x%x)\nlocal_particle_vars: (0x%x)\nlocal_moments: (0x%x)\nil_cell: %d (0x%x)\n",
devBuffers[LOCAL_PARTICLE_CORES],
devBuffers[LOCAL_PARTICLE_VARS],
devBuffers[LOCAL_MOMENTS],
wr->buffers[ILCELL_IDX].id,
devBuffers[wr->buffers[ILCELL_IDX].id]
);
#endif
if( wr->buffers[ILCELL_IDX].transfer_to_device ){
#ifndef CUDA_NO_KERNELS
#ifdef GPU_LOCAL_TREE_WALK
gpuLocalTreeWalk<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>> (
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CudaMultipoleMoments *)devBuffers[LOCAL_MOMENTS],
ptr->firstParticle,
ptr->lastParticle,
ptr->rootIdx,
ptr->theta,
ptr->thetaMono,
ptr->nReplicas,
ptr->fperiod,
ptr->fperiodY,
ptr->fperiodZ
);
#else
nodeGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CudaMultipoleMoments *)devBuffers[LOCAL_MOMENTS],
(ILCell *)devBuffers[wr->buffers[ILCELL_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#endif //GPU_LOCAL_TREE_WALK
cudaChk(cudaPeekAtLastError());
#endif
HAPI_TRACE_BEGIN();
#ifdef CUDA_PRINT_ERRORS
printf("TP_GRAVITY_LOCAL 0: %s\n", cudaGetErrorString( cudaGetLastError() ) );
#endif
HAPI_TRACE_END(CUDA_LOCAL_NODE_KERNEL);
}
}
void run_TP_PART_GRAVITY_LOCAL_SMALLPHASE(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
ParameterStruct *ptr = (ParameterStruct *)wr->getUserData();
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("TP_PART_GRAVITY_LOCAL_SMALLPHASE KERNELSELECT buffers:\nlocal_particles: (0x%x)\nlocal_particle_vars: (0x%x)\nil_cell: %d (0x%x)\n",
devBuffers[LOCAL_PARTICLE_CORES],
devBuffers[LOCAL_PARTICLE_VARS],
wr->buffers[ILPART_IDX].id,
devBuffers[wr->buffers[ILPART_IDX].id]
);
#endif
if( wr->buffers[ILPART_IDX].transfer_to_device ){
#ifndef CUDA_NO_KERNELS
#ifdef CUDA_2D_TB_KERNEL
particleGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CompactPartData *)devBuffers[wr->buffers[MISSED_PARTS_IDX].id],
(ILCell *)devBuffers[wr->buffers[ILPART_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#else
particleGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CompactPartData *)devBuffers[wr->buffers[MISSED_PARTS_IDX].id],
(ILPart *)devBuffers[wr->buffers[ILPART_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#endif
cudaChk(cudaPeekAtLastError());
#endif
HAPI_TRACE_BEGIN();
#ifdef CUDA_PRINT_ERRORS
printf("TP_PART_GRAVITY_LOCAL_SMALLPHASE 0: %s\n", cudaGetErrorString( cudaGetLastError() ) );
#endif
HAPI_TRACE_END(CUDA_LOCAL_PART_KERNEL);
}
}
void run_TP_PART_GRAVITY_LOCAL(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
ParameterStruct *ptr = (ParameterStruct *)wr->getUserData();
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("TP_PART_GRAVITY_LOCAL KERNELSELECT buffers:\nlocal_particles: (0x%x)\nlocal_particle_vars: (0x%x)\nil_cell: %d (0x%x)\n",
devBuffers[LOCAL_PARTICLE_CORES],
devBuffers[LOCAL_PARTICLE_VARS],
wr->buffers[ILPART_IDX].id,
devBuffers[wr->buffers[ILPART_IDX].id]
);
#endif
if( wr->buffers[ILPART_IDX].transfer_to_device ){
#ifndef CUDA_NO_KERNELS
#ifdef CUDA_2D_TB_KERNEL
particleGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(ILCell *)devBuffers[wr->buffers[ILPART_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#else
particleGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(ILPart *)devBuffers[wr->buffers[ILPART_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#endif
cudaChk(cudaPeekAtLastError());
#endif
HAPI_TRACE_BEGIN();
#ifdef CUDA_PRINT_ERRORS
printf("TP_PART_GRAVITY_LOCAL 0: %s\n", cudaGetErrorString( cudaGetLastError() ) );
#endif
HAPI_TRACE_END(CUDA_LOCAL_PART_KERNEL);
}
}
void run_TP_GRAVITY_REMOTE(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
ParameterStruct *ptr = (ParameterStruct *)wr->getUserData();
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("TP_GRAVITY_REMOTE KERNELSELECT buffers:\nlocal_particles: (0x%x)\nlocal_particle_vars: (0x%x)\nremote_moments: (0x%x)\nil_cell: %d (0x%x)\n",
devBuffers[LOCAL_PARTICLE_CORES],
devBuffers[LOCAL_PARTICLE_VARS],
devBuffers[REMOTE_MOMENTS],
wr->buffers[ILCELL_IDX].id,
devBuffers[wr->buffers[ILCELL_IDX].id]
);
#endif
if( wr->buffers[ILCELL_IDX].transfer_to_device ){
#ifndef CUDA_NO_KERNELS
nodeGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CudaMultipoleMoments *)devBuffers[REMOTE_MOMENTS],
(ILCell *)devBuffers[wr->buffers[ILCELL_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
cudaChk(cudaPeekAtLastError());
#endif
HAPI_TRACE_BEGIN();
#ifdef CUDA_PRINT_ERRORS
printf("TP_GRAVITY_REMOTE 0: %s\n", cudaGetErrorString( cudaGetLastError() ) );
#endif
HAPI_TRACE_END(CUDA_REMOTE_NODE_KERNEL);
}
}
void run_TP_PART_GRAVITY_REMOTE(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
ParameterStruct *ptr = (ParameterStruct *)wr->getUserData();
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("TP_PART_GRAVITY_REMOTE KERNELSELECT buffers:\nlocal_particles: (0x%x)\nlocal_particle_vars: (0x%x)\nil_cell: %d (0x%x)\n",
devBuffers[LOCAL_PARTICLE_CORES],
devBuffers[LOCAL_PARTICLE_VARS],
wr->buffers[ILPART_IDX].id,
devBuffers[wr->buffers[ILPART_IDX].id]
);
#endif
if( wr->buffers[ILPART_IDX].transfer_to_device ){
#ifndef CUDA_NO_KERNELS
#ifdef CUDA_2D_TB_KERNEL
particleGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CompactPartData *)devBuffers[REMOTE_PARTICLE_CORES],
(ILCell *)devBuffers[wr->buffers[ILPART_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#else
particleGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CompactPartData *)devBuffers[REMOTE_PARTICLE_CORES],
(ILPart *)devBuffers[wr->buffers[ILPART_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#endif
cudaChk(cudaPeekAtLastError());
#endif
HAPI_TRACE_BEGIN();
#ifdef CUDA_PRINT_ERRORS
printf("TP_PART_GRAVITY_REMOTE 0: %s\n", cudaGetErrorString( cudaGetLastError() ) );
#endif
HAPI_TRACE_END(CUDA_REMOTE_PART_KERNEL);
}
}
void run_TP_GRAVITY_REMOTE_RESUME(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
ParameterStruct *ptr = (ParameterStruct *)wr->getUserData();
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("TP_GRAVITY_REMOTE_RESUME KERNELSELECT buffers:\nlocal_particles: (0x%x)\nlocal_particle_vars: (0x%x)\nmissed_moments: %d (0x%x)\nil_cell: %d (0x%x)\n",
devBuffers[LOCAL_PARTICLE_CORES],
devBuffers[LOCAL_PARTICLE_VARS],
wr->buffers[MISSED_MOMENTS_IDX].id,
devBuffers[wr->buffers[MISSED_MOMENTS_IDX].id],
wr->buffers[ILCELL_IDX].id,
devBuffers[wr->buffers[ILCELL_IDX].id]
);
#endif
if( wr->buffers[ILCELL_IDX].transfer_to_device ){
#ifndef CUDA_NO_KERNELS
nodeGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CudaMultipoleMoments *)devBuffers[wr->buffers[MISSED_MOMENTS_IDX].id],
(ILCell *)devBuffers[wr->buffers[ILCELL_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[NODE_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
cudaChk(cudaPeekAtLastError());
#endif
HAPI_TRACE_BEGIN();
#ifdef CUDA_PRINT_ERRORS
printf("TP_GRAVITY_REMOTE_RESUME 0: %s\n", cudaGetErrorString( cudaGetLastError() ) );
#endif
HAPI_TRACE_END(CUDA_REMOTE_RESUME_NODE_KERNEL);
}
}
void run_TP_PART_GRAVITY_REMOTE_RESUME(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
ParameterStruct *ptr = (ParameterStruct *)wr->getUserData();
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("TP_PART_GRAVITY_REMOTE_RESUME KERNELSELECT buffers:\nlocal_particles: (0x%x)\nlocal_particle_vars: (0x%x)\nmissed_parts: %d (0x%x)\nil_cell: %d (0x%x)\n",
devBuffers[LOCAL_PARTICLE_CORES],
devBuffers[LOCAL_PARTICLE_VARS],
wr->buffers[MISSED_PARTS_IDX].id,
devBuffers[wr->buffers[MISSED_PARTS_IDX].id],
wr->buffers[ILPART_IDX].id,
devBuffers[wr->buffers[ILPART_IDX].id]
);
#endif
if( wr->buffers[ILPART_IDX].transfer_to_device ){
#ifndef CUDA_NO_KERNELS
#ifdef CUDA_2D_TB_KERNEL
particleGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CompactPartData *)devBuffers[wr->buffers[MISSED_PARTS_IDX].id],
(ILCell *)devBuffers[wr->buffers[ILPART_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#else
particleGravityComputation<<<wr->grid_dim, wr->block_dim, wr->shared_mem, kernel_stream>>>
(
(CompactPartData *)devBuffers[LOCAL_PARTICLE_CORES],
(VariablePartData *)devBuffers[LOCAL_PARTICLE_VARS],
(CompactPartData *)devBuffers[wr->buffers[MISSED_PARTS_IDX].id],
(ILPart *)devBuffers[wr->buffers[ILPART_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_START_MARKERS_IDX].id],
(int *)devBuffers[wr->buffers[PART_BUCKET_SIZES_IDX].id],
ptr->fperiod
);
#endif
cudaChk(cudaPeekAtLastError());
#endif
HAPI_TRACE_BEGIN();
#ifdef CUDA_PRINT_ERRORS
printf("TP_PART_GRAVITY_REMOTE_RESUME 0: %s\n", cudaGetErrorString( cudaGetLastError() ) );
#endif
HAPI_TRACE_END(CUDA_REMOTE_RESUME_PART_KERNEL);
}
}
void TreePieceCellListDataTransferLocal(CudaRequest *data){
int numBlocks = data->numBucketsPlusOne-1;
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
#ifdef CUDA_2D_TB_KERNEL
gravityKernel->setExecParams(numBlocks, dim3(NODES_PER_BLOCK, PARTS_PER_BLOCK));
#else
gravityKernel->setexecParams(numBlocks, THREADS_PER_BLOCK);
#endif
#ifdef GPU_LOCAL_TREE_WALK
// +1 to avoid dimGrid = 0 when we run test with extremely small input.
gravityKernel->setExecParams((data->lastParticle - data->firstParticle + 1)
/ THREADS_PER_BLOCK + 1, dim3(THREADS_PER_BLOCK));
#endif //GPU_LOCAL_TREE_WALK
TreePieceCellListDataTransferBasic(data, gravityKernel);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER LOCAL CELL\n", CmiMyPe());
#endif
gravityKernel->setDeviceToHostCallback(data->cb);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("gravityLocal");
#endif
gravityKernel->setRunKernel(run_TP_GRAVITY_LOCAL);
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = data->tpIndex;
gravityKernel->comp_type = TP_GRAVITY_LOCAL;
gravityKernel->comp_phase = data->phase;
#endif
hapiEnqueue(gravityKernel);
}
void TreePieceCellListDataTransferRemote(CudaRequest *data){
int numBlocks = data->numBucketsPlusOne-1;
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
#ifdef CUDA_2D_TB_KERNEL
gravityKernel->setExecParams(numBlocks, dim3(NODES_PER_BLOCK, PARTS_PER_BLOCK));
#else
gravityKernel->setExecParams(numBlocks, THREADS_PER_BLOCK);
#endif
TreePieceCellListDataTransferBasic(data, gravityKernel);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER REMOTE CELL\n", CmiMyPe());
#endif
gravityKernel->setDeviceToHostCallback(data->cb);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("gravityRemote");
#endif
gravityKernel->setRunKernel(run_TP_GRAVITY_REMOTE);
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = data->tpIndex;
gravityKernel->comp_type = TP_GRAVITY_REMOTE;
gravityKernel->comp_phase = data->phase;
#endif
hapiEnqueue(gravityKernel);
}
void TreePieceCellListDataTransferRemoteResume(CudaRequest *data){
int numBlocks = data->numBucketsPlusOne-1;
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
bool transfer;
#ifdef CUDA_2D_TB_KERNEL
gravityKernel->setExecParams(numBlocks, dim3(NODES_PER_BLOCK, PARTS_PER_BLOCK));
#else
gravityKernel->setExecParams(numBlocks, THREADS_PER_BLOCK);
#endif
TreePieceCellListDataTransferBasic(data, gravityKernel);
transfer = gravityKernel->buffers[ILCELL_IDX].transfer_to_device;
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER REMOTE RESUME CELL (%d)\n", CmiMyPe(), transfer);
#endif
gravityKernel->addBuffer(data->missedNodes, data->sMissed, transfer, false,
transfer);
ParameterStruct *ptr = (ParameterStruct *)gravityKernel->getUserData();
gravityKernel->setDeviceToHostCallback(data->cb);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("remoteResume");
#endif
gravityKernel->setRunKernel(run_TP_GRAVITY_REMOTE_RESUME);
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = data->tpIndex;
gravityKernel->comp_type = TP_GRAVITY_REMOTE_RESUME;
gravityKernel->comp_phase = data->phase;
#endif
hapiEnqueue(gravityKernel);
}
void TreePieceCellListDataTransferBasic(CudaRequest *data, hapiWorkRequest *gravityKernel){
int numBucketsPlusOne = data->numBucketsPlusOne;
int numBuckets = numBucketsPlusOne-1;
size_t size = (data->numInteractions) * sizeof(ILCell);
bool transfer = size > 0;
gravityKernel->addBuffer(data->list, size, transfer, false, transfer);
size = (numBucketsPlusOne) * sizeof(int);
gravityKernel->addBuffer(data->bucketMarkers, (transfer ? size : 0),
transfer, false, transfer);
size = (numBuckets) * sizeof(int);
gravityKernel->addBuffer(data->bucketStarts, size, transfer, false, transfer);
gravityKernel->addBuffer(data->bucketSizes, size, transfer, false, transfer);
ParameterStruct *ptr = (ParameterStruct *)malloc(sizeof(ParameterStruct));
ptr->numInteractions = data->numInteractions;
ptr->numBucketsPlusOne = numBucketsPlusOne;
ptr->fperiod = data->fperiod;
#ifdef GPU_LOCAL_TREE_WALK
ptr->firstParticle = data->firstParticle;
ptr->lastParticle = data->lastParticle;
ptr->rootIdx = data->rootIdx;
ptr->theta = data->theta;
ptr->thetaMono = data->thetaMono;
ptr->nReplicas = data->nReplicas;
ptr->fperiod = data->fperiod;
ptr->fperiodY = data->fperiodY;
ptr->fperiodZ = data->fperiodZ;
#endif //GPU_LOCAL_TREE_WALK
gravityKernel->setUserData(ptr, true);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER BASIC cells %zu (%d) bucket_markers %zu (%d) bucket_starts %zu (%d) bucket_sizes %zu (%d)\n",
CmiMyPe(),
gravityKernel->buffers[ILCELL_IDX].size,
gravityKernel->buffers[ILCELL_IDX].transfer_to_device,
gravityKernel->buffers[NODE_BUCKET_MARKERS_IDX].size,
gravityKernel->buffers[NODE_BUCKET_MARKERS_IDX].transfer_to_device,
gravityKernel->buffers[NODE_BUCKET_START_MARKERS_IDX].size,
gravityKernel->buffers[NODE_BUCKET_START_MARKERS_IDX].transfer_to_device,
gravityKernel->buffers[NODE_BUCKET_SIZES_IDX].size,
gravityKernel->buffers[NODE_BUCKET_SIZES_IDX].transfer_to_device
);
#endif
}
void TreePiecePartListDataTransferLocalSmallPhase(CudaRequest *data, CompactPartData *particles, int len){
int numBlocks = data->numBucketsPlusOne-1;
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
void* bufferHostBuffer;
size_t size;
bool transfer;
#ifdef CUDA_2D_TB_KERNEL
gravityKernel->setExecParams(numBlocks, dim3(NODES_PER_BLOCK_PART, PARTS_PER_BLOCK_PART));
#else
gravityKernel->setExecParams(numBlocks, THREADS_PER_BLOCK);
#endif
TreePiecePartListDataTransferBasic(data, gravityKernel);
transfer = gravityKernel->buffers[ILPART_IDX].transfer_to_device;
size = (len) * sizeof(CompactPartData);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER LOCAL SMALL PHASE %zu (%d)\n",
CmiMyPe(),
size,
transfer
);
#endif
if(transfer){
allocatePinnedHostMemory(&bufferHostBuffer, size);
#ifdef CUDA_PRINT_ERRORS
printf("TPPartSmallPhase 0: %s\n", cudaGetErrorString( cudaGetLastError() ) );
#endif
memcpy(bufferHostBuffer, particles, size);
}
gravityKernel->addBuffer(bufferHostBuffer, size, transfer, false, transfer);
gravityKernel->setDeviceToHostCallback(data->cb);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("partGravityLocal");
#endif
gravityKernel->setRunKernel(run_TP_PART_GRAVITY_LOCAL_SMALLPHASE);
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = data->tpIndex;
gravityKernel->comp_type = TP_PART_GRAVITY_LOCAL_SMALLPHASE;
gravityKernel->comp_phase = data->phase;
#endif
hapiEnqueue(gravityKernel);
}
void TreePiecePartListDataTransferLocal(CudaRequest *data){
int numBlocks = data->numBucketsPlusOne-1;
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
#ifdef CUDA_2D_TB_KERNEL
gravityKernel->setExecParams(numBlocks, dim3(NODES_PER_BLOCK_PART, PARTS_PER_BLOCK_PART));
#else
gravityKernel->setExecParams(numBlocks, THREADS_PER_BLOCK);
#endif
TreePiecePartListDataTransferBasic(data, gravityKernel);
gravityKernel->setDeviceToHostCallback(data->cb);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("partGravityLocal");
#endif
gravityKernel->setRunKernel(run_TP_PART_GRAVITY_LOCAL);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER LOCAL LARGEPHASE PART\n", CmiMyPe());
#endif
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = data->tpIndex;
gravityKernel->comp_type = TP_PART_GRAVITY_LOCAL;
gravityKernel->comp_phase = data->phase;
#endif
hapiEnqueue(gravityKernel);
}
void TreePiecePartListDataTransferRemote(CudaRequest *data){
int numBlocks = data->numBucketsPlusOne-1;
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
#ifdef CUDA_2D_TB_KERNEL
gravityKernel->setExecParams(numBlocks, dim3(NODES_PER_BLOCK_PART, PARTS_PER_BLOCK_PART));
#else
gravityKernel->setExecParams(numBlocks, THREADS_PER_BLOCK);
#endif
TreePiecePartListDataTransferBasic(data, gravityKernel);
gravityKernel->setDeviceToHostCallback(data->cb);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("partGravityRemote");
#endif
gravityKernel->setRunKernel(run_TP_PART_GRAVITY_REMOTE);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER REMOTE PART\n", CmiMyPe());
#endif
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = data->tpIndex;
gravityKernel->comp_type = TP_PART_GRAVITY_REMOTE;
gravityKernel->comp_phase = data->phase;
#endif
hapiEnqueue(gravityKernel);
}
void TreePiecePartListDataTransferRemoteResume(CudaRequest *data){
int numBlocks = data->numBucketsPlusOne-1;
bool transfer;
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
#ifdef CUDA_2D_TB_KERNEL
gravityKernel->setExecParams(numBlocks, dim3(NODES_PER_BLOCK_PART, PARTS_PER_BLOCK_PART));
#else
gravityKernel->setExecParams(numBlocks, THREADS_PER_BLOCK);
#endif
TreePiecePartListDataTransferBasic(data, gravityKernel);
transfer = gravityKernel->buffers[ILPART_IDX].transfer_to_device;
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER REMOTE RESUME PART (%d)\n",
CmiMyPe(),
transfer
);
#endif
gravityKernel->addBuffer(data->missedParts, data->sMissed, transfer,
false, transfer);
gravityKernel->setDeviceToHostCallback(data->cb);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("partGravityRemote");
#endif
gravityKernel->setRunKernel(run_TP_PART_GRAVITY_REMOTE_RESUME);
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = data->tpIndex;
gravityKernel->comp_type = TP_PART_GRAVITY_REMOTE_RESUME;
gravityKernel->comp_phase = data->phase;
#endif
hapiEnqueue(gravityKernel);
}
void TreePiecePartListDataTransferBasic(CudaRequest *data, hapiWorkRequest *gravityKernel){
int numInteractions = data->numInteractions;
int numBucketsPlusOne = data->numBucketsPlusOne;
int numBuckets = numBucketsPlusOne-1;
size_t size;
bool transfer;
size = (numInteractions) * sizeof(ILCell);
transfer = size > 0;
gravityKernel->addBuffer(data->list, size, transfer, false, transfer);
size = (numBucketsPlusOne) * sizeof(int);
gravityKernel->addBuffer(data->bucketMarkers, (transfer ? size : 0), transfer, false, transfer);
size = (numBuckets) * sizeof(int);
gravityKernel->addBuffer(data->bucketStarts, size, transfer, false, transfer);
gravityKernel->addBuffer(data->bucketSizes, size, transfer, false, transfer);
ParameterStruct *ptr = (ParameterStruct *)malloc(sizeof(ParameterStruct));
ptr->numInteractions = data->numInteractions;
ptr->numBucketsPlusOne = numBucketsPlusOne;
ptr->fperiod = data->fperiod;
gravityKernel->setUserData(ptr, true);
#ifdef CUDA_VERBOSE_KERNEL_ENQUEUE
printf("(%d) TRANSFER BASIC PART parts %zu (%d) bucket_markers %zu (%d) bucket_starts %zu (%d) bucket_sizes %zu (%d)\n",
CmiMyPe(),
gravityKernel->buffers[ILPART_IDX].size,
gravityKernel->buffers[ILPART_IDX].transfer_to_device,
gravityKernel->buffers[PART_BUCKET_MARKERS_IDX].size,
gravityKernel->buffers[PART_BUCKET_MARKERS_IDX].transfer_to_device,
gravityKernel->buffers[PART_BUCKET_START_MARKERS_IDX].size,
gravityKernel->buffers[PART_BUCKET_START_MARKERS_IDX].transfer_to_device,
gravityKernel->buffers[PART_BUCKET_SIZES_IDX].size,
gravityKernel->buffers[PART_BUCKET_SIZES_IDX].transfer_to_device
);
#endif
}
/* kernels:
TP_GRAVITY_LOCAL,
TP_GRAVITY_REMOTE,
TP_GRAVITY_REMOTE_RESUME,
TP_PART_GRAVITY_LOCAL,
TP_PART_GRAVITY_REMOTE,
TP_PART_GRAVITY_REMOTE_RESUME
*/
#ifdef HAPI_INSTRUMENT_WRS
void FreeDataManagerLocalTreeMemory(bool freemom, bool freepart, int index, char phase){
#else
void FreeDataManagerLocalTreeMemory(bool freemom, bool freepart){
#endif
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
gravityKernel->addBuffer(NULL, 0, false, false, freemom, LOCAL_MOMENTS);
gravityKernel->addBuffer(NULL, 0, false, false, freepart, LOCAL_PARTICLE_CORES);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("freeLocal");
#endif
gravityKernel->setRunKernel(run_DM_TRANSFER_FREE_LOCAL);
//printf("DM TRANSFER FREE LOCAL\n");
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = index;
gravityKernel->comp_type = DM_TRANSFER_FREE_LOCAL;
gravityKernel->comp_phase = phase;
#endif
hapiEnqueue(gravityKernel);
}
// this function begins the transfer of the next
// pending chunk on dm, once we are assured that
// the previous chunk's allocated memory has been
// freed
void initiateNextChunkTransfer(void *dm);
void run_DM_TRANSFER_FREE_REMOTE_CHUNK(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("DM_TRANSFER_FREE_REMOTE_CHUNK KERNELSELECT\n");
#endif
initiateNextChunkTransfer(wr->getUserData());
}
#ifdef HAPI_INSTRUMENT_WRS
void FreeDataManagerRemoteChunkMemory(int chunk, void *dm, bool freemom, bool freepart, int index, char phase){
#else
void FreeDataManagerRemoteChunkMemory(int chunk, void *dm, bool freemom, bool freepart){
#endif
hapiWorkRequest* gravityKernel = hapiCreateWorkRequest();
gravityKernel->addBuffer(NULL, 0, false, false, freemom, REMOTE_MOMENTS);
gravityKernel->addBuffer(NULL, 0, false, false, freepart, REMOTE_PARTICLE_CORES);
#ifdef HAPI_TRACE
gravityKernel->setTraceName("freeRemote");
#endif
gravityKernel->setRunKernel(run_DM_TRANSFER_FREE_REMOTE_CHUNK);
// save a pointer to the data manager so that
// the next chunk's transfer can be initiated once
// the memory for this chunk has been freed
gravityKernel->setUserData(dm);
//printf("DM TRANSFER FREE REMOTE CHUNK\n");
#ifdef HAPI_INSTRUMENT_WRS
gravityKernel->chare_index = index;
gravityKernel->comp_type = DM_TRANSFER_FREE_REMOTE_CHUNK;
gravityKernel->comp_phase = phase;
#endif
hapiEnqueue(gravityKernel);
}
void run_DM_TRANSFER_BACK(hapiWorkRequest *wr, cudaStream_t kernel_stream,void** devBuffers) {
#ifdef CUDA_NOTIFY_DATA_TRANSFER_DONE
printf("DM_TRANSFER_BACK: 0x%x KERNELSELECT\n", devBuffers[LOCAL_PARTICLE_VARS]);
#endif
}
/* Schedule the transfer of the accelerations back from the GPU to the host.
* This also schedules the freeing of the device buffers used for the
* force calculation.
*/
#ifdef HAPI_INSTRUMENT_WRS
void TransferParticleVarsBack(VariablePartData *hostBuffer, size_t size, void *cb,
bool freemom, bool freepart, bool freeRemoteMom, bool freeRemotePart,
int index, char phase){