mirror of
https://github.com/stevenrobertson/cuburn.git
synced 2025-02-05 11:40:04 -05:00
Before I rip out tempita and start a DSL
This commit is contained in:
parent
0c78e972b1
commit
cceb75396f
@ -35,7 +35,6 @@ class LaunchContext(object):
|
|||||||
def __init__(self, entries, block=(1,1,1), grid=(1,1), seed=None,
|
def __init__(self, entries, block=(1,1,1), grid=(1,1), seed=None,
|
||||||
tests=False):
|
tests=False):
|
||||||
self.devinfo = pycuda.tools.DeviceData()
|
self.devinfo = pycuda.tools.DeviceData()
|
||||||
self.stream = cuda.Stream()
|
|
||||||
self.entry_types = entries
|
self.entry_types = entries
|
||||||
self.block, self.grid, self.build_tests = block, grid, tests
|
self.block, self.grid, self.build_tests = block, grid, tests
|
||||||
self.rand = np.random.mtrand.RandomState(seed)
|
self.rand = np.random.mtrand.RandomState(seed)
|
||||||
@ -73,7 +72,7 @@ class LaunchContext(object):
|
|||||||
inst = self.ptx.instances[test_type]
|
inst = self.ptx.instances[test_type]
|
||||||
print "Running test: %s... " % inst.name
|
print "Running test: %s... " % inst.name
|
||||||
try:
|
try:
|
||||||
self.stream.synchronize()
|
cuda.Context.synchronize()
|
||||||
if inst.call(self):
|
if inst.call(self):
|
||||||
print "Test %s passed." % inst.name
|
print "Test %s passed." % inst.name
|
||||||
else:
|
else:
|
||||||
|
@ -8,6 +8,7 @@ from cuburnlib.ptx import PTXFragment, PTXEntryPoint, PTXTest
|
|||||||
|
|
||||||
class MWCRNG(PTXFragment):
|
class MWCRNG(PTXFragment):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.threads_ready = 0
|
||||||
if not os.path.isfile('primes.bin'):
|
if not os.path.isfile('primes.bin'):
|
||||||
raise EnvironmentError('primes.bin not found')
|
raise EnvironmentError('primes.bin not found')
|
||||||
|
|
||||||
@ -57,24 +58,27 @@ class MWCRNG(PTXFragment):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def set_up(self, ctx):
|
def set_up(self, ctx):
|
||||||
|
if self.threads_ready >= ctx.threads:
|
||||||
|
return
|
||||||
# Load raw big-endian u32 multipliers from primes.bin.
|
# Load raw big-endian u32 multipliers from primes.bin.
|
||||||
with open('primes.bin') as primefp:
|
with open('primes.bin') as primefp:
|
||||||
dt = np.dtype(np.uint32).newbyteorder('B')
|
dt = np.dtype(np.uint32).newbyteorder('B')
|
||||||
mults = np.frombuffer(primefp.read(), dtype=dt)
|
mults = np.frombuffer(primefp.read(), dtype=dt)
|
||||||
|
stream = cuda.Stream()
|
||||||
# Randomness in choosing multipliers is good, but larger multipliers
|
# Randomness in choosing multipliers is good, but larger multipliers
|
||||||
# have longer periods, which is also good. This is a compromise.
|
# have longer periods, which is also good. This is a compromise.
|
||||||
# TODO: fix mutability, enable shuffle here
|
mults = np.array(mults[:ctx.threads*4])
|
||||||
# TODO: prevent period-1 random generators
|
ctx.rand.shuffle(mults)
|
||||||
#ctx.rand.shuffle(mults[:ctx.threads*4])
|
|
||||||
# Copy multipliers and seeds to the device
|
# Copy multipliers and seeds to the device
|
||||||
multdp, multl = ctx.mod.get_global('mwc_rng_mults')
|
multdp, multl = ctx.mod.get_global('mwc_rng_mults')
|
||||||
# TODO: get async to work
|
cuda.memcpy_htod_async(multdp, mults.tostring()[:multl])
|
||||||
#cuda.memcpy_htod_async(multdp, mults.tostring()[:multl], ctx.stream)
|
# Intentionally excludes both 0 and (2^32-1), as they can lead to
|
||||||
cuda.memcpy_htod(multdp, mults.tostring()[:multl])
|
# degenerate sequences of period 0
|
||||||
|
states = np.array(ctx.rand.randint(1, 0xffffffff, size=2*ctx.threads),
|
||||||
|
dtype=np.uint32)
|
||||||
statedp, statel = ctx.mod.get_global('mwc_rng_state')
|
statedp, statel = ctx.mod.get_global('mwc_rng_state')
|
||||||
#cuda.memcpy_htod_async(statedp, ctx.rand.bytes(statel), ctx.stream)
|
cuda.memcpy_htod_async(statedp, states.tostring())
|
||||||
|
self.threads_ready = ctx.threads
|
||||||
cuda.memcpy_htod(statedp, ctx.rand.bytes(statel))
|
|
||||||
|
|
||||||
def tests(self, ctx):
|
def tests(self, ctx):
|
||||||
return [MWCRNGTest]
|
return [MWCRNGTest]
|
||||||
@ -151,4 +155,31 @@ loopstart:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
class CameraCoordTransform(PTXFragment):
|
||||||
|
# This is here until I get the device stream packer going, or decide on
|
||||||
|
# how to handle C struct addressing if we go for unpacked structures
|
||||||
|
prelude = ".global .u32 camera_coords[8];"
|
||||||
|
|
||||||
|
def _cam_coord_xf(self, x, y, dreg):
|
||||||
|
"""
|
||||||
|
Given `.f32 x, y`, a coordinate in IFS space, writes the integer
|
||||||
|
offset from the start of the sampling lattice into `.u32 dreg`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return """{
|
||||||
|
.pred is_badval;
|
||||||
|
// TODO: This will change when data streaming is done
|
||||||
|
.reg .u32 camera_coord_address;
|
||||||
|
mov.u32 camera_coord_address, camera_coords;
|
||||||
|
// TODO: see if preloading everything hurts register count
|
||||||
|
.reg .f32 width_scale, width_upper_bound, height_scale, height_upper_bound;
|
||||||
|
ldu.v4.f32 {width_scale, width_upper_bound,
|
||||||
|
height_scale, height_upper_bound},
|
||||||
|
[camera_coord_address+0];
|
||||||
|
.reg .f32 x_xf, y_xf;
|
||||||
|
mad.rz.f32 x_xf, x, width_scale"""
|
||||||
|
# TODO unfinished
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
38
main.py
38
main.py
@ -11,39 +11,25 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
from ctypes import *
|
||||||
import ctypes
|
|
||||||
import struct
|
|
||||||
|
|
||||||
# These imports are order-sensitive!
|
|
||||||
import pyglet
|
|
||||||
import pyglet.gl as gl
|
|
||||||
gl.get_current_context()
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from fr0stlib import pyflam3
|
#from cuburnlib.device_code import MWCRNGTest
|
||||||
from cuburnlib.device_code import MWCRNGTest
|
#from cuburnlib.cuda import LaunchContext
|
||||||
from cuburnlib.cuda import LaunchContext
|
from fr0stlib.pyflam3 import *
|
||||||
|
from fr0stlib.pyflam3._flam3 import *
|
||||||
class CUGenome(pyflam3.Genome):
|
from cuburnlib.render import *
|
||||||
def _render(self, frame, trans):
|
|
||||||
obuf = (ctypes.c_ubyte * ((3+trans)*self.width*self.height))()
|
|
||||||
stats = pyflam3.RenderStats()
|
|
||||||
pyflam3.flam3_render(ctypes.byref(frame), obuf,
|
|
||||||
pyflam3.flam3_field_both,
|
|
||||||
trans+3, trans, ctypes.byref(stats))
|
|
||||||
return obuf, stats, frame
|
|
||||||
|
|
||||||
|
|
||||||
def main(genome_path):
|
def main(genome_path):
|
||||||
ctx = LaunchContext([MWCRNGTest], block=(256,1,1), grid=(64,1), tests=True)
|
#ctx = LaunchContext([MWCRNGTest], block=(256,1,1), grid=(64,1), tests=True)
|
||||||
ctx.compile(True)
|
#ctx.compile(True)
|
||||||
ctx.run_tests()
|
#ctx.run_tests()
|
||||||
|
|
||||||
with open(genome_path) as fp:
|
with open(genome_path) as fp:
|
||||||
genome = CUGenome.from_string(fp.read())[0]
|
genomes = Genome.from_string(fp.read())
|
||||||
|
render = Render(genomes)
|
||||||
|
render.render_frame()
|
||||||
|
|
||||||
#genome.width, genome.height = 512, 512
|
#genome.width, genome.height = 512, 512
|
||||||
#genome.sample_density = 1000
|
#genome.sample_density = 1000
|
||||||
|
Loading…
Reference in New Issue
Block a user