A library and framework for developing CPU-CUDA compatible applications under one unified code.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#define CUDATOOLS_IMPLEMENTATION
|
|
|
|
#include <Core.h>
|
|
|
|
|
|
|
|
class intPair {
|
|
|
|
DEVICE_COPY(intPair)
|
|
|
|
public:
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
intPair(const int x_, const int y_) : x(x_), y(y_) {
|
|
|
|
allocateDevice(); // Allocates memory for this intPair on the device.
|
|
|
|
updateDevice()
|
|
|
|
.wait(); // Copies the memory on the host to the device and waits until finished.
|
|
|
|
};
|
|
|
|
|
|
|
|
HD void swap() {
|
|
|
|
int swap = x;
|
|
|
|
x = y;
|
|
|
|
y = swap;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
KERNEL(swap, intPair* const pair) { pair->swap(); }
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
intPair pair(1, 2);
|
|
|
|
printf("Before: %u, %u\n", pair.x, pair.y); // Prints 1, 2.
|
|
|
|
|
|
|
|
CudaTools::Kernel::launch(swap, CudaTools::Kernel::basic(1), pair.that()).wait();
|
|
|
|
pair.updateHost()
|
|
|
|
.wait(); // Copies the memory from the device back to the host and waits until finished.
|
|
|
|
|
|
|
|
printf("After: %u, %u\n", pair.x, pair.y); // Prints 2, 1.
|
|
|
|
return 0;
|
|
|
|
}
|