Skip to content

Commit

Permalink
Global and thread-local pools are now treated separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
schani committed Aug 2, 2009
1 parent 79b2127 commit 642d65c
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 105 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ CXX = g++

export CFLAGS CC

COMMON_OBJECTS = mathmap_common.o builtins/builtins.o exprtree.o parser.o scanner.o vars.o tags.o tuples.o internals.o macros.o userval.o overload.o jump.o builtins/libnoise.o builtins/spec_func.o compiler.o bitvector.o expression_db.o drawable.o floatmap.o tree_vectors.o designer/designer.o designer/cycles.o designer/loadsave.o designer_filter.o native-filters/gauss.o compopt/dce.o compopt/resize.o backends/cc.o backends/lazy_creator.o $(FFTW_OBJECTS) $(LLVM_OBJECTS)
COMMON_OBJECTS = mathmap_common.o builtins/builtins.o exprtree.o parser.o scanner.o vars.o tags.o tuples.o internals.o macros.o userval.o overload.o jump.o builtins/libnoise.o builtins/spec_func.o compiler.o bitvector.o expression_db.o drawable.o floatmap.o tree_vectors.o mmpools.o designer/designer.o designer/cycles.o designer/loadsave.o designer_filter.o native-filters/gauss.o compopt/dce.o compopt/resize.o backends/cc.o backends/lazy_creator.o $(FFTW_OBJECTS) $(LLVM_OBJECTS)
#COMMON_OBJECTS += designer/widget.o
COMMON_OBJECTS += designer/cairo_widget.o

GIMP_OBJECTS = mathmap.o

OBJECTS = $(COMMON_OBJECTS) $(CMDLINE_OBJECTS) $(GIMP_OBJECTS)

TEMPLATE_INPUTS = tuples.h mathmap.h userval.h drawable.h compiler.h builtins/builtins.h builtins/libnoise.h tree_vectors.h native-filters/native-filters.h
TEMPLATE_INPUTS = tuples.h mathmap.h userval.h drawable.h compiler.h mmpools.h builtins/builtins.h builtins/libnoise.h tree_vectors.h native-filters/native-filters.h

mathmap : libnoise compiler_types.h $(OBJECTS) $(CMDLINE_TARGETS) liblispreader new_template.c $(LLVM_TARGETS)
$(CXX) $(CGEN_LDFLAGS) -o mathmap $(OBJECTS) $(CMDLINE_LIBS) $(LLVM_LDFLAGS) lispreader/liblispreader.a $(MATHMAP_LDFLAGS)
Expand Down
6 changes: 3 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
FFTW
.lang file
get correct number of cpus
threads?
installer (from yuval)

** General
xy_vars must be moved to slice. the problem is that it might contain closures, whose pools might be used by the threads, and they're not thread-safe

** LLVM
why do we compare against floats in simple counting loops? (do we?)
update exported_symbols
Expand Down Expand Up @@ -60,6 +58,7 @@ Generate keyword list in sourceview spec file from builtins.lisp
add a few new tests, especially for native filters

** Rendering
strip resize images manually
specifiable size
antialiasing from rendered images
do rendering multi-threaded if possible
Expand All @@ -80,6 +79,7 @@ color gimp layer mode
** Native filters
figure out how much faster 2^n ffts are
do gaussian multithreaded if possible
see if there are faster gauss implementations available (some intel stuff?)
take aspect ratio of kernel into consideration - don't stretch it
normalize argument for convolve should not be bool but be the value to normalize to
image segmentation
Expand Down
6 changes: 3 additions & 3 deletions backends/llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ get_slice_ptr_type (Module *module)
static const Type*
get_pools_ptr_type (Module *module)
{
const Type *pools_type = module->getTypeByName(string("struct.pools_t"));
const Type *pools_type = module->getTypeByName(string("struct.mathmap_pools_t"));
g_assert(pools_type);
return PointerType::getUnqual(pools_type);
}
Expand Down Expand Up @@ -1196,7 +1196,7 @@ code_emitter::setup_init_frame_function ()

set_internals_from_invocation(invocation_arg);

