https://github.com/mikex86/LibreCuda Skip to content Navigation Menu Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + GitHub Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions By size + Enterprise + Teams + Startups By industry + Healthcare + Financial services + Manufacturing By use case + CI/CD & Automation + DevOps + DevSecOps * Resources Topics + AI + DevOps + Security + Software Development Explore + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up Reseting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} mikex86 / LibreCuda Public * Notifications You must be signed in to change notification settings * Fork 21 * Star 694 License MIT license 694 stars 21 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights mikex86/LibreCuda This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master BranchesTags Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 5 Commits src src CMakeLists.txt CMakeLists.txt LICENSE LICENSE README.MD README.MD complex.ptx complex.ptx write_float.cubin write_float.cubin write_float.ptx write_float.ptx View all files Repository files navigation * README * MIT license LibreCUDA LibreCUDA is a project aimed at replacing the CUDA driver API to enable launching CUDA code on Nvidia GPUs without relying on the proprietary CUDA runtime. It achieves this by communicating directly with the hardware via ioctls, (specifically what Nvidia's open-gpu-kernel-modules refer to as the rmapi), as well as QMD, Nvidia's MMIO command queue structure. LibreCUDA is capable of uploading CUDA ELF binaries onto the GPU and launching them via the command queue. Current features * Allocate and free gpu memory & map the memory to be accessible by the CPU * Capable of uploading CUDA ELF binaries to the GPU * Launches CUDA kernels via the command queue Example Below is an example demonstrating the usage of LibreCUDA: int main() { libreCuInit(0); int device_count{}; libreCuDeviceGetCount(&device_count); std::cout << "Device count: " + std::to_string(device_count) << std::endl; LibreCUdevice device{}; libreCuDeviceGet(&device, 0); LibreCUcontext ctx{}; libreCuCtxCreate_v2(&ctx, CU_CTX_SCHED_YIELD, device); LibreCUmodule module{}; uint8_t *image; size_t n_bytes; { std::ifstream input("write_float.cubin", std::ios::binary); std::vector bytes( (std::istreambuf_iterator(input)), (std::istreambuf_iterator())); input.close(); image = new uint8_t[bytes.size()]; memcpy(image, bytes.data(), bytes.size()); n_bytes = bytes.size(); } libreCuModuleLoadData(&module, image, n_bytes); uint32_t num_funcs{}; libreCuModuleGetFunctionCount(&num_funcs, module); std::cout << "Num functions: " << num_funcs << std::endl; auto *functions = new LibreCUFunction[num_funcs]; libreCuModuleEnumerateFunctions(functions, num_funcs, module); for (size_t i = 0; i < num_funcs; i++) { LibreCUFunction func = functions[i]; const char *func_name{}; libreCuFuncGetName(&func_name, func); std::cout << " function \"" << func_name << "\"" << std::endl; } delete[] functions; LibreCUFunction func{}; libreCuModuleGetFunction(&func, module, "write_float"); LibreCUstream stream{}; libreCuStreamCreate(&stream, 0); void *float_dst_va{}; libreCuMemAlloc(&float_dst_va, sizeof(float), true); float float_value = 3.1415f; void *float_src_va{}; libreCuMemAlloc(&float_src_va, sizeof(float), true); *(float *) (float_src_va) = float_value; std::cout << "Src value: " << float_value << std::endl; std::cout << "Dst value (pre exec): " << *(float *) (float_dst_va) << std::endl; void *params[] = { &float_dst_va, // dst &float_src_va // src }; libreCuLaunchKernel(func, 1, 1, 1, 1, 1, 1, 0, stream, params, sizeof(params) / sizeof(void *), nullptr ); libreCuStreamCommence(stream); libreCuStreamAwait(stream); std::cout << "Dst value (post exec): " << *(float *) (float_dst_va) << std::endl; libreCuMemFree(float_dst_va); libreCuStreamDestroy(stream); libreCuModuleUnload(module); libreCuCtxDestroy(ctx); return 0; } Outputs: Device count: 1 Num functions: 1 function "write_float" Src value: 3.1415 Dst value (pre exec): 0 Dst value (post exec): 3.1415 Project Status The project is in its early stages and currently implements only rudimentary CUDA functions. It is not yet ready for production use. Contributing Contributions are welcome! Please submit issues and pull requests to help improve LibreCUDA. License This project is licensed under the MIT License. About No description, website, or topics provided. Resources Readme License MIT license Activity Stars 694 stars Watchers 11 watching Forks 21 forks Report repository Releases No releases published Packages 0 No packages published Languages * C 93.9% * C++ 6.1% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.