# GSoC 2024: GPU Libc Benchmarking

DevFeed: [GSoC 2024: GPU Libc Benchmarking](<https://devfeed.tech/articles/gsoc-2024-gpu-libc-benchmarking-43101.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2024-08-09-libc-gpu-benchmarking/>)

Author: James Hu

Published: 2024-08-09T00:00:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [GPU](<https://devfeed.tech/topics/gpu.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [CUDA](<https://devfeed.tech/topics/cuda.md>), [CMake](<https://devfeed.tech/topics/cmake.md>), [Google](<https://devfeed.tech/topics/google.md>)

Tags: [amd](<https://devfeed.tech/tags/amd.md>), [benchmarking](<https://devfeed.tech/tags/benchmarking.md>), [cmake](<https://devfeed.tech/tags/cmake.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [cuda](<https://devfeed.tech/tags/cuda.md>), [google](<https://devfeed.tech/tags/google.md>), [gpu](<https://devfeed.tech/tags/gpu.md>), [gsoc](<https://devfeed.tech/tags/gsoc.md>), [infrastructure](<https://devfeed.tech/tags/infrastructure.md>), [libc](<https://devfeed.tech/tags/libc.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [nvidia](<https://devfeed.tech/tags/nvidia.md>), [offloading](<https://devfeed.tech/tags/offloading.md>), [project](<https://devfeed.tech/tags/project.md>), [results](<https://devfeed.tech/tags/results.md>), [threads](<https://devfeed.tech/tags/threads.md>)

## AI overview

An LLVM GSoC project developed microbenchmarking infrastructure for LLVM libc functions running on GPUs. The framework supports GPU execution, vendor implementation comparisons, CMake linking, and measurements such as cycles, iteration time, and standard deviation.

## Source excerpt

Hey everyone! My name is James and I worked on LLVM this summer through GSoC. My project is called GPU Libc Benchmarking. The main objective of this project was to develop microbenchmarking infrastructure for libc on the GPU. Background The LLVM libc project was designed as an alternative to glibc that aims to be modular, configurable, and sanitizer-friendly. Currently, LLVM libc is being ported to Nvidia and AMD GPUs to give libc functionality (e.g. printf(), malloc(), and math functions) on the GPU. As of March 2024, programs can use GPU libc in offloading languages (CUDA, OpenMP) or through direct compilation and linking with the libc library. What We Did During this project, we developed a microbenchmarking framework that is directly compiled for and run on the GPU, using libc functions to display output to the user. As this was a short project (90 hours), we mostly focused on developing the infrastructure and writing a few example usages (isalnum(), isalpha(), and sin()). Our benchmarking infrastructure is based on Google Benchmark and measures the average cycles, minimum, maximum, and standard deviation of each benchmark. Each benchmark is run for multiple iterations to stabilize the results. Benchmark writers can measure against vendor implementations of libc functions by passing specific linking flags to the benchmark's CMake portion and registering the corresponding vendor function from the benchmark itself. Below is an example of our benchmarking infrastructure's output for sinf() Benchmark | Cycles | Min | Max | Iterations | Time / Iteration | Stddev | Threads |----------------------------------------------------------------------------------------------------------Sinf_1 | 764 | 369 | 2101 | 273 | 7 us | 323 | 32 |Sinf_128 | 721 | 699 | 744 | 5 | 913 us | 16 | 32 |Sinf_1024 | 661 | 650 | 689 | 9 | 7 ms | 31 | 32 |Sinf_4096 | 666 | 663 | 669 | 5 | 28 ms | 28 | 32 |SinfTwoPi_1 | 372 | 369 | 632 | 70 | 7 us | 39 | 32 |SinfTwoPi_128 | 379 | 379 | 379 | 4 | 8