Coder Social home page Coder Social logo

cudaf / histogram Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 34 KB

Histogram represents a count of the frequency of each element in a data set.

Home Page: https://www.kaggle.com/wolfram77/cudaf-histogram

License: MIT License

Cuda 6.00% Python 0.59% Shell 0.42% C++ 93.00%
cuda gpu byte histogram events atomics shared memory cpp

histogram's Introduction

Histogram represents a count of the frequency of each element in a data set.

Each thread computes pairwise product of multiple components of vector.
Since there are 10 components, but only a maximum of 4 total threads,
each thread pairwise product of its component, and shifts by a stride
of the total number of threads. This is done as long as it does not
exceed the length of the vector. Each thread maintains the sum of the
pairwise products it calculates.

kernel():
1. Get byte at buffer for this thread.
2. Atomically increment appropriate index in histogram.
3. Shift to the next byte, by a stride.
Each thread atomically increments the bytes in buffer meant for it.
This is done in the shared thread block memory first, until the
buffer is consumed. Then each thread in the block updates the
histogram in the global memory atomically. This reduces global
memory contention.

kernelShared():
1. Initialize shared memory (of size 256).
2. Get byte at buffer for this thread.
3. Atomically increment appropriate index in shared memory.
4. Shift to the next byte, by a stride.
5. Wait for all threads within the block to finish.
5. Reduce the sum in the cache to a single value in binary tree fashion.
6. Atomically update per-block histogram into global histogram.
$ nvcc -std=c++17 -Xcompiler -O3 main.cu
$ ./a.out

# CPU Histogram ...
# CPU execution time: 0.0 ms
# CPU Histogram sum: 1000000
#
# GPU Histogram: atomic ...
# GPU execution time: 1.1 ms
# GPU Histogram sum: 1000000
# GPU Histogram verified.
#
# GPU Histogram: shared + atomic ...
# GPU execution time: 0.5 ms
# GPU Histogram sum: 1000000
# GPU Histogram verified.

See main.cu for code.



References

histogram's People

Contributors

wolfram77 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.