#define CUDATOOLS_IMPLEMENTATION #include class intPair { DEVICE_CLASS(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; }