Skip to content

Commit 995fb40

Browse files
authored
Very useful function to calculate sizes of a data chunks (#10)
1 parent 07d25a8 commit 995fb40

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/cuq.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,28 @@ class LambdaGPUTask : public GPUTask {
2121
void doWork() {
2222
gpuCalculations(params);
2323
}
24+
25+
int calculationsCount(int localI, int groupSize, int wholeSize) {
26+
int startingIndex = localI * groupSize;
27+
28+
if (startingIndex < wholeSize - groupSize) //we are not close to an end of our data
29+
return groupSize;
30+
31+
int rest = wholeSize - startingIndex;
32+
33+
if (rest >= 0) //the last chunk of the data
34+
return rest;
35+
36+
return 0; //the data ended, nothing more to process
37+
}
2438

2539
private:
2640
T params;
2741
std::function<void(T)> gpuCalculations;
2842
};
2943

44+
int calculationsCount(int localI, int groupSize, int wholeSize);
45+
3046
class GPUTasksQueue {
3147
public:
3248
bool resetDeviceAfterFinish;

src/cuq.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
using namespace std;
1010

11+
int calculationsCount(int localI, int groupSize, int wholeSize) {
12+
int startingIndex = localI * groupSize;
13+
14+
if (startingIndex < wholeSize - groupSize) //we are not close to an end of our data
15+
return groupSize;
16+
17+
int rest = wholeSize - startingIndex;
18+
19+
if (rest >= 0) //the last chunk of the data
20+
return rest;
21+
22+
return 0; //the data ended, nothing more to process
23+
}
24+
1125
GPUTask::~GPUTask() {
1226
}
1327

0 commit comments

Comments
 (0)