[llvm-commits] [test-suite] r171745 - in /test-suite/trunk: LICENSE.TXT SingleSource/Benchmarks/Makefile SingleSource/Benchmarks/SmallPT/ SingleSource/Benchmarks/SmallPT/LICENSE.txt SingleSource/Benchmarks/SmallPT/Makefile SingleSource/Benchmarks/SmallPT/README SingleSource/Benchmarks/SmallPT/smallpt.cpp SingleSource/Benchmarks/SmallPT/smallpt.reference_output

Paul Redmond paul.redmond at intel.com
Mon Jan 7 07:25:10 PST 2013


Author: predmond
Date: Mon Jan  7 09:25:10 2013
New Revision: 171745

URL: http://llvm.org/viewvc/llvm-project?rev=171745&view=rev
Log:
add smallpt benchmark to test-suite

original source from http://www.kevinbeason.com/smallpt/ with the following
modifications:
- commented out openmp pragma
- disabled writing to output image to file

Added:
    test-suite/trunk/SingleSource/Benchmarks/SmallPT/
    test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt
    test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile
    test-suite/trunk/SingleSource/Benchmarks/SmallPT/README
    test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp
    test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output
Modified:
    test-suite/trunk/LICENSE.TXT
    test-suite/trunk/SingleSource/Benchmarks/Makefile

Modified: test-suite/trunk/LICENSE.TXT
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/LICENSE.TXT?rev=171745&r1=171744&r2=171745&view=diff
==============================================================================
--- test-suite/trunk/LICENSE.TXT (original)
+++ test-suite/trunk/LICENSE.TXT Mon Jan  7 09:25:10 2013
@@ -108,3 +108,4 @@
 SingleSource Tests: llvm-test/SingleSource/Benchmarks/Misc
                     llvm-test/SingleSource/CustomChecked
                     llvm-test/SingleSource/Gizmos
+                    llvm-test/SingleSource/Benchmarks/SmallPT

Modified: test-suite/trunk/SingleSource/Benchmarks/Makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/Makefile?rev=171745&r1=171744&r2=171745&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/Makefile (original)
+++ test-suite/trunk/SingleSource/Benchmarks/Makefile Mon Jan  7 09:25:10 2013
@@ -1,6 +1,7 @@
 LEVEL = ../..
 PARALLEL_DIRS := Dhrystone CoyoteBench Shootout Shootout-C++ Stanford McGill \
