https://github.com/exaloop/codon Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + 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 + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} exaloop / codon Public * Notifications * Fork 4 * Star 550 A high-performance, zero-overhead, extensible Python compiler using LLVM docs.exaloop.io/codon License View license 550 stars 4 forks Star Notifications * Code * Issues 5 * Pull requests 0 * Discussions * Actions * Security * Insights More * 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 Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 2 branches 1 tag Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/e] Use Git or checkout with SVN using the web URL. [gh repo clone exaloo] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @inumanag @arshajii inumanag and arshajii Plugin loading fixes (#66) ... f4feee2 Dec 7, 2022 Plugin loading fixes (#66) * Add INSTALL target; Plugin loading fixes * Use ast::executable_path to get exec path * Update README.md Co-authored-by: A. R. Shajii f4feee2 Git stats * 336 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github Dynamic Polymorphism (#58) Dec 5, 2022 bench Dynamic Polymorphism (#58) Dec 5, 2022 cmake Plugin loading fixes (#66) Dec 8, 2022 codon Plugin loading fixes (#66) Dec 8, 2022 docs Update links [skip ci] Dec 5, 2022 extra Dynamic Polymorphism (#58) Dec 5, 2022 scripts Remove x86_64 install restriction [ci skip] Dec 5, 2022 stdlib Dynamic Polymorphism (#58) Dec 5, 2022 test Dynamic Polymorphism (#58) Dec 5, 2022 .clang-format Initial commit Sep 27, 2021 .clang-tidy Trigger CI Aug 2, 2022 .gitattributes Update .gitattributes Oct 3, 2021 .gitignore Typechecker refactoring (#20) Jul 26, 2022 CMakeLists.txt Plugin loading fixes (#66) Dec 8, 2022 CODEOWNERS Dynamic Polymorphism (#58) Dec 5, 2022 CONTRIBUTING.md Dynamic Polymorphism (#58) Dec 5, 2022 LICENSE Dynamic Polymorphism (#58) Dec 5, 2022 README.md Plugin loading fixes (#66) Dec 8, 2022 book.json Update docs (#28) Jul 26, 2022 View code Docs | FAQ | Blog | Forum | Chat | Benchmarks What is Codon? Install Examples What isn't Codon? Documentation README.md Codon Docs | FAQ | Blog | Forum | Chat | Benchmarks Build Status What is Codon? Codon is a high-performance Python compiler that compiles Python code to native machine code without any runtime overhead. Typical speedups over 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. Codon grew out of the Seq project. 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. 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). What isn't Codon? While Codon supports nearly all of Python's syntax, it is not a drop-in replacement, and large codebases might require modifications to be run through the Codon compiler. For example, some of Python's modules are not yet implemented within Codon, and a few of Python's dynamic features are disallowed. The Codon compiler produces detailed error messages to help identify and resolve any incompatibilities. Codon can be used within larger Python codebases via the @codon.jit decorator. Plain Python functions and libraries can also be called from within Codon via Python interoperability. 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 Stars 550 stars Watchers 8 watching Forks 4 forks Releases 1 v0.15.1 Latest Dec 5, 2022 Contributors 4 * * * * Languages * C++ 55.2% * Python 43.4% * Other 1.4% Footer (c) 2022 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. 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.