Coder Social home page Coder Social logo

lean4-raytracer's People

Contributors

kmill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

lean4-raytracer's Issues

missing C optimisations

I'm not sure if the C benchmark here is meant to be "optimised to the hilt" or just reasonably representative. Obviously you want it to somewhat correspond to the Lean implementation, but it's possible to teach the compiler more about this code.

All the functions except main in render.c could be marked static. Alternatively, -fwhole-program has the same effect in GCC. This improves the compiler's ability (or maybe willingness) to inline and specialize functions. Link-time optimisation could also be added on top of this with -flto that might further accelerate it.

Maybe these comments are not relevant and you just wanted to compare against reasonably optimised C. But if not, I hope these comments are helpful.

Lean implementation is single-threaded

The following numbers were produced on my personal laptop with various programs running in the background (<5% noise). ASUS ZenBook UX434FAC (i7-10510U).

I've only run the default test once per version. I recommend using https://docs.rs/hyperfine for accurate benchmark results on a dedicated server with intentionally minimal noise and a static clock.

All single-threaded implementations clock around 3.7 GHz (+/- 0.1GHz), while the multi-threaded C clocked around 2.1 GHz (+/- 0.1 GHz) per core.

(Normalized to single threaded C time. Lower is better.)

Master branch Lean. 3.53x (~34m 30s)
Optimize branch Lean. 2.89x (~28m 16s) (I guess this implementation differs too much to be a fair comparison?)
Single threaded C. 1x (~9m 46s)
Multi-threaded C. 0.42x (~4m 9s) (Obviously flawed comparison)

--- render.c    2021-10-20 +0000
+++ render-single-core.c        2021-10-20 +0000
@@ -592,7 +592,7 @@

   printf("Starting %d threads.\n", num_threads);

-  pthread_t threads[num_threads];
+  struct RenderData *threads[num_threads];

   for (int i = 0; i < num_threads; i++) {
     struct RenderData *rd = malloc(sizeof(struct RenderData));
@@ -606,7 +606,8 @@
     rd->nobj = nobj;
     Rand_split(&rand, &rd->rand);
     rd->show_progress = (i == 0);
-    pthread_create(&threads[i], NULL, &render_task, (void*)rd);
+    render_task(rd);
+    threads[i] = rd;
   }

   Color *pixels = malloc(height * width * sizeof(Color));
@@ -615,8 +616,7 @@
   }

   for (int i = 0; i < num_threads; i++) {
-    struct RenderData *rd = NULL;
-    pthread_join(threads[i], (void **)&rd);
+    struct RenderData *rd = threads[i];
     Color *new_pixels = rd->pixels;
     for (int i = 0; i < height * width; i++) {
       pixels[i] = Vec3_add(pixels[i], new_pixels[i]);

Missing license

There is no license file and the readme does not mention a license.

The repo should have a license file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.