This repository contains my C code. A lot of it is my own versions of standard datatypes and algorithms such as my own hashset datatype. It was written for fun because I love C coding.
As some smart person once said; only the one who reinvents the wheel truly understand how it works. So there's that.
This repository consists of the following directories:
Located in libraries
are a bunch of libraries I have written to
learn more about algorithms, data structures, OS APIs, etc. They are
designed to be mostly self-contained and thus easy to borrow by
copying the files. However, over the years I have introduced
dependencies between them. Factoring out common code is just too
pleasurable.
No guarantee that the libraries are -- or ever will be -- complete. They were written because I wanted to.
Minimal library for benchmarking C code.
An object model and a bunch of garbage collectors. These were written to teach myself about garbage collection strategies.
copying.[ch]
- Bump pointer allocation and semi-space copyingcopying-opt.[ch]
- Optimized version of the aboveref-counting.[ch]
- Plain reference countingref-counting-cycles.[ch]
- Reference counting with cycle detectionmark-sweep.[ch]
- Mark & Sweep gc
Small wrapper for CUDA libraries.
Standard datatypes for C programming like vector
and
hashset
. There is not a lot of documentation for these
datatypes because the code should be self-explanatory.
A minimal library for solving linear Diophantine equations.
Fast IO routines accessing stdin
and stdout
. They are useful to
minimize IO overhead in competitive programming challenges.
A library for loading 3d meshes.
A library for explicit handling of ieee754 floating point numbers.
A collection of ray/triangle intersection algorithms. These are used by my raytracer.
Trival single-precision linear algebra library. Contains things like matrix multiplication and stuff.
A library containing OpenCL utility functions. It can be tricky to compile for Intel FPGA because libraries and headers are not in standard locations. You can try:
CFLAGS=$(aocl compile-config) \
CXXFLAGS=$(aocl compile-config) \
LDFLAGS=$(aocl ldflags) \
./waf-2.0.25 build
Of course, this assumes that aocl
and related programs are on the
PATH
. To run the built programs the OpenCL library must be linkable:
LD_LIBRARY_PATH=/path/to/opencl ./build/programs/opencl/prog
Simple pretty-printing.
Random number generation using www.pcg-random.org.
A library for filesystem path handling.
A memory allocator based on the Quick Fit algorithm. It's used by my garbage collectors.
A library for dealing with N-dimensional arrays (tensors).
Test suites for the various libraries.
Demo programs of all kinds:
programs/npyread.c
: Reading .npy files.programs/ntimes.c
: See {n} times faster than C - part one.programs/opencl/list.c
: List installed OpenCL platforms.
The project is built using the build tool Waf like this:
./waf configure build
Windows, Linux and OS X is supported.
Structs are not private. I have good reasons for making them public, but I forgot what they are now.
I prefer function declarations split over multiple lines, with the return type and function attributes on a separate line. Like this:
cl_int
ocl_create_buffer_and_write(cl_context ctx, cl_command_queue queue,
size_t n_bytes, void *host_ptr,
cl_mem *mem);
Lines shouldn't be longer 73-75 characters since that is how long my side-by-side Emacs frames are.