https://github.com/exaloop/codon 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 + View all 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 }} exaloop / codon Public * Notifications You must be signed in to change notification settings * Fork 504 * Star 14.5k A high-performance, zero-overhead, extensible Python compiler using LLVM docs.exaloop.io/codon License View license 14.5k stars 504 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 190 * Pull requests 3 * Discussions * Actions * Security * Insights Additional navigation options * Code * Issues * Pull requests * Discussions * Actions * Security * Insights exaloop/codon This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. develop BranchesTags Go to file Code Folders and files Last commit Last Name Name message commit date Latest commit History 445 Commits .github .github bench bench cmake cmake codon codon docs docs jit jit jupyter jupyter scripts scripts stdlib stdlib test test .clang-format .clang-format .clang-tidy .clang-tidy .gitattributes .gitattributes .gitignore .gitignore .pre-commit-config.yaml .pre-commit-config.yaml CMakeLists.txt CMakeLists.txt CODEOWNERS CODEOWNERS CONTRIBUTING.md CONTRIBUTING.md LICENSE LICENSE README.md README.md book.json book.json View all files Repository files navigation * README * License Codon Docs * FAQ * Blog * Chat * Roadmap * Benchmarks Build Status What is Codon? Codon is a high-performance Python implementation that compiles to native machine code without any runtime overhead. Typical speedups over vanilla Python are on the order of 10-100x or more, on a single thread. Codon's performance is typically on par with (and sometimes better than) that of C/C++. Unlike Python, Codon supports native multithreading, which can lead to speedups many times higher still. Think of Codon as Python reimagined for static, ahead-of-time compilation, built from the ground up with best possible performance in mind. Goals * No learning curve: Be as close to CPython as possible in terms of syntax, semantics and libraries * Top-notch performance: At least on par with low-level languages like C, C++ or Rust * Hardware support: Full, seamless support for multicore programming, multithreading (no GIL!), GPU and more * Optimizations: Comprehensive optimization framework that can target high-level Python constructs and libraries * Interoperability: Full interoperability with Python's ecosystem of packages and libraries Non-goals * Drop-in replacement for CPython: Codon is not a drop-in replacement for CPython. There are some aspects of Python that are not suitable for static compilation -- we don't support these in Codon. There are ways to use Codon in larger Python codebases via its JIT decorator or Python extension backend. Codon also supports calling any Python module via its Python interoperability. See also "Differences with Python" in the docs. * New syntax and language constructs: We try to avoid adding new syntax, keywords or other language features as much as possible. While Codon does add some new syntax in a couple places (e.g. to express parallelism), we try to make it as familiar and intuitive as possible. Install Pre-built binaries for Linux (x86_64) and macOS (x86_64 and arm64) are available alongside each release. Download and install with: /bin/bash -c "$(curl -fsSL https://exaloop.io/install.sh)" Or you can build from source. Examples Codon is a Python-compatible language, and many Python programs will work with few if any modifications: def fib(n): a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print() fib(1000) The codon compiler has a number of options and modes: # compile and run the program codon run fib.py # 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 # compile and run the program with optimizations enabled codon run -release fib.py # 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 # compile to executable with optimizations enabled codon build -release -exe fib.py ./fib # 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 # compile to LLVM IR file with optimizations enabled codon build -release -llvm fib.py # outputs file fib.ll See the docs for more options and examples. You can import and use any Python package from Codon. For example: from python import matplotlib.pyplot as plt data = [x**2 for x in range(10)] plt.plot(data) plt.show() (Just remember to set the CODON_PYTHON environment variable to the CPython shared library, as explained in the the docs.) This prime counting example showcases Codon's OpenMP support, enabled with the addition of one line. The @par annotation tells the compiler to parallelize the following for-loop, in this case using a dynamic schedule, chunk size of 100, and 16 threads. from sys import argv def is_prime(n): factors = 0 for i in range(2, n): if n % i == 0: factors += 1 return factors == 0 limit = int(argv[1]) total = 0 @par(schedule='dynamic', chunk_size=100, num_threads=16) for i in range(2, limit): if is_prime(i): total += 1 print(total) Codon supports writing and executing GPU kernels. Here's an example that computes the Mandelbrot set: import gpu MAX = 1000 # maximum Mandelbrot iterations N = 4096 # width and height of image pixels = [0 for _ in range(N * N)] def scale(x, a, b): return a + (x/N)*(b - a) @gpu.kernel def mandelbrot(pixels): idx = (gpu.block.x * gpu.block.dim.x) + gpu.thread.x i, j = divmod(idx, N) c = complex(scale(j, -2.00, 0.47), scale(i, -1.12, 1.12)) z = 0j iteration = 0 while abs(z) <= 2 and iteration < MAX: z = z**2 + c iteration += 1 pixels[idx] = int(255 * iteration/MAX) mandelbrot(pixels, grid=(N*N)//1024, block=1024) GPU programming can also be done using the @par syntax with @par(gpu= True). Documentation Please see docs.exaloop.io for in-depth documentation. About A high-performance, zero-overhead, extensible Python compiler using LLVM docs.exaloop.io/codon Topics python compiler high-performance llvm parallel-programming gpu-programming Resources Readme License View license Activity Custom properties Stars 14.5k stars Watchers 140 watching Forks 504 forks Report repository Releases 10 v0.17.0 Latest Aug 23, 2024 + 9 releases Contributors 14 * @arshajii * @inumanag * @isnumanagic * @dependabot[bot] * @markhend * @kurtmckee * @stephenberry * @seanfarley * @zstadler * @jsoref * @hsmajlovic * @eltociear * @learnforpractice * @pakaelbling Languages * C++ 52.6% * Python 46.0% * Other 1.4% 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.