{"id":17632697,"url":"https://github.com/tyler-hilbert/cuda-kmeans","last_synced_at":"2025-03-30T03:32:12.275Z","repository":{"id":252144098,"uuid":"839557923","full_name":"Tyler-Hilbert/CUDA-KMeans","owner":"Tyler-Hilbert","description":"K-Means in CUDA","archived":false,"fork":false,"pushed_at":"2025-02-09T23:15:16.000Z","size":362,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T03:31:46.750Z","etag":null,"topics":["cuda","kmeans-clustering","machine-learning","nsight"],"latest_commit_sha":null,"homepage":"","language":"Cuda","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tyler-Hilbert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-07T21:28:30.000Z","updated_at":"2025-03-27T21:45:08.000Z","dependencies_parsed_at":"2025-02-09T23:21:52.798Z","dependency_job_id":"65e12731-5835-4227-ba06-bffd7705d128","html_url":"https://github.com/Tyler-Hilbert/CUDA-KMeans","commit_stats":null,"previous_names":["tyler-hilbert/cuda-kmeans"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyler-Hilbert%2FCUDA-KMeans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyler-Hilbert%2FCUDA-KMeans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyler-Hilbert%2FCUDA-KMeans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tyler-Hilbert%2FCUDA-KMeans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tyler-Hilbert","download_url":"https://codeload.github.com/Tyler-Hilbert/CUDA-KMeans/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246273533,"owners_count":20750904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","kmeans-clustering","machine-learning","nsight"],"created_at":"2024-10-23T01:45:10.265Z","updated_at":"2025-03-30T03:32:12.252Z","avatar_url":"https://github.com/Tyler-Hilbert.png","language":"Cuda","funding_links":[],"categories":[],"sub_categories":[],"readme":"# K-Means implemented from scratch using CUDA  \n## Usage (C++)  \n```C++\nKMeans_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\nmodel.one_epoch(); // Trains one epoch\nmodel.print_predictions(); // Prints the classifications. Can be commented out.\n// printf (\"Error: %f\\n\", model.compute_error()); // Uncomment to print error\n```  \n\n## Kernels\n```C++\n// Updates each centroid using d_sum and d_count\n//    where the index is d * centroid number (out of k).\n// d: number of dimensions\n// k: number of clusters\n__global__ void update_centroids(\n    float *d_centroids,\n    const float *d_sum,\n    const int *d_count,\n    int d,\n    int k\n);\n```  \n\n```C++\n// Computes the sum (d_sum) and count (d_count) \n//    for each of the k clusters labeled in d_centroids.\n// n: number of data points\n// d: number of dimensions\n// k: number of clusters\n// Uses shared memory of 3*k*d\n__global__ void sum_and_count(\n    const float *d_data,\n    const float *d_centroids,\n    float *d_sum,\n    int *d_count,\n    int n,\n    int d,\n    int k\n);\n```  \n\n```C++\n// Computes error and updates d_error\n// n: number of data points\n// d: number of dimensions\n// k: number of clusters\n__global__ void calculate_error(\n    const float *d_data,\n    const float *d_centroids,\n    float *d_error,\n    int n,\n    int d,\n    int k\n) {\n```  \n\n## Usage (Python Bindings)\n```Python\n# pip install pybind11\n# (Look in the comments I left in the example if you also need to compile the library)\nimport KMeans_CUDA\nimport numpy as np\n# Data\nN=6\nD=1\nK=2\nepochs=3\ndata = np.array([0.1, 0.2, 0.3, 1.5, 1.6, 1.7], dtype=np.float32) # AoS\n# Constructor\nKMeans_CUDA.KMeans_CUDA_constructor(data, N, D, K)\n# Train\nKMeans_CUDA.fit(epochs)\n# Predict\nprint (KMeans_CUDA.predictions())\n\n# DON'T FORGET TO DELETE MEMORY!\nKMeans_CUDA.release_memory()\n```  \n\n## Performance  \nGo to: https://github.com/Tyler-Hilbert/CUDA-KMeans/tree/52db75728794449dc152989c648e03b632d24c08 for most recent performance tests.  \n\n## Performance compared to scikit-learn and ArrayFire  \nIt is shown that this implementations of K-Means outperforms scitkit-learn and ArrayFire on a T4.  \n![CUDA KMeans Performance vs scikit-learn and ArrayFire](https://raw.githubusercontent.com/Tyler-Hilbert/CUDA-KMeans/main/Benchmark_Performance/Comparison.png)  \n\n## Usage Continued  \nTo compile the test program:  \n$git clone https://github.com/Tyler-Hilbert/CUDA-KMeans.git  \n$cd CUDA-KMeans  \n$nvcc main.cpp KMeans_CUDA.cu -o kmeans  \n$./kmeans  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyler-hilbert%2Fcuda-kmeans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyler-hilbert%2Fcuda-kmeans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyler-hilbert%2Fcuda-kmeans/lists"}