2010-08-27 12:28:02 -04:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# flam3cuda, one of a surprisingly large number of ports of the fractal flame
|
|
|
|
# algorithm to NVIDIA GPUs.
|
|
|
|
#
|
|
|
|
# This one is copyright 2010 Steven Robertson <steven@strobe.cc>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 or later
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2010-09-11 13:15:36 -04:00
|
|
|
from pprint import pprint
|
2010-08-30 14:45:44 -04:00
|
|
|
from ctypes import *
|
2010-08-27 12:28:02 -04:00
|
|
|
|
|
|
|
import numpy as np
|
2010-10-01 01:20:20 -04:00
|
|
|
np.set_printoptions(precision=5, edgeitems=20)
|
|
|
|
|
2010-10-07 11:21:43 -04:00
|
|
|
from pyptx import ptx, run
|
|
|
|
|
2010-09-12 18:42:52 -04:00
|
|
|
from cuburn.device_code import *
|
2010-08-30 14:45:44 -04:00
|
|
|
from fr0stlib.pyflam3 import *
|
|
|
|
from fr0stlib.pyflam3._flam3 import *
|
2010-09-10 14:48:34 -04:00
|
|
|
from cuburn.render import *
|
2010-08-27 12:28:02 -04:00
|
|
|
|
2010-09-09 11:36:14 -04:00
|
|
|
import pyglet
|
|
|
|
|
|
|
|
def dump_3d(nda):
|
|
|
|
with open('/tmp/data.txt', 'w') as f:
|
|
|
|
for row in nda:
|
|
|
|
f.write(' | '.join([' '.join(
|
|
|
|
['%4.1g\t' % x for x in pt]) for pt in row]) + '\n')
|
|
|
|
|
2010-10-07 11:21:43 -04:00
|
|
|
def disass(mod):
|
|
|
|
import subprocess
|
|
|
|
sys.stdout.flush()
|
|
|
|
with open('/tmp/pyptx.ptx', 'w') as fp:
|
|
|
|
fp.write(mod.source)
|
|
|
|
subprocess.check_call('ptxas -arch sm_21 /tmp/pyptx.ptx '
|
|
|
|
'-o /tmp/elf.o'.split())
|
|
|
|
subprocess.check_call('/home/steven/code/decuda/elfToCubin.py --nouveau '
|
|
|
|
'/tmp/elf.o'.split())
|
|
|
|
|
2010-10-09 11:18:58 -04:00
|
|
|
def mwctest():
|
2010-10-07 11:21:43 -04:00
|
|
|
mwcent = ptx.Entry("mwc_test", 512)
|
|
|
|
mwctest = MWCRNGTest(mwcent)
|
|
|
|
|
|
|
|
# Get the source for saving and disassembly before potentially crashing
|
|
|
|
mod = ptx.Module([mwcent])
|
|
|
|
print '\n'.join(['%4d %s' % t for t in enumerate(mod.source.split('\n'))])
|
|
|
|
disass(mod)
|
|
|
|
|
|
|
|
mod = run.Module([mwcent])
|
|
|
|
mod.print_func_info()
|
|
|
|
|
|
|
|
ctx = mod.get_context('mwc_test', 14)
|
|
|
|
mwctest.run_test(ctx)
|
|
|
|
|
2010-10-09 11:18:58 -04:00
|
|
|
def main(args):
|
2010-09-02 16:12:22 -04:00
|
|
|
with open(args[-1]) as fp:
|
2010-08-30 14:45:44 -04:00
|
|
|
genomes = Genome.from_string(fp.read())
|
2010-09-02 17:26:16 -04:00
|
|
|
anim = Animation(genomes)
|
2010-09-06 11:18:20 -04:00
|
|
|
anim.compile()
|
2010-09-09 11:36:14 -04:00
|
|
|
bins = anim.render_frame()
|
2010-09-13 12:22:08 -04:00
|
|
|
w, h = anim.features.hist_width, anim.features.hist_height
|
|
|
|
bins = bins[:,:w]
|
|
|
|
alpha = bins[...,3]
|
2010-09-12 02:32:03 -04:00
|
|
|
k2ish = (256./(np.mean(alpha)+1e-9))
|
|
|
|
lses = 20 * np.log2(1.0 + alpha * k2ish) / (alpha+1e-6)
|
2010-09-13 12:22:08 -04:00
|
|
|
bins *= lses.reshape(h,w,1).repeat(4,2)
|
2010-09-11 13:15:36 -04:00
|
|
|
bins = np.minimum(bins, 255)
|
|
|
|
bins = bins.astype(np.uint8)
|
2010-09-06 11:18:20 -04:00
|
|
|
|
2010-09-09 11:36:14 -04:00
|
|
|
if '-g' not in args:
|
|
|
|
return
|
2010-08-27 12:28:02 -04:00
|
|
|
|
2010-09-13 00:20:15 -04:00
|
|
|
window = pyglet.window.Window(1600, 900)
|
2010-09-09 11:36:14 -04:00
|
|
|
image = pyglet.image.ImageData(anim.features.hist_width,
|
|
|
|
anim.features.hist_height,
|
|
|
|
'RGBA',
|
2010-09-13 12:22:08 -04:00
|
|
|
bins.tostring())
|
|
|
|
#-anim.features.hist_stride*4)
|
2010-09-09 11:36:14 -04:00
|
|
|
tex = image.texture
|
2010-08-27 12:28:02 -04:00
|
|
|
|
2010-09-12 18:42:52 -04:00
|
|
|
pal = (anim.ctx.ptx.instances[PaletteLookup].pal * 255.).astype(np.uint8)
|
|
|
|
image2 = pyglet.image.ImageData(256, 16, 'RGBA', pal.tostring())
|
|
|
|
|
2010-09-09 11:36:14 -04:00
|
|
|
@window.event
|
|
|
|
def on_draw():
|
|
|
|
window.clear()
|
|
|
|
tex.blit(0, 0)
|
2010-09-12 18:42:52 -04:00
|
|
|
image2.blit(0, 0)
|
2010-08-27 12:28:02 -04:00
|
|
|
|
2010-09-09 11:36:14 -04:00
|
|
|
@window.event
|
|
|
|
def on_key_press(sym, mod):
|
|
|
|
if sym == pyglet.window.key.Q:
|
|
|
|
pyglet.app.exit()
|
2010-08-27 12:28:02 -04:00
|
|
|
|
2010-09-09 11:36:14 -04:00
|
|
|
pyglet.app.run()
|
2010-08-27 12:28:02 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2010-09-02 16:12:22 -04:00
|
|
|
if len(sys.argv) < 2 or not os.path.isfile(sys.argv[-1]):
|
|
|
|
print "Last argument must be a path to a genome file"
|
2010-08-27 12:28:02 -04:00
|
|
|
sys.exit(1)
|
2010-09-02 16:12:22 -04:00
|
|
|
main(sys.argv)
|
2010-08-27 12:28:02 -04:00
|
|
|
|