Skip to content

Commit

Permalink
Basic cuda support
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Dec 18, 2023
1 parent cb5fd01 commit 0f46089
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 20 deletions.
1 change: 1 addition & 0 deletions LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Creole (creole)
Crystal (cr)
CSS (css)
CSV (csv)
Cuda (cu)
Cython (pyx,pxi,pxd)
D (d)
Dart (dart)
Expand Down
45 changes: 27 additions & 18 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<th>465</th>
<th>7810</th>
<th>1593</th>
<th>397344</th>
<th>397927</th>
</tr><tr>
<th>Java</th>
<th>24</th>
Expand All @@ -39,12 +39,12 @@
</tr><tr>
<th>Markdown</th>
<th>11</th>
<th>1473</th>
<th>1474</th>
<th>356</th>
<th>0</th>
<th>1117</th>
<th>1118</th>
<th>0</th>
<th>59762</th>
<th>59772</th>
</tr><tr>
<th>Python</th>
<th>11</th>
Expand Down Expand Up @@ -107,7 +107,7 @@
<th>92</th>
<th>928</th>
<th>106</th>
<th>41842</th>
<th>41850</th>
</tr><tr>
<th>C#</th>
<th>2</th>
Expand Down Expand Up @@ -297,6 +297,15 @@
<th>141</th>
<th>5</th>
<th>4287</th>
</tr><tr>
<th>Cuda</th>
<th>1</th>
<th>43</th>
<th>8</th>
<th>7</th>
<th>28</th>
<th>3</th>
<th>927</th>
</tr><tr>
<th>DM</th>
<th>1</th>
Expand Down Expand Up @@ -444,12 +453,12 @@
</tr><tr>
<th>HTML</th>
<th>1</th>
<th>770</th>
<th>743</th>
<th>0</th>
<th>0</th>
<th>770</th>
<th>743</th>
<th>0</th>
<th>11257</th>
<th>10774</th>
</tr><tr>
<th>Hare</th>
<th>1</th>
Expand All @@ -471,12 +480,12 @@
</tr><tr>
<th>JSON</th>
<th>1</th>
<th>8686</th>
<th>8719</th>
<th>8</th>
<th>0</th>
<th>8678</th>
<th>8711</th>
<th>0</th>
<th>121714</th>
<th>122146</th>
</tr><tr>
<th>Korn Shell</th>
<th>1</th>
Expand Down Expand Up @@ -732,12 +741,12 @@
</tr></tbody>
<tfoot><tr>
<th>Total</th>
<th>200</th>
<th>31912</th>
<th>3551</th>
<th>2032</th>
<th>26329</th>
<th>2787</th>
<th>1961983</th>
<th>201</th>
<th>31962</th>
<th>3559</th>
<th>2039</th>
<th>26364</th>
<th>2790</th>
<th>1963460</th>
</tr></tfoot>
</table></body></html>
43 changes: 43 additions & 0 deletions examples/language/cuda.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <math.h>
// Kernel function to add the elements of two arrays
__global__
void add(int n, float *x, float *y)
{
for (int i = 0; i < n; i++)
y[i] = x[i] + y[i];
}

int main(void)
{
int N = 1<<20;
float *x, *y;

// Allocate Unified Memory – accessible from CPU or GPU
cudaMallocManaged(&x, N*sizeof(float));
cudaMallocManaged(&y, N*sizeof(float));

// initialize x and y arrays on the host
for (int i = 0; i < N; i++) {
x[i] = 1.0f;
y[i] = 2.0f;
}

// Run kernel on 1M elements on the GPU
add<<<1, 1>>>(N, x, y);

// Wait for GPU to finish before accessing on host
cudaDeviceSynchronize();

// Check for errors (all values should be 3.0f)
float maxError = 0.0f;
for (int i = 0; i < N; i++)
maxError = fmax(maxError, fabs(y[i]-3.0f));
std::cout << "Max error: " << maxError << std::endl;

// Free memory
cudaFree(x);
cudaFree(y);

return 0;
}
33 changes: 33 additions & 0 deletions languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,39 @@
}
]
},
"Cuda": {
"complexitychecks": [
"for ",
"for(",
"if ",
"if(",
"switch ",
"while ",
"else ",
"|| ",
"&& ",
"!= ",
"== "
],
"extensions": [
"cu"
],
"line_comment": [
"//"
],
"multi_line": [
[
"/*",
"*/"
]
],
"quotes": [
{
"end": "\"",
"start": "\""
}
]
},
"CMake": {
"complexitychecks": [
"for ",
Expand Down
2 changes: 1 addition & 1 deletion processor/constants.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ else
fi

# Try out specific languages
for i in 'Bosque ' 'Flow9 ' 'Bitbucket Pipeline ' 'Docker ignore ' 'Q# ' 'Futhark ' 'Alloy ' 'Wren ' 'Monkey C ' 'Alchemist ' 'Luna ' 'ignore ' 'XML Schema ' 'Web Services' 'Go ' 'Java ' 'Boo ' 'License ' 'BASH ' 'C Shell ' 'Korn Shell ' 'Makefile ' 'Shell ' 'Zsh ' 'Rakefile ' 'Gemfile ' 'Dockerfile ' 'Yarn ' 'Sieve ' 'F# ' 'Elm ' 'Terraform ' 'Clojure ' 'C# ' 'LLVM IR ' 'HAML ' 'FXML ' 'DM ' 'Nushell ' 'Racket ' 'DOT ' 'YAML ' 'Teal ' 'FSL ' 'INI ' 'Hare ' 'Templ '
for i in 'Bosque ' 'Flow9 ' 'Bitbucket Pipeline ' 'Docker ignore ' 'Q# ' 'Futhark ' 'Alloy ' 'Wren ' 'Monkey C ' 'Alchemist ' 'Luna ' 'ignore ' 'XML Schema ' 'Web Services' 'Go ' 'Java ' 'Boo ' 'License ' 'BASH ' 'C Shell ' 'Korn Shell ' 'Makefile ' 'Shell ' 'Zsh ' 'Rakefile ' 'Gemfile ' 'Dockerfile ' 'Yarn ' 'Sieve ' 'F# ' 'Elm ' 'Terraform ' 'Clojure ' 'C# ' 'LLVM IR ' 'HAML ' 'FXML ' 'DM ' 'Nushell ' 'Racket ' 'DOT ' 'YAML ' 'Teal ' 'FSL ' 'INI ' 'Hare ' 'Templ ' 'Cuda '
do
if ./scc "examples/language/" | grep -q "$i "; then
echo -e "${GREEN}PASSED $i Language Check"
Expand Down

0 comments on commit 0f46089

Please sign in to comment.