-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated the Fibonacci device example to be roughly correct :)
- Loading branch information
Showing
4 changed files
with
46 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,15 @@ | ||
#include "cuda_kernel.h" | ||
#include "fibonacci_cuda_kernel.h" | ||
|
||
#ifdef TTG_HAVE_CUDA | ||
|
||
__global__ void cu_calculate_fibonacci(int64_t* results, std::size_t n) { | ||
int tx = threadIdx.x; // Thread index | ||
|
||
if (tx == 0) { | ||
int64_t a = 0, b = 1, c; | ||
if (n == 0) { | ||
results[tx] = a; | ||
return; | ||
} | ||
for (int i = 2; i <= n; i++) { | ||
c = a + b; | ||
a = b; | ||
b = c; | ||
} | ||
results[tx] = b; | ||
} | ||
__global__ void cu_next_value(int64_t* fn_and_fnm1) { | ||
int64_t fnp1 = fn_and_fnm1[0] + fn_and_fnm1[1]; | ||
fn_and_fnm1[1] = fn_and_fnm1[0]; | ||
fn_and_fnm1[0] = fnp1; | ||
} | ||
|
||
void calculate_fibonacci(int64_t* results, std::size_t n) { | ||
cu_calculate_fibonacci<<<1, 1>>>(results, n); // Adjust <<<1, 1>>> as needed for parallel computation | ||
void next_value(int64_t* fn_and_fnm1) { | ||
cu_next_value<<<1, 1>>>(fn_and_fnm1); | ||
} | ||
|
||
#endif // TTG_HAVE_CUDA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "ttg/config.h" | ||
#include <cinttypes> | ||
|
||
void calculate_fibonacci(int64_t* result, std::size_t n); | ||
void next_value(int64_t* fn_and_fnm1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters