Skip to content

Commit

Permalink
Opt signal handling, LambdaGPUTask (#9)
Browse files Browse the repository at this point in the history
* Optional signal handling

* The next level GPU tasks with lambda functions!

* GPU calculations take a parameter
  • Loading branch information
tiermak authored May 28, 2019
1 parent 0ee2091 commit 07d25a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Werror cross-execution-space-call,reo

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-O2 -Wall -Wextra -Wshadow -Wpedantic -Wnon-virtual-dtor -Wunused -Wdouble-promotion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -rdynamic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")


Expand Down
20 changes: 19 additions & 1 deletion include/cuq.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mutex>
#include <queue>
#include <functional>

#pragma once

Expand All @@ -9,6 +10,23 @@ class GPUTask {
virtual ~GPUTask();
};

template <class T>
class LambdaGPUTask : public GPUTask {
public:
LambdaGPUTask(T _params, std::function<void(T)> _gpuCalculations) {
params = _params;
gpuCalculations = _gpuCalculations;
}

void doWork() {
gpuCalculations(params);
}

private:
T params;
std::function<void(T)> gpuCalculations;
};

class GPUTasksQueue {
public:
bool resetDeviceAfterFinish;
Expand All @@ -27,7 +45,7 @@ extern "C"
void processTasks(
GPUTask ** tasks, int taskCount,
int requestedDevicesCount,
bool resetDeviceAfterFinish = false, bool deleteTasksAutomatically = true);
bool resetDeviceAfterFinish = false, bool deleteTasksAutomatically = true, bool handleSignals = true);

extern "C"
int occupyDevices(int requestedDevicesCount, int * occupiedDevicesIdxs, char * errorMsg);
Expand Down
5 changes: 3 additions & 2 deletions src/cuq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ extern "C"
void processTasks(
GPUTask ** tasks, int taskCount,
int requestedDevicesCount,
bool resetDeviceAfterFinish, bool deleteTasksAutomatically) {
bool resetDeviceAfterFinish, bool deleteTasksAutomatically, bool handleSignals) {

signal(SIGSEGV, signalHandler);
if (handleSignals)
signal(SIGSEGV, signalHandler);

char errorMsg[1000];
int devices[128];
Expand Down

0 comments on commit 07d25a8

Please sign in to comment.