This file contains hidden or 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
## main.nim - uses a loop and a split | |
import strutils | |
let inFile = open("input.txt", fmRead) | |
let outFile = open("output.txt", fmWrite) | |
var ln: TaintedString = "" | |
var parts: seq[string] | |
while inFile.readLine(ln): |
This file contains hidden or 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
## From https://forum.nim-lang.org/t/2856 | |
import macros | |
macro chaining(code: untyped): untyped = | |
const chainIdent = "chain" | |
const combineIdent = "combine" | |
proc inspect(depth: int, n: NimNode): NimNode = | |
case(n.kind) | |
of nnkIdent, nnkStrLit: |
This file contains hidden or 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
proc filter[T](it: (iterator : T), f: proc(x: T): bool): (iterator: T) = | |
return iterator(): T = | |
while (let x = it(); not finished(it)): | |
if f(x): | |
yield x |
This file contains hidden or 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
git rev-list --objects --all \ | |
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \ | |
| awk '/^blob/ {print substr($0,6)}' \ | |
| sort --numeric-sort --key=2 \ | |
| cut --complement --characters=13-40 \ | |
| numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest |
This file contains hidden or 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
#!/usr/bin/env bash | |
# Colours picked from https://robinpowered.com/blog/best-practice-system-for-organizing-and-tagging-github-issues/ | |
### | |
# Label definitions | |
### | |
declare -A LABELS | |
# Platform |
This file contains hidden or 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
import nimcuda/[cuda_runtime_api, driver_types, nimcuda] | |
import sequtils, future | |
type GpuArray[T: SomeReal] = object | |
data: ref[ptr T] | |
len: int | |
{.compile: "./square.cu".} | |
proc cuda_square(bpg, tpb: cint, y: ptr cfloat, x: ptr cfloat) {.importc, header:"../square.cuh".} | |
#../square.cuh is a workaround because header is not copied to nimcache |
This file contains hidden or 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
__global__ | |
void GPUCode( int* input, int* output, int length) | |
{ | |
int idx = __umul24( blockDim.x, blockIdx.x) + threadIdx.x; | |
if ( idx < length ) | |
{ | |
output[ idx ] = input[ idx ] + 2 * input[ idx + 1 ]; | |
} | |
} |
This file contains hidden or 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
__global__ | |
void saxpy(int n, float a, float *x, float *y) | |
{ | |
for (int i = blockIdx.x * blockDim.x + threadIdx.x; | |
i < n; | |
i += blockDim.x * gridDim.x) | |
{ | |
y[i] = a * x[i] + y[i]; | |
} | |
} |
This file contains hidden or 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
## Even easier, without the cu / cuh | |
## Note VScode properly syntax highlight the emit part, yeah! | |
import nimcuda/[cuda_runtime_api, driver_types, nimcuda] | |
import sequtils, future | |
type GpuArray[T: SomeReal] = object | |
data: ref[ptr T] | |
len: int |
This file contains hidden or 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
// Note: this doesn't work (yet) | |
// Example program | |
#include <iostream> | |
#include <string> | |
int cuda_getIndexOfElementID( | |
const int rank, | |
const int * __restrict__ shape, | |
const int * __restrict__ strides, |