Ive changed few things, now I preffere to do firstyly something in zig and later on I will look for options to make bindings to python.
mm.zig is main file with matrix multiplication function. the main problem is that i dont know how to build this, to make it work as a independent library in python, I lost an idea to make "faster pytorch", now im focused to something that can be used with or without pytorch.
As a man who is trying to understand zig and write usefull code in other language than python (or try to write something usefull), I get an idea of creating something what is using zig to optize pytorch, make is faster, more reliable. I don't know if it's going to work, but I need to do it my own as a motivation do study.
PyTorch is written in C++ and gives API in this language, BUT ZIG GIVES US built in tools to compile code in C/C++. I can define functions from C++ in zig and use it in my code. 000_example.zig. As you see, something works, and the plan is rewrite/build from scrach pytorch functions in zig and do something with it.
- Write pytorch functions in zig.
- Check it everything work on python
This function takes two tensors 2d (matrix).
- Plan: Define the functionality you want to implement
- Test-Driven Development: Write tests in Zig first
- Implement: Create the Zig implementation
- Benchmark: Compare performance with PyTorch
- C API: Expose functionality through C API
- Python Bindings: Create Python wrappers
- Document: Update documentation
# Build the Zig library
zig build
# Run Zig tests
zig build test
# Build in release mode for better performance
zig build -Drelease-fast
zig build command
zig build-obj -OReleaseFast -fPIC mm.zig
zig build-obj -fcompiler-rt mm.zig -fPIC -lpthread
important to create module
pip install -e .
//python setup.py install
Building the Python Package
# Install in development mode
pip install -e .
# Build and install
python setup.py install
ex: Creating a New Operation
- create a new file in src/ (e.g., src/add.zig) example add.zig
- Implement your function
- Create a test file in tests/ (e.g., tests/testadd.zig)
- Update build.zig to include your new files
- Expose through C API in src/native.zig
# Basic build
zig build
# Build with optimization for release
zig build -Drelease-fast
# Run tests
zig build test
# Clean build artifacts
rm -rf zig-out/