-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.jmd
59 lines (40 loc) · 1.24 KB
/
README.jmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
## CuCountmap
`cucountmap` is a faster `countmap` equivalent utilizing CUDA.jl for `Vector{T}` where `isbits(T)` and `sizeof(T) <= 2`.
### Usage
```julia
using CuCountMap
v = rand(Int16, 1_000_000)
cucountmap(v) # converts v to cu(v) and then run countmap
using CUDA: cu
cuv = cu(v)
countmap(cuv) # StatsBase.countmap is overloaded for CuArrays
```
### Example & Benchmarks
```julia
using CUDA
using CuCountMap
using StatsBase: countmap
v = rand(Int16, 10_000_000);
using BenchmarkTools
cpu_to_gpu_benchmark = @benchmark gpu_countmap = cucountmap($v)
```
```julia
cpu_to_cpu_benchmark = @benchmark cpu_countmap = countmap($v)
```
```julia
cuv = CUDA.cu(v)
gpu_to_gpu_benchmark = @benchmark gpu_countmap2 = countmap(cuv)
```
#### Benchmark Plot
```julia
using Plots
using Statistics: mean
cpu_to_gpu = mean(cpu_to_gpu_benchmark.times)/1000/1000
gpu_to_gpu = mean(gpu_to_gpu_benchmark.times)/1000/1000
cpu_to_cpu = mean(cpu_to_cpu_benchmark.times)/1000/1000
plot(
["CPU Array on CPU \n countmap(v)", "convert CPU Array to GPU array on GPU \n cucountmap(cu(v))", "GPU array on GPU \n cucountmap(cuv)"],
[cpu_to_cpu, cpu_to_gpu, gpu_to_gpu],
seriestypes = :bar, title="CuCountMap.cucountmap vs StatsBase.countmap", label="ms",
legendtitle="Mean time")
```