Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyler-hilbert/cuda-kmeans
Performance test for K-Means written from scratch in CUDA
https://github.com/tyler-hilbert/cuda-kmeans
cuda kmeans-clustering machine-learning nsight
Last synced: 16 days ago
JSON representation
Performance test for K-Means written from scratch in CUDA
- Host: GitHub
- URL: https://github.com/tyler-hilbert/cuda-kmeans
- Owner: Tyler-Hilbert
- Created: 2024-08-07T21:28:30.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-14T00:45:22.000Z (about 2 months ago)
- Last Synced: 2024-09-15T02:17:34.994Z (about 2 months ago)
- Topics: cuda, kmeans-clustering, machine-learning, nsight
- Language: C++
- Homepage:
- Size: 314 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# K-Means implemented from scratch using CUDA
## Usage
```C++
KMeans_CUDA model (data, N, D, K); // Where data is AoS, N is number of data points, D is number of dimensions and K is number of clusters
model.one_epoch(); // Trains one epoch
model.print_predictions(); // Prints the classifications. Can be commented out.
// printf ("Error: %f\n", model.compute_error()); // Uncomment to print error
```## Kernels
```C++
// Updates each centroid using d_sum and d_count
// where the index is d * centroid number (out of k).
// d: number of dimensions
// k: number of clusters
__global__ void update_centroids(
float *d_centroids,
const float *d_sum,
const int *d_count,
int d,
int k
);
``````C++
// Computes the sum (d_sum) and count (d_count)
// for each of the k clusters labeled in d_centroids.
// n: number of data points
// d: number of dimensions
// k: number of clusters
// Uses shared memory of 3*k*d
__global__ void sum_and_count(
const float *d_data,
const float *d_centroids,
float *d_sum,
int *d_count,
int n,
int d,
int k
);
``````C++
// Computes error and updates d_error
// n: number of data points
// d: number of dimensions
// k: number of clusters
__global__ void calculate_error(
const float *d_data,
const float *d_centroids,
float *d_error,
int n,
int d,
int k
) {
```## Performance
Go to: https://github.com/Tyler-Hilbert/CUDA-KMeans/tree/52db75728794449dc152989c648e03b632d24c08 for most recent performance tests.## Performance compared to scikit-learn and ArrayFire
It is shown that this implementations of K-Means outperforms scitkit-learn and ArrayFire on a T4.
![CUDA KMeans Performance vs scikit-learn and ArrayFire](https://raw.githubusercontent.com/Tyler-Hilbert/CUDA-KMeans/main/Performance/Comparison.png)## Usage Continued
To compile the test program:
$git clone https://github.com/Tyler-Hilbert/CUDA-KMeans.git
$cd CUDA-KMeans
$nvcc main.cpp KMeans_CUDA.cu -o kmeans
$./kmeans