https://github.com/xiaodaigh/cucountmap.jl
Fast `StatsBase.countmap` for small types on the GPU via CUDA.jl
https://github.com/xiaodaigh/cucountmap.jl
Last synced: 2 months ago
JSON representation
Fast `StatsBase.countmap` for small types on the GPU via CUDA.jl
- Host: GitHub
- URL: https://github.com/xiaodaigh/cucountmap.jl
- Owner: xiaodaigh
- License: mit
- Created: 2020-06-17T04:21:58.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-13T14:25:46.000Z (almost 4 years ago)
- Last Synced: 2025-01-20T11:12:05.822Z (4 months ago)
- Language: Julia
- Homepage:
- Size: 73.2 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.jmd
- License: LICENSE
Awesome Lists containing this project
README
## CuCountmap
`cucountmap` is a faster `countmap` equivalent utilizing CUDA.jl for `Vector{T}` where `isbits(T)` and `sizeof(T) <= 2`.
### Usage
```julia
using CuCountMapv = 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: countmapv = 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: meancpu_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/1000plot(
["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")
```