-              Misc Misc-C++ Misc-C++-EH BenchmarkGame Adobe-C++ Polybench Linpack LivermoreLoops
+              Misc Misc-C++ Misc-C++-EH BenchmarkGame Adobe-C++ Polybench Linpack LivermoreLoops \
+              SmallPT
 LDFLAGS += -lm
 
 # Disable Polybench tests on ARM for the time being, they are very long running.

Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt?rev=171745&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt (added)
+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/LICENSE.txt Mon Jan  7 09:25:10 2013
@@ -0,0 +1,22 @@
+LICENSE
+
+Copyright (c) 2006-2008 Kevin Beason (kevin.beason at gmail.com)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile?rev=171745&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile (added)
+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/Makefile Mon Jan  7 09:25:10 2013
@@ -0,0 +1,7 @@
+LEVEL = ../../..
+LDFLAGS += -lm 
+FP_TOLERANCE := 0.001
+
+include $(LEVEL)/Makefile.config
+
+include $(LEVEL)/SingleSource/Makefile.singlesrc

Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/README
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/README?rev=171745&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/README (added)
+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/README Mon Jan  7 09:25:10 2013
@@ -0,0 +1,119 @@
+TITLE
+
+smallpt: Global Illumination in 99 lines of C++
+
+CREDITS
+
+Author: Kevin Beason (kevin.beason [at] gmail.com)
+Date: 10/11/2008
+
+SUMMARY
+
+smallpt is a small Monte Carlo path tracer, and generates a single image of a
+modified Cornell box rendered with full global illumination (GI). It does this
+by solving the rendering equation, including ideal Lambertian, specular, and
+dielectric reflection, area lights, anti-aliasing, importance sampling, and
+multi-threading. It is only 99 lines of C++, but illustrates photo realistic
+rendering in a correct, and concise manner.
+
+DESCRIPTION
+
+The source code for a small program that path traces a simple Cornell box and
+produces accurate results in a terse implementation is given, which provides an
+educational example to new graphics students (and seasoned alike), and yields a
+ground truth image, all in an easy to read package. Never before has a correct,
+complete, and functioning path tracer been presented so succinctly. Readers
+will see ray-sphere intersection, Monte Carlo path tracing, Russian roulette,
+importance sampling, anti-aliasing, and OpenMP multi-threading in a concrete
+working example, which may be read from beginning to end in a single
+sitting. The program compiles with GCC 4.2 down to a 16k executable and
+produces a 1024x768 resolution image using 5000 paths in 2 hours on an Intel
+Core 2 Quad machine. With slight modifications (smallpt4k.cpp) the code compiles to
+under 4KB.
+
+FEATURES
+
+* Global illumination
+* Unbiased Monte Carlo path tracing
+* Cornell box scene description
+* Ray-sphere intersection
+* Soft shadows from diffuse luminaire
+* Specular, Diffuse, and Glass BRDFs
+* Cosine importance sampling of the hemisphere for diffuse reflection
+* Russian roulette for path termination
+* Russian roulette for selecting reflection or refraction for glass BRDF
+* Antialiasing via super-sampling with importance-sampled tent distribution,
+  and 2x2 subpixels
+* Automatic multi-threading using OpenMP
+* Less than 100 lines of 72-column code
+* With provided code changes, can compile to 4K binary
+
+BUILDING
+
+There are two versions of smallpt. The basic version is called "smallpt"
+(smallpt.cpp), and is 99 lines. A second version, "smallpt4k" (smallpt4k.cpp),
+is 102 lines but compiles to 4K instead of 16KB. It is just a
+proof-of-concept. They compute slightly different images due to compiler optimization differences.
+The 4 KB version takes 30% longer.
+
+1) Modify top of Makefile to select the correct compiler.
+2) "make smallpt" (This builds both the regular version)
+3) "make smallpt4k"  (This builds the 4K version. Requires sstrip, see Makefile.)
+
+USAGE
+
+The program takes one argument, the number of samples per pixel. This value
+must be greater than 4 to accommodate the 2x2 subpixel grid. For example,
+the included reference image was generated with:
+
+     time ./smallpt 5000
+
+This took 124 minutes (2 hours) on a Intel Core 2 Quad Q6600 2.4GHz machine
+running Kubuntu Linux (32-bit Gutsy).
+
+The tiny version takes no arguments (5000 samples/pixel is hard coded):
+
+    time ./smallpt4k
+
+Compilation requires gzip and ELFkicker's sstrip command. See the Makefile for
+details. It executes in slightly longer time, and yields a slightly different
+image due to compiler optimizations differences.
+
+The time command tells you how long the render takes and is optional. You can
+view the image with most any image viewer. For example, if you have ImageMagick
+installed:
+
+    display image.ppm
+
+MORE INFO
+
+MINILIGHT - a minimal global illumination renderer, by Harrison Ainsworth
+A similar, earlier project. More general but also larger (100x). The site has
+some good information on Monte Carlo path tracing. Instead of repeating it
+here, the reader is referred to that site:
+http://www.hxa7241.org/minilight/minilight.html
+
+Realistic Ray Tracing by Peter Shirley
+Almost 100% of smallpt is derived from this book.
+http://www.amazon.com/Realistic-Ray-Tracing-Peter-Shirley/dp/1568811101
+
+Henrik Wann Jensen's Cornell box images
+The inpiration of the output generated by smallpt.
+http://graphics.ucsd.edu/~henrik/images/cbox.html
+
+100 lines C++ sphereflake raytracer, by Thierry Berger-Perrin
+Ray sphere intersection code stolen from here. (No full GI.)
+http://ompf.org/ray/sphereflake/
+
+sf4k, also by Thierry Berger-Perrin
+Idea for 4K-ness. (No full GI.)
+http://ompf.org/stuff/sf4k/
+
+C++ vs OCaml: Ray tracer comparison, by Jon D. Harrop
+105 line C++ ray tracer. (No full GI.)
+http://www.ffconsultancy.com/languages/ray_tracer/comparison.html
+
+Introduction to Linux as 4 KB Platform
+Some information regarding shrinking binaries to 4KB on Linux .
+http://in4k.untergrund.net/index.php?title=Linux
+

Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp?rev=171745&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp (added)
+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.cpp Mon Jan  7 09:25:10 2013
@@ -0,0 +1,102 @@
+#include <math.h>   // smallpt, a Path Tracer by Kevin Beason, 2008
+#include <stdlib.h> // Make : g++ -O3 -fopenmp smallpt.cpp -o smallpt
+#include <stdio.h>  //        Remove "-fopenmp" for g++ version < 4.2
+struct Vec {        // Usage: time ./smallpt 5000 && xv image.ppm
+  double x, y, z;                  // position, also color (r,g,b)
+  Vec(double x_=0, double y_=0, double z_=0){ x=x_; y=y_; z=z_; }
+  Vec operator+(const Vec &b) const { return Vec(x+b.x,y+b.y,z+b.z); }
+  Vec operator-(const Vec &b) const { return Vec(x-b.x,y-b.y,z-b.z); }
+  Vec operator*(double b) const { return Vec(x*b,y*b,z*b); }
+  Vec mult(const Vec &b) const { return Vec(x*b.x,y*b.y,z*b.z); }
+  Vec& norm(){ return *this = *this * (1/sqrt(x*x+y*y+z*z)); }
+  double dot(const Vec &b) const { return x*b.x+y*b.y+z*b.z; } // cross:
+  Vec operator%(Vec&b){return Vec(y*b.z-z*b.y,z*b.x-x*b.z,x*b.y-y*b.x);}
+};
+struct Ray { Vec o, d; Ray(Vec o_, Vec d_) : o(o_), d(d_) {} };
+enum Refl_t { DIFF, SPEC, REFR };  // material types, used in radiance()
+struct Sphere {
+  double rad;       // radius
+  Vec p, e, c;      // position, emission, color
+  Refl_t refl;      // reflection type (DIFFuse, SPECular, REFRactive)
+  Sphere(double rad_, Vec p_, Vec e_, Vec c_, Refl_t refl_):
+    rad(rad_), p(p_), e(e_), c(c_), refl(refl_) {}
+  double intersect(const Ray &r) const { // returns distance, 0 if nohit
+    Vec op = p-r.o; // Solve t^2*d.d + 2*t*(o-p).d + (o-p).(o-p)-R^2 = 0
+    double t, eps=1e-4, b=op.dot(r.d), det=b*b-op.dot(op)+rad*rad;
+    if (det<0) return 0; else det=sqrt(det);
+    return (t=b-det)>eps ? t : ((t=b+det)>eps ? t : 0);
+  }
+};
+Sphere spheres[] = {//Scene: radius, position, emission, color, material
+  Sphere(1e5, Vec( 1e5+1,40.8,81.6), Vec(),Vec(.75,.25,.25),DIFF),//Left
+  Sphere(1e5, Vec(-1e5+99,40.8,81.6),Vec(),Vec(.25,.25,.75),DIFF),//Rght
+  Sphere(1e5, Vec(50,40.8, 1e5),     Vec(),Vec(.75,.75,.75),DIFF),//Back
+  Sphere(1e5, Vec(50,40.8,-1e5+170), Vec(),Vec(),           DIFF),//Frnt
+  Sphere(1e5, Vec(50, 1e5, 81.6),    Vec(),Vec(.75,.75,.75),DIFF),//Botm
+  Sphere(1e5, Vec(50,-1e5+81.6,81.6),Vec(),Vec(.75,.75,.75),DIFF),//Top
+  Sphere(16.5,Vec(27,16.5,47),       Vec(),Vec(1,1,1)*.999, SPEC),//Mirr
+  Sphere(16.5,Vec(73,16.5,78),       Vec(),Vec(1,1,1)*.999, REFR),//Glas
+  Sphere(600, Vec(50,681.6-.27,81.6),Vec(12,12,12),  Vec(), DIFF) //Lite
+};
+inline double clamp(double x){ return x<0 ? 0 : x>1 ? 1 : x; }
+inline int toInt(double x){ return int(pow(clamp(x),1/2.2)*255+.5); }
+inline bool intersect(const Ray &r, double &t, int &id){
+  double n=sizeof(spheres)/sizeof(Sphere), d, inf=t=1e20;
+  for(int i=int(n);i--;) if((d=spheres[i].intersect(r))&&d<t){t=d;id=i;}
+  return t<inf;
+}
+Vec radiance(const Ray &r, int depth, unsigned short *Xi){
+  double t;                               // distance to intersection
+  int id=0;                               // id of intersected object
+  if (!intersect(r, t, id)) return Vec(); // if miss, return black
+  const Sphere &obj = spheres[id];        // the hit object
+  Vec x=r.o+r.d*t, n=(x-obj.p).norm(), nl=n.dot(r.d)<0?n:n*-1, f=obj.c;
+  double p = f.x>f.y && f.x>f.z ? f.x : f.y>f.z ? f.y : f.z; // max refl
+  if (++depth>5) if (erand48(Xi)<p) f=f*(1/p); else return obj.e; //R.R.
+  if (obj.refl == DIFF){                  // Ideal DIFFUSE reflection
+    double r1=2*M_PI*erand48(Xi), r2=erand48(Xi), r2s=sqrt(r2);
+    Vec w=nl, u=((fabs(w.x)>.1?Vec(0,1):Vec(1))%w).norm(), v=w%u;
+    Vec d = (u*cos(r1)*r2s + v*sin(r1)*r2s + w*sqrt(1-r2)).norm();
+    return obj.e + f.mult(radiance(Ray(x,d),depth,Xi));
+  } else if (obj.refl == SPEC)            // Ideal SPECULAR reflection
+    return obj.e + f.mult(radiance(Ray(x,r.d-n*2*n.dot(r.d)),depth,Xi));
+  Ray reflRay(x, r.d-n*2*n.dot(r.d));     // Ideal dielectric REFRACTION
+  bool into = n.dot(nl)>0;                // Ray from outside going in?
+  double nc=1, nt=1.5, nnt=into?nc/nt:nt/nc, ddn=r.d.dot(nl), cos2t;
+  if ((cos2t=1-nnt*nnt*(1-ddn*ddn))<0)    // Total internal reflection
+    return obj.e + f.mult(radiance(reflRay,depth,Xi));
+  Vec tdir = (r.d*nnt - n*((into?1:-1)*(ddn*nnt+sqrt(cos2t)))).norm();
+  double a=nt-nc, b=nt+nc, R0=a*a/(b*b), c = 1-(into?-ddn:tdir.dot(n));
+  double Re=R0+(1-R0)*c*c*c*c*c,Tr=1-Re,P=.25+.5*Re,RP=Re/P,TP=Tr/(1-P);
+  return obj.e + f.mult(depth>2 ? (erand48(Xi)<P ?   // Russian roulette
+    radiance(reflRay,depth,Xi)*RP:radiance(Ray(x,tdir),depth,Xi)*TP) :
+    radiance(reflRay,depth,Xi)*Re+radiance(Ray(x,tdir),depth,Xi)*Tr);
+}
+int main(int argc, char *argv[]){
+  int w=1024, h=768, samps = argc==2 ? atoi(argv[1])/4 : 1; // # samples
+  Ray cam(Vec(50,52,295.6), Vec(0,-0.042612,-1).norm()); // cam pos, dir
+  Vec cx=Vec(w*.5135/h), cy=(cx%cam.d).norm()*.5135, r, *c=new Vec[w*h];
+  //#pragma omp parallel for schedule(dynamic, 1) private(r)       // OpenMP
+  fprintf(stderr,"Rendering (%d spp)\n",samps*4);
+  for (int y=0; y<h; y++){                       // Loop over image rows
+    //fprintf(stderr,"\rRendering (%d spp) %5.2f%%",samps*4,100.*y/(h-1));
+    for (unsigned short x=0, Xi[3]={0,0,y*y*y}; x<w; x++)   // Loop cols
+      for (int sy=0, i=(h-y-1)*w+x; sy<2; sy++)     // 2x2 subpixel rows
+        for (int sx=0; sx<2; sx++, r=Vec()){        // 2x2 subpixel cols
+          for (int s=0; s<samps; s++){
+            double r1=2*erand48(Xi), dx=r1<1 ? sqrt(r1)-1: 1-sqrt(2-r1);
+            double r2=2*erand48(Xi), dy=r2<1 ? sqrt(r2)-1: 1-sqrt(2-r2);
+            Vec d = cx*( ( (sx+.5 + dx)/2 + x)/w - .5) +
+                    cy*( ( (sy+.5 + dy)/2 + y)/h - .5) + cam.d;
+            r = r + radiance(Ray(cam.o+d*140,d.norm()),0,Xi)*(1./samps);
+          } // Camera rays are pushed ^^^^^ forward to start in interior
+          c[i] = c[i] + Vec(clamp(r.x),clamp(r.y),clamp(r.z))*.25;
+        }
+  }
+#if 0
+  FILE *f = fopen("image.ppm", "w");         // Write image to PPM file.
+  fprintf(f, "P3\n%d %d\n%d\n", w, h, 255);
+  for (int i=0; i<w*h; i++)
+    fprintf(f, "%d %d %d\n", toInt(c[i].x), toInt(c[i].y), toInt(c[i].z));
+#endif
+}

Added: test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output?rev=171745&view=auto
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output (added)
+++ test-suite/trunk/SingleSource/Benchmarks/SmallPT/smallpt.reference_output Mon Jan  7 09:25:10 2013
@@ -0,0 +1,2 @@
+Rendering (4 spp)
+exit 0





More information about the llvm-commits mailing list