Start ripping stuff out

This commit is contained in:
Steven Robertson 2011-04-28 11:24:58 -04:00
parent 04351d6582
commit bd1a943914
4 changed files with 5 additions and 127 deletions

View File

@ -1,32 +1 @@
from collections import namedtuple
Flag = namedtuple('Flag', 'level desc')
class DebugSettings(object):
"""
Container for default debug settings.
"""
def __init__(self, items):
self.items = items
self.values = {}
self.level = 1
def __getattr__(self, name):
if name not in self.items:
raise KeyError("Unknown debug flag name!")
if name in self.values:
return self.values[name]
return (self.items[name].level <= self.level)
def format_help(self):
name_len = min(30, max(map(len, self.items.keys())))
fmt = '%-' + name_len + 's %d %s'
return '\n'.join([fmt % (k, v.level, v.desc)
for k, v in self.items.items()])
debug_flags = dict(
count_writes = Flag(3, "Count the number of points written per thread "
"when doing iterations."),
count_rounds = Flag(3, "Count the number of times the iteration loop "
"runs per thread when doing iterations.")
)

View File

@ -9,7 +9,6 @@ from fr0stlib import pyflam3
from fr0stlib.pyflam3._flam3 import *
from fr0stlib.pyflam3.constants import *
from cuburn.device_code import *
from cuburn.variations import Variations
Point = lambda x, y: np.array([x, y], dtype=np.double)
@ -136,7 +135,7 @@ class Animation(object):
In other words, it's best to use exactly one Animation for each
interpolated sequence between one or two genomes.
"""
def __init__(self, genomes):
def __init__(self, genomes, ngenomes = None):
# _frame is the ctypes frame object used only for interpolation
self._frame = _Frame(genomes)
@ -145,28 +144,9 @@ class Animation(object):
self.features = Features(genomes, self.filters)
def compile(self):
"""
Create a PTX kernel optimized for this animation, compile it, and
attach it to a LaunchContext with a thread distribution optimized for
the active device.
"""
# TODO: automatic optimization of block parameters
entry = ptx.Entry("iterate", 512)
iter = IterThread(entry, self.features)
entry.finalize()
iter.cp.finalize()
srcmod = ptx.Module([entry])
util.disass(srcmod)
self.mod = run.Module([entry])
pass
def render_frame(self, time=0):
# TODO: support more nuanced frame control than just 'time'
# TODO: reuse more information between frames
# TODO: allow animation-long override of certain parameters (size, etc)
frame = Frame(self._frame, time)
frame.upload_data(self.ctx, self.filters, time)
IterThread.call(self.ctx)
return HistScatter.get_bins(self.ctx, self.features)
pass
class Filters(object):
def __init__(self, frame, cp):

View File

@ -1,4 +1,3 @@
from pyptx import ptx
class Variations(object):
"""
@ -27,65 +26,3 @@ class Variations(object):
"waves2", "exp", "log", "sin", "cos", "tan", "sec", "csc", "cot",
"sinh", "cosh", "tanh", "sech", "csch", "coth", "auger", "flux", ]
def apply_xform(self, entry, cp, x, y, color, xform_idx):
"""
Apply a transform.
This function necessarily makes a copy of the input variables, so it's
safe to use the same registers for input and output.
"""
e, r, o, m, p, s = entry.locals
# For use in retrieving properties from the control point datastream
xfs = lambda stval: 'cp.xforms[%d].%s' % (xform_idx, stval)
e.comment('Color transformation')
c_speed, c_val = cp.get.v2.f32('1.0 - %s' % xfs('color_speed'),
'%s * %s' % (xfs('color'), xfs('color_speed')))
color = color * c_speed + c_val
e.comment('Affine transformation')
c00, c20 = cp.get.v2.f32(xfs('coefs[0][0]'), xfs('coefs[2][0]'))
xt = x * c00 + c20
c01, c21 = cp.get.v2.f32(xfs('coefs[0][1]'), xfs('coefs[2][1]'))
yt = x * c01 + c21
c10, c11 = cp.get.v2.f32(xfs('coefs[1][0]'), xfs('coefs[1][1]'))
xt += y * c10
yt += y * c11
xo, yo = o.mov.f32(0), o.mov.f32(0)
for var_name in sorted(self.features.xforms[xform_idx].vars):
func = getattr(self, var_name, None)
if not func:
raise NotImplementedError(
"Haven't implemented %s yet" % var_name)
e.comment('%s variation' % var_name)
xtemp, ytemp = func(o, xt, yt, cp.get.f32(xfs(var_name)))
xo += xtemp
yo += ytemp
if self.features.xforms[xform_idx].has_post:
e.comment('Affine post-transformation')
c00, c20 = cp.get.v2.f32(xfs('post[0][0]'), xfs('post[2][0]'))
xt = xo * c00 + c20
c01, c21 = cp.get.v2.f32(xfs('post[0][1]'), xfs('post[2][1]'))
yt = xo * c01 + c21
c10, c11 = cp.get.v2.f32(xfs('post[1][0]'), xfs('post[1][1]'))
xt += yo * c10
yt += yo * c11
xo, yo = xt, yt
self.xform_idx = None
return xo, yo, color
def linear(self, o, x, y, wgt):
return x * wgt, y * wgt
def sinusoidal(self, o, x, y, wgt):
return o.sin(x) * wgt, o.sin(y) * wgt
def spherical(self, o, x, y, wgt):
rsquared = x * x + y * y
rrcp = o.rcp(rsquared) * wgt
return x * wgt, y * wgt

12
main.py
View File

@ -17,20 +17,12 @@ from ctypes import *
import numpy as np
np.set_printoptions(precision=5, edgeitems=20)
from pyptx import ptx, run, util
from cuburn.device_code import *
from fr0stlib.pyflam3 import *
from fr0stlib.pyflam3._flam3 import *
from cuburn.render import *
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')
from cuburn.render import *
def mwctest():
mwcent = ptx.Entry("mwc_test", 512)