Skip to content
Snippets Groups Projects
Commit f87db739 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent dc2942a8
No related branches found
No related tags found
No related merge requests found
......@@ -87,6 +87,8 @@
<a href=glimage.py>glimage.py</a>, <a href=glsurf.py>glsurf.py<a/>
<a href=https://www.w3.org/TR/webgpu/>WebGPU</a> <a href=https://github.com/pygfx/wgpu-py>wgpu-py</a> <a href=https://github.com/pygfx/pygfx>pygfx</a>
<a href=programs/pygfxsurf.py>pygfxsurf.py</a> <a href=programs/pygfxsurf.mp4>video</a>
<a href=https://github.com/taichi-dev/taichi>Taichi</a>
<a href=programs/taichisurf.py>taichisurf.py</a> <a href=programs/taichisurf.mp4>video</a>
<a href=http://renderman.pixar.com/view/non-commercial-renderman>RenderMan</a>, <a href=http://cgkit.sourceforge.net/>cgkit</a>
<a href=http://www.vtk.org/>VTK</a>, <a href=http://www.vtk.org/Wiki/VTK/Writing_VTK_files_using_python>pyvtk</a>, <a href=http://docs.enthought.com/mayavi/mayavi/>Mayavi</a>
<a href=https://www.paraview.org/>ParaView</a>
......@@ -132,9 +134,7 @@
<a href=https://gitlab.cba.mit.edu/pub/pi/blob/master/README.md><b>performance</b></a>
<a href=https://gitlab.cba.mit.edu/pub/pi/-/blob/master/Python/pi.py>pi.py</a>, <a href=https://gitlab.cba.mit.edu/pub/pi/-/blob/master/Python/numpi.py>numpi.py</a>
<a href=http://cython.org>Cython</a>
<a href=http://numba.pydata.org>Numba</a> <a href=https://gitlab.cba.mit.edu/pub/pi/-/blob/master/Python/numbapi.py>numbapi.py</a>
<a href=https://jax.readthedocs.io/en/latest/notebooks/quickstart.html>JAX</a>
<a href=https://pub.pages.cba.mit.edu/pi/JavaScript/pi.html>pi.html</a>
<a href=https://v8.dev>JIT</a>, <a href=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays>typed arrays</a>, <a href=https://developer.mozilla.org/en-US/docs/Web/Guide/Performance/Using_web_workers>web workers</a>, <a href=https://developer.mozilla.org/en-US/docs/Web/API/FileReader>file readers</a>
<a href=https://gitlab.cba.mit.edu/pub/pi/-/blob/master/C/pi.c>pi.c</a>
......@@ -147,6 +147,8 @@
<a href=https://developer.nvidia.com/cuda-zone>CUDA</a>, <a href=https://mathema.tician.de/software/pycuda>PyCUDA</a>
<a href=https://www.khronos.org/opencl>OpenCL</a>, <a href=https://mathema.tician.de/software/pyopencl>PyOpenCL</a>
<a href=https://gpuweb.github.io/gpuweb/>WebGPU</a>, <a href=http://fab.cba.mit.edu/classes/864.17/people/amandaghassaei/CAs>GPUMath.js</a>
<a href=https://github.com/taichi-dev/taichi>Taichi</a>
<a href=programs/taichipi.py>taichipi.py</a>
<b>deploy</b>
<a href=https://restfulapi.net/>REST</a>, <a href=https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Introduction>PWA</a>
......
#
# taichipi.py
# Neil Gershenfeld 2/22/23
# calculation of pi by Taichi
# pi = 3.14159265358979323846
#
import time
import taichi as ti
NPTS = 10000000
def calc_pi(NPTS):
pi = 0
for i in range(1,(NPTS+1)):
pi += 0.5/((i-0.75)*(i-0.25))
return pi
pi = calc_pi(1000) # run first to compile
start_time = time.time()
pi = calc_pi(NPTS)
end_time = time.time()
mflops = NPTS*5.0/(1.0e6*(end_time-start_time))
print("\nNPTS = %d, pi = %f"%(NPTS,pi))
print("time = %f, estimated Python MFlops = %f\n"%(end_time-start_time,mflops))
ti.init(arch=ti.cpu,default_ip=ti.i64,default_fp=ti.f64,cpu_max_num_threads=1)
NPTS = int(1000000000)
@ti.kernel
def calc_pi_CPU(NPTS:int)->float:
pi = float(0)
for i in range(1,(NPTS+1)):
pi += 0.5/((i-0.75)*(i-0.25))
return pi
pi = calc_pi_CPU(1000) # run first to compile
start_time = time.time()
pi = calc_pi_CPU(NPTS)
end_time = time.time()
mflops = NPTS*5.0/(1.0e6*(end_time-start_time))
print("NPTS = %d, pi = %f"%(NPTS,pi))
print("time = %f, estimated Taichi CPU serial MFlops = %f\n"%(end_time-start_time,mflops))
ti.init(arch=ti.cpu,default_ip=ti.i64,default_fp=ti.f64)
@ti.kernel
def calc_pi_CPU(NPTS:int)->float:
pi = float(0)
for i in range(1,(NPTS+1)):
pi += 0.5/((i-0.75)*(i-0.25))
return pi
pi = calc_pi_CPU(1000) # run first to compile
start_time = time.time()
pi = calc_pi_CPU(NPTS)
end_time = time.time()
mflops = NPTS*5.0/(1.0e6*(end_time-start_time))
print("NPTS = %d, pi = %f"%(NPTS,pi))
print("time = %f, estimated Taichi CPU parallel MFlops = %f\n"%(end_time-start_time,mflops))
ti.init(arch=ti.gpu,default_ip=ti.i64,default_fp=ti.f64)
@ti.kernel
def calc_pi_GPU(NPTS:int)->float:
pi = float(0)
for i in range(1,(NPTS+1)):
pi += 0.5/((i-0.75)*(i-0.25))
return pi
pi = calc_pi_GPU(1000) # run first to compile
start_time = time.time()
pi = calc_pi_GPU(NPTS)
end_time = time.time()
mflops = NPTS*5.0/(1.0e6*(end_time-start_time))
print("NPTS = %d, pi = %f"%(NPTS,pi))
print("time = %f, estimated Taichi GPU MFlops = %f\n"%(end_time-start_time,mflops))
File added
#
# taichisurf.py
# Neil Gershenfeld 3/1/23
# Taichi particle plot example
#
import taichi as ti
ti.init()
N = 100
r = 1/N
kmax = 50
dk = 0.05
k = 0.0
p = ti.Vector.field(3,float,N*N)
c = ti.Vector.field(3,float,N*N)
@ti.kernel
def update(k:float):
for i in range(N):
for j in range(N):
x = i/(N-1)-0.5
y = j/(N-1)-0.5
r = ti.sqrt(x*x+y*y)
z = ti.sin(k*r)/(k*r)
p[i+N*j].z = z
c[i+N*j] = (z,1-z,0)
@ti.kernel
def init():
for i in range(N):
for j in range(N):
p[i+N*j].x = i/N
p[i+N*j].y = j/N
i = 0
def render():
global k,dk
scene.set_camera(camera)
scene.point_light(pos=(0.5,1.5,0.5), color=(0.5,0.5,0.5))
scene.point_light(pos=(0.5,1.5,1.5), color=(0.5,0.5,0.5))
k += dk
if ((k >= kmax) | (k <= 0)):
dk = -dk
update(k)
scene.particles(p,radius=r,per_vertex_color=c)
canvas.scene(scene)
window = ti.ui.Window("sin(r)/r",(1080,720))
canvas = window.get_canvas()
gui = window.get_gui()
scene = ti.ui.Scene()
camera = ti.ui.Camera()
camera.position(6,2.5,2)
camera.lookat(0.5,0.5,0.3)
camera.up(0,0,1)
camera.fov(15)
init()
count = 0
while window.running:
render()
#window.save_image(f'images/out{count:05d}.png')
count += 1
window.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment