-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update examples + readme for nim 2.1.9
- Loading branch information
Showing
10 changed files
with
62 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ nimcache | |
*.ilk | ||
*.out | ||
.* | ||
|
||
!.vscode |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"nimlang.nimlang" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "nim: debug current file", | ||
"preLaunchTask": "nim: build current file (for debugging)", | ||
"program": "${workspaceFolder}/bin/${fileBasenameNoExtension}", | ||
"args": [], | ||
"cwd": "${workspaceFolder}", | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.associations": { | ||
"version": "cpp" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "nim: build current file (for debugging)", | ||
"command": "nim", | ||
"args": [ | ||
"cpp", | ||
"-g", | ||
"--define:HippoRuntime=HIP_CPU", | ||
"--debugger:native", | ||
"-o:${workspaceRoot}/bin/${fileBasenameNoExtension}", | ||
"${relativeFile}" | ||
], | ||
"options": { | ||
"cwd": "${workspaceRoot}" | ||
}, | ||
"type": "shell", | ||
} | ||
] | ||
} |
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,7 +1,2 @@ | ||
--path:"../src" | ||
|
||
--cc:clang | ||
--clang.cpp.exe:hipcc | ||
--clang.cpp.linkerexe:hipcc | ||
--passC: "--offload-arch=gfx1100" | ||
--passC: "--offload-arch=gfx1102" | ||
--cc:hipcc |
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,7 +1,2 @@ | ||
--path:"../src" | ||
|
||
--cc:clang | ||
--clang.cpp.exe:hipcc | ||
--clang.cpp.linkerexe:hipcc | ||
--passC: "--offload-arch=gfx1100" | ||
--passC: "--offload-arch=gfx1102" | ||
--cc:hipcc |
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,32 +1,12 @@ | ||
# nim cpp --cc:nvcc --define:"useMalloc" hello_kernel.nim | ||
# minimal cuda example for nim without using hippo | ||
{.emit: """ | ||
__global__ void add(int a, int b, int *c) { | ||
*c = a + b; | ||
__global__ void add(int a, int b) { | ||
int c; | ||
c = a + b; | ||
} | ||
""".} | ||
|
||
type | ||
cudaMemcpyKind* {.size: sizeof(cint), importcpp: "cudaMemcpyKind".} = enum | ||
cudaMemcpyHostToHost = 0, ## < Host-to-Host Copy | ||
cudaMemcpyHostToDevice = 1, ## < Host-to-Device Copy | ||
cudaMemcpyDeviceToHost = 2, ## < Device-to-Host Copy | ||
cudaMemcpyDeviceToDevice = 3, ## < Device-to-Device Copy | ||
cudaMemcpyDefault = 4 ## < Runtime will automatically determine copy-kind based on virtual addresses. | ||
|
||
proc cudaMalloc*(`ptr`: ptr pointer; size: cint): cint {.importcpp: "cudaMalloc(@)".} | ||
proc cudaMemcpy*(dst: pointer; src: pointer; size: cint; kind: cudaMemcpyKind): cint {.importcpp: "cudaMemcpy(@)".} | ||
proc cudaFree*(`ptr`: pointer): cint {.importcpp: "cudaFree(@)".} | ||
|
||
proc main() = | ||
var c: int32 | ||
var dev_c: ptr[int32] | ||
discard cudaMalloc(cast[ptr pointer](addr dev_c), sizeof(int32).cint) | ||
{.emit: """ | ||
add<<<1,1>>>(2,7,dev_c); | ||
""".} | ||
discard cudaMemcpy(addr c, dev_c, sizeof(int32).cint, cudaMemcpyDeviceToHost) | ||
echo "2 + 7 = ", c | ||
discard cudaFree(dev_c) | ||
|
||
when isMainModule: | ||
main() | ||
{.emit: """ | ||
add<<<1,1>>>(2,7); | ||
""".} |