-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcsBigBlockInitializationForPositions.cu
61 lines (48 loc) · 1.88 KB
/
lcsBigBlockInitializationForPositions.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
/******************************************************************
File : lcsBigBlockInitializationForPositions.cu
Author : Mingcheng Chen
Last Update : January 31st, 2013
*******************************************************************/
#include <stdio.h>
#define BLOCK_SIZE 512
__global__ void BigBlockInitializationForPositionsKernel(double *globalVertexPositions,
int *blockedGlobalPointIDs,
int *startOffsetInPoint,
double *vertexPositionsForBig
) {
// Get number of threads in a work group
int numOfThreads = blockDim.x;
// Get local thread ID
int localID = threadIdx.x;
// Get interesting block ID of the current big block
int interestingBlockID = blockIdx.x;
// Declare some work arrays
double *gVertexPositions;
int startPoint = startOffsetInPoint[interestingBlockID];
int numOfPoints = startOffsetInPoint[interestingBlockID + 1] - startPoint;
// Initialize vertexPositions
gVertexPositions = vertexPositionsForBig + startPoint * 3;
for (int i = localID; i < numOfPoints * 3; i += numOfThreads) {
int localPointID = i / 3;
int dimensionID = i % 3;
int globalPointID = blockedGlobalPointIDs[startPoint + localPointID];
gVertexPositions[i] = globalVertexPositions[globalPointID * 3 + dimensionID];
}
}
extern "C"
void BigBlockInitializationForPositions(double *globalVertexPositions,
int *blockedGlobalPointIDs,
int *startOffsetInPoint,
double *vertexPositionsForBig,
int numOfInterestingBlocks
) {
dim3 dimBlock(BLOCK_SIZE, 1, 1);
dim3 dimGrid(numOfInterestingBlocks, 1, 1);
BigBlockInitializationForPositionsKernel<<<dimGrid, dimBlock>>>(globalVertexPositions, blockedGlobalPointIDs,
startOffsetInPoint, vertexPositionsForBig);
cudaError_t err = cudaDeviceSynchronize();
if (err) {
cudaGetErrorString(err);
exit(0);
}
}