chaos support \0/

This commit is contained in:
Erik Reckase 2011-06-24 06:09:04 -06:00
parent bc2aa00e2a
commit 50b664b1f9
3 changed files with 34 additions and 16 deletions

View File

@ -102,7 +102,7 @@ class DensityEst(HunkOCode):
def defs(self): def defs(self):
return self.defs_tmpl.substitute(features=self.features, cp=self.cp) return self.defs_tmpl.substitute(features=self.features, cp=self.cp)
defs_tmpl = Template(""" defs_tmpl = Template('''
#define W 15 // Filter width (regardless of standard deviation chosen) #define W 15 // Filter width (regardless of standard deviation chosen)
#define W2 7 // Half of filter width, rounded down #define W2 7 // Half of filter width, rounded down
#define FW 46 // Width of local result storage (NW+W2+W2) #define FW 46 // Width of local result storage (NW+W2+W2)
@ -277,7 +277,7 @@ void density_est(float4 *pixbuf, float4 *outbuf, float *denbuf,
} }
} }
""") ''')
def invoke(self, mod, cp, abufd, obufd, dbufd, stream=None): def invoke(self, mod, cp, abufd, obufd, dbufd, stream=None):
# TODO: add no-est version # TODO: add no-est version
@ -285,8 +285,7 @@ void density_est(float4 *pixbuf, float4 *outbuf, float *denbuf,
k1 = np.float32(cp.brightness * 268 / 256) k1 = np.float32(cp.brightness * 268 / 256)
area = self.features.width * self.features.height / cp.ppu ** 2 area = self.features.width * self.features.height / cp.ppu ** 2
k2 = np.float32(1 / (area * cp.adj_density)) k2 = np.float32(1 / (area * cp.adj_density ))
print k1, k2
if self.cp.estimator == 0: if self.cp.estimator == 0:
nbins = self.features.acc_height * self.features.acc_stride nbins = self.features.acc_height * self.features.acc_stride

View File

@ -67,7 +67,7 @@ void apply_xf{{xfid}}(float *ix, float *iy, float *icolor, mwc_st *rctx) {
return tmpl.substitute(g) return tmpl.substitute(g)
def _iterbody(self): def _iterbody(self):
tmpl = Template(r""" tmpl = Template('''
__global__ __global__
void iter(mwc_st *msts, iter_info *infos, float4 *accbuf, float *denbuf) { void iter(mwc_st *msts, iter_info *infos, float4 *accbuf, float *denbuf) {
mwc_st rctx = msts[gtid()]; mwc_st rctx = msts[gtid()];
@ -81,9 +81,10 @@ void iter(mwc_st *msts, iter_info *infos, float4 *accbuf, float *denbuf) {
int consec_bad = -{{features.fuse}}; int consec_bad = -{{features.fuse}};
// TODO: remove '512' constant // TODO: remove '512' constant
int nsamps = {{packer.get('cp.width * cp.height / (cp.ntemporal_samples * 512.) * cp.adj_density')}}; int nsamps = {{packer.get("cp.width * cp.height / (cp.ntemporal_samples * 512.) * cp.adj_density")}};
float x, y, color; float x, y, color;
int last_xf_used = 0;
x = mwc_next_11(&rctx); x = mwc_next_11(&rctx);
y = mwc_next_11(&rctx); y = mwc_next_11(&rctx);
color = mwc_next_01(&rctx); color = mwc_next_01(&rctx);
@ -91,14 +92,17 @@ void iter(mwc_st *msts, iter_info *infos, float4 *accbuf, float *denbuf) {
while (nsamps > 0) { while (nsamps > 0) {
float xfsel = mwc_next_01(&rctx); float xfsel = mwc_next_01(&rctx);
{{for xfid, xform in enumerate(features.xforms)}} {{for density_row_idx, prior_xform_idx in enumerate(features.std_xforms)}}
{{if xfid != features.final_xform_index}} {{for density_col_idx, this_xform_idx in enumerate(features.std_xforms)}}
if (xfsel <= {{packer.get('cp.norm_density[%d]' % xfid)}}) { if (last_xf_used == {{prior_xform_idx}} &&
apply_xf{{xfid}}(&x, &y, &color, &rctx); xfsel < {{packer.get("cp.chaos_densities[%d][%d]" % (density_row_idx, density_col_idx))}}) {
apply_xf{{this_xform_idx}}(&x, &y, &color, &rctx);
last_xf_used = {{this_xform_idx}};
} else } else
{{endif}} {{endfor}}
{{endfor}} {{endfor}}
{ {
//printf("%d ",last_xf_used);
denbuf[0] = xfsel; denbuf[0] = xfsel;
break; // TODO: fail here break; // TODO: fail here
} }
@ -125,7 +129,7 @@ void iter(mwc_st *msts, iter_info *infos, float4 *accbuf, float *denbuf) {
{{endif}} {{endif}}
// TODO: verify that constants get premultiplied // TODO: verify that constants get premultiplied
float ditherwidth = {{packer.get('0.33 * cp.spatial_filter_radius')}}; float ditherwidth = {{packer.get("0.33 * cp.spatial_filter_radius")}};
float u0 = mwc_next_01(&rctx); float u0 = mwc_next_01(&rctx);
float r = ditherwidth * sqrt(-2.0f * log2f(u0) / M_LOG2E); float r = ditherwidth * sqrt(-2.0f * log2f(u0) / M_LOG2E);
@ -150,7 +154,7 @@ void iter(mwc_st *msts, iter_info *infos, float4 *accbuf, float *denbuf) {
int i = iy * {{features.acc_stride}} + ix; int i = iy * {{features.acc_stride}} + ix;
float4 outcol = tex2D(palTex, color, {{packer.get('cp_step_frac')}}); float4 outcol = tex2D(palTex, color, {{packer.get("cp_step_frac")}});
float4 pix = accbuf[i]; float4 pix = accbuf[i];
pix.x += outcol.x; pix.x += outcol.x;
pix.y += outcol.y; pix.y += outcol.y;
@ -161,7 +165,7 @@ void iter(mwc_st *msts, iter_info *infos, float4 *accbuf, float *denbuf) {
} }
asm volatile ("membar.cta;"); asm volatile ("membar.cta;");
} }
""") ''')
return tmpl.substitute( return tmpl.substitute(
features = self.features, features = self.features,
packer = self.packer.view('info'), packer = self.packer.view('info'),

View File

@ -41,8 +41,19 @@ class Genome(object):
self.xforms = [self.xform[i] for i in range(self.num_xforms)] self.xforms = [self.xform[i] for i in range(self.num_xforms)]
dens = np.array([x.density for i, x in enumerate(self.xforms) dens = np.array([x.density for i, x in enumerate(self.xforms)
if i != self.final_xform_index]) if i != self.final_xform_index])
dens /= np.sum(dens)
self.norm_density = [np.sum(dens[:i+1]) for i in range(len(dens))] ###############
# Chaos support
num_std_xf = len(dens)
self.chaos_densities = np.zeros( (num_std_xf,num_std_xf) )
for r in range(num_std_xf):
chaos_row = np.array([ctypes_genome.chaos[r][c] for c in range(num_std_xf)])
chaos_row = chaos_row * dens
chaos_row /= np.sum(chaos_row)
chaos_row = [np.sum(chaos_row[:i+1]) for i in range(len(dens))]
self.chaos_densities[r,:] = chaos_row
###############
self.camera_transform = self.calc_camera_transform() self.camera_transform = self.calc_camera_transform()
scale = property(lambda cp: 2.0 ** cp.zoom) scale = property(lambda cp: 2.0 ** cp.zoom)
@ -368,6 +379,9 @@ class _AnimRenderer(object):
g = a.features.gutter g = a.features.gutter
obuf_dim = (a.features.acc_height, a.features.acc_stride, 4) obuf_dim = (a.features.acc_height, a.features.acc_stride, 4)
out = cuda.from_device(self.d_out, obuf_dim, np.float32) out = cuda.from_device(self.d_out, obuf_dim, np.float32)
#dacc = cuda.from_device(self.d_accum, obuf_dim, np.float32)
#daccw = dacc[:,:,3]
#print daccw.sum()
# TODO: performance? # TODO: performance?
g = a.features.gutter g = a.features.gutter
out = np.delete(out, np.s_[:g], axis=0) out = np.delete(out, np.s_[:g], axis=0)
@ -438,6 +452,7 @@ class Features(object):
self.acc_width = genomes[0].width + 2 * self.gutter self.acc_width = genomes[0].width + 2 * self.gutter
self.acc_height = genomes[0].height + 2 * self.gutter self.acc_height = genomes[0].height + 2 * self.gutter
self.acc_stride = 32 * int(math.ceil(self.acc_width / 32.)) self.acc_stride = 32 * int(math.ceil(self.acc_width / 32.))
self.std_xforms = filter(lambda v: v != self.final_xform_index, range(self.nxforms))
class XFormFeatures(object): class XFormFeatures(object):
def __init__(self, xforms, xform_id): def __init__(self, xforms, xform_id):