ret_var = builder->CreateCall2(module->getFunction(string("_pools_alloc")),
ret_var = builder->CreateCall2(module->getFunction(string("_mathmap_pools_alloc")),
pools_arg, emit_sizeof(xy_vars_type));
xy_vars_var = builder->CreateBitCast(ret_var, PointerType::getUnqual(xy_vars_type));

Expand Down Expand Up @@ -1233,7 +1233,7 @@ code_emitter::setup_init_x_or_y_function (string function_name, const char *inte

set_xy_vars_from_frame();

ret_var = builder->CreateCall2(module->getFunction(string("_pools_alloc")),
ret_var = builder->CreateCall2(module->getFunction(string("_mathmap_pools_alloc")),
pools_arg, emit_sizeof(vars_type));

Value *vars_var = builder->CreateBitCast(ret_var, PointerType::getUnqual(vars_type));
Expand Down
13 changes: 6 additions & 7 deletions builtins/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_linalg.h>

#include "lispreader/pools.h"

#include "mmpools.h"
#include "builtins.h"
#include "tags.h"
#include "overload.h"
Expand Down Expand Up @@ -267,7 +266,7 @@ get_floatmap_pixel (mathmap_invocation_t *invocation, image_t *image, float x, f

CALLBACK_SYMBOL
image_t*
render_image (mathmap_invocation_t *invocation, image_t *image, int width, int height, pools_t *pools, int force)
render_image (mathmap_invocation_t *invocation, image_t *image, int width, int height, mathmap_pools_t *pools, int force)
{
image_t *new_image;

Expand Down Expand Up @@ -307,7 +306,7 @@ render_image (mathmap_invocation_t *invocation, image_t *image, int width, int h
color_t (*get_orig_val_pixel_func) (mathmap_invocation_t*, float, float, image_t*, int) = get_orig_val_pixel;
int x, y;
float *p;
pools_t filter_pools;
mathmap_pools_t filter_pools;

#ifdef DEBUG_OUTPUT
g_print("image is not closure: %d\n", image->type);
Expand All @@ -318,7 +317,7 @@ render_image (mathmap_invocation_t *invocation, image_t *image, int width, int h
ay = new_image->v.floatmap.ay;
by = new_image->v.floatmap.by;

init_pools(&filter_pools);
mathmap_pools_init_local(&filter_pools);
pools = &filter_pools;

p = new_image->v.floatmap.data;
Expand All @@ -331,7 +330,7 @@ render_image (mathmap_invocation_t *invocation, image_t *image, int width, int h
float fx = ((float)x - bx) / ax;
float *tuple;

reset_pools(&filter_pools);
mathmap_pools_reset(&filter_pools);
tuple = ORIG_VAL(fx, fy, image, 0.0);

memcpy(p, tuple, sizeof(float) * 4);
Expand All @@ -340,7 +339,7 @@ render_image (mathmap_invocation_t *invocation, image_t *image, int width, int h
}
}

free_pools(&filter_pools);
mathmap_pools_free(&filter_pools);
}

return new_image;
Expand Down
5 changes: 3 additions & 2 deletions builtins/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <stdio.h>

#include "lispreader/pools.h"
#include "mmpools.h"
#include "tuples.h"
#include "color.h"

Expand All @@ -44,7 +44,8 @@ color_t get_orig_val_intersample_pixel (struct _mathmap_invocation_t *invocation

float* get_floatmap_pixel (struct _mathmap_invocation_t *invocation, struct _image_t *image, float x, float y, float frame);

struct _image_t* render_image (struct _mathmap_invocation_t *invocation, struct _image_t *image, int width, int height, pools_t *pools, int force);
struct _image_t* render_image (struct _mathmap_invocation_t *invocation, struct _image_t *image,
int width, int height, mathmap_pools_t *pools, int force);
/* END */

void init_builtins (void);
Expand Down
12 changes: 7 additions & 5 deletions drawable.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ get_nth_input_drawable (int n)

CALLBACK_SYMBOL
image_t*
make_resize_image (image_t *image, float x_factor, float y_factor, pools_t *pools)
make_resize_image (image_t *image, float x_factor, float y_factor, mathmap_pools_t *pools)
{
image_t *resize = pools_alloc(pools, sizeof(image_t));
image_t *resize = mathmap_pools_alloc(pools, sizeof(image_t));

g_assert(image->type != IMAGE_RESIZE);

Expand All @@ -227,8 +227,8 @@ closure_image_alloc (mathfuncs_t *mathfuncs, filter_func_t filter_func,
image->v.closure.funcs = mathfuncs;
image->v.closure.func = filter_func;
image->v.closure.num_args = num_uservals;
image->v.closure.pools = g_new(pools_t, 1);
init_pools(image->v.closure.pools);
image->v.closure.pools = g_new0(mathmap_pools_t, 1);
mathmap_pools_init_global(image->v.closure.pools);
memcpy(image->v.closure.args, uservals, num_uservals * sizeof(userval_t));

return image;
Expand All @@ -237,6 +237,8 @@ closure_image_alloc (mathfuncs_t *mathfuncs, filter_func_t filter_func,
void
closure_image_free (image_t *closure)
{
free_pools(closure->v.closure.pools);
g_assert(closure->type == IMAGE_CLOSURE);
mathmap_pools_free(closure->v.closure.pools);
g_free(closure->v.closure.pools);
g_free(closure);
}
16 changes: 8 additions & 8 deletions drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include "color.h"
#include "userval.h"
#include "lispreader/pools.h"
#include "mmpools.h"

#define INPUT_DRAWABLE_GIMP 1
#define INPUT_DRAWABLE_CMDLINE_IMAGE 2
Expand All @@ -62,18 +62,18 @@ typedef void (*calc_lines_func_t) (struct _mathmap_slice_t*, struct _image_t*, i
typedef float* (*filter_func_t) (struct _mathmap_invocation_t*,
struct _image_t*,
float, float, float,
pools_t*);
mathmap_pools_t*);

/* FIXME: just for LLVM - remove eventually */
typedef void* (*llvm_init_frame_func_t) (struct _mathmap_invocation_t*,
struct _image_t*,
float,
pools_t*);
mathmap_pools_t*);
typedef float* (*llvm_filter_func_t) (struct _mathmap_slice_t*,
struct _image_t*,
void*, void*,
float, float, float,
pools_t*);
mathmap_pools_t*);
typedef void* (*init_x_or_y_func_t) (struct _mathmap_slice_t*,
struct _image_t*,
float, float);
Expand Down Expand Up @@ -101,7 +101,7 @@ typedef struct _image_t
struct _mathfuncs_t *funcs;
/* for getting single pixels - never called for the root closure */
filter_func_t func;
pools_t *pools;
mathmap_pools_t *pools;
void *xy_vars;
int num_args;
userval_t args[];
Expand Down Expand Up @@ -195,11 +195,11 @@ input_drawable_t* alloc_cmdline_image_input_drawable (const char *filename);
input_drawable_t* alloc_cmdline_movie_input_drawable (const char *filename);
#endif

image_t* floatmap_alloc (int width, int height, pools_t *pools);
image_t* floatmap_copy (image_t *floatmap, pools_t *pools);
image_t* floatmap_alloc (int width, int height, mathmap_pools_t *pools);
image_t* floatmap_copy (image_t *floatmap, mathmap_pools_t *pools);

/* TEMPLATE make_resize_image */
image_t* make_resize_image (image_t *image, float x_factor, float y_factor, pools_t *pools);
image_t* make_resize_image (image_t *image, float x_factor, float y_factor, mathmap_pools_t *pools);
/* END */

void floatmap_get_channel_column (float *dst, image_t *img, int col, int channel);
Expand Down
8 changes: 4 additions & 4 deletions floatmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#include "rwimg/writeimage.h"

image_t*
floatmap_alloc (int width, int height, pools_t *pools)
floatmap_alloc (int width, int height, mathmap_pools_t *pools)
{
image_t *img = pools_alloc(pools, sizeof(image_t));
image_t *img = mathmap_pools_alloc(pools, sizeof(image_t));

img->type = IMAGE_FLOATMAP;
img->pixel_width = width;
Expand All @@ -39,13 +39,13 @@ floatmap_alloc (int width, int height, pools_t *pools)
img->v.floatmap.ay = img->v.floatmap.by = (float)(height - 1) / 2.0;
img->v.floatmap.ay *= -1.0;

img->v.floatmap.data = pools_alloc(pools, sizeof(float) * width * height * NUM_FLOATMAP_CHANNELS);
img->v.floatmap.data = mathmap_pools_alloc(pools, sizeof(float) * width * height * NUM_FLOATMAP_CHANNELS);

return img;
}

image_t*
floatmap_copy (image_t *floatmap, pools_t *pools)
floatmap_copy (image_t *floatmap, mathmap_pools_t *pools)
{
image_t *copy;

Expand Down
28 changes: 15 additions & 13 deletions llvm_template.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "opmacros.h"
#include "lispreader/pools.h"

$def_mmpools

#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
Expand Down Expand Up @@ -170,7 +172,7 @@ make_color (int r, int g, int b, int a)
}

float*
alloc_tuple (pools_t *pools, int n)
alloc_tuple (mathmap_pools_t *pools, int n)
{
return ALLOC_TUPLE(n);
}
Expand All @@ -182,7 +184,7 @@ tuple_set (float *tuple, int n, float x)
}

tree_vector_t*
alloc_tree_vector (pools_t *pools, int n, float *v)
alloc_tree_vector (mathmap_pools_t *pools, int n, float *v)
{
return new_tree_vector(pools, n, v);
}
Expand All @@ -193,7 +195,7 @@ get_slice_frame (mathmap_slice_t *slice)
return slice->frame;
}

pools_t*
mathmap_pools_t*
get_slice_pools (mathmap_slice_t *slice)
{
return &slice->pools;
Expand Down Expand Up @@ -223,7 +225,7 @@ get_frame_t (mathmap_frame_t *frame)
return frame->current_t;
}

pools_t*
mathmap_pools_t*
get_frame_pools (mathmap_frame_t *frame)
{
return &frame->pools;
Expand Down Expand Up @@ -261,7 +263,7 @@ get_invocation_image_R (mathmap_invocation_t *invocation)

void*
calc_closure_xy_vars (mathmap_invocation_t *invocation, image_t *closure, float t,
void* (*init_frame) (mathmap_invocation_t*, image_t*, float, pools_t*))
void* (*init_frame) (mathmap_invocation_t*, image_t*, float, mathmap_pools_t*))
{
if (!closure->v.closure.xy_vars)
{
Expand Down Expand Up @@ -303,12 +305,12 @@ get_uninited_image (void)
$def_llvm_mathfuncs

image_t*
alloc_closure_image (mathmap_invocation_t *invocation, pools_t *pools, int num_args, filter_func_t filter_func,
alloc_closure_image (mathmap_invocation_t *invocation, mathmap_pools_t *pools, int num_args, filter_func_t filter_func,
llvm_init_frame_func_t init_frame_func, llvm_filter_func_t main_filter_func,
init_x_or_y_func_t init_x_func, init_x_or_y_func_t init_y_func)
{
image_t *image = ALLOC_CLOSURE_IMAGE(num_args);
mathfuncs_t *funcs = (mathfuncs_t*)pools_alloc(pools, sizeof(mathfuncs_t));
mathfuncs_t *funcs = (mathfuncs_t*)mathmap_pools_alloc(pools, sizeof(mathfuncs_t));

#ifdef POOLS_DEBUG_OUTPUT
printf("alloced closure %p from pools %p\n", image, pools);
Expand All @@ -332,9 +334,9 @@ alloc_closure_image (mathmap_invocation_t *invocation, pools_t *pools, int num_a
}

userval_t*
alloc_uservals (pools_t *pools, int num)
alloc_uservals (mathmap_pools_t *pools, int num)
{
return (userval_t*)pools_alloc(pools, sizeof(userval_t) * num);
return (userval_t*)mathmap_pools_alloc(pools, sizeof(userval_t) * num);
}

userval_t*
Expand Down Expand Up @@ -402,25 +404,25 @@ set_closure_pixel_size (image_t *image, int width, int height)
$def_native_filters

image_t*
llvm_native_filter_gaussian_blur (mathmap_invocation_t *invocation, userval_t *args, pools_t *pools)
llvm_native_filter_gaussian_blur (mathmap_invocation_t *invocation, userval_t *args, mathmap_pools_t *pools)
{
return native_filter_gaussian_blur(invocation, args, pools);
}

image_t*
llvm_native_filter_convolve (mathmap_invocation_t *invocation, userval_t *args, pools_t *pools)
llvm_native_filter_convolve (mathmap_invocation_t *invocation, userval_t *args, mathmap_pools_t *pools)
{
return native_filter_convolve(invocation, args, pools);
}

image_t*
llvm_native_filter_half_convolve (mathmap_invocation_t *invocation, userval_t *args, pools_t *pools)
llvm_native_filter_half_convolve (mathmap_invocation_t *invocation, userval_t *args, mathmap_pools_t *pools)
{
return native_filter_half_convolve(invocation, args, pools);
}

image_t*
llvm_native_filter_visualize_fft (mathmap_invocation_t *invocation, userval_t *args, pools_t *pools)
llvm_native_filter_visualize_fft (mathmap_invocation_t *invocation, userval_t *args, mathmap_pools_t *pools)
{
return native_filter_visualize_fft(invocation, args, pools);
}
Expand Down
Loading

0 comments on commit 642d65c

Please sign in to comment.