Added elliptical power law model with shear

// elliptical power law profile lens (Tessore & Metcalf 2015)

type = LENS;

params
{
    { "x",  POSITION_X              },
    { "y",  POSITION_Y              },
    { "r",  RADIUS                  },
    { "t",  PARAMETER, { 0.f, 2.f } },
    { "q",  AXIS_RATIO              },
    { "pa", POS_ANGLE               },
    { "g1", PARAMETER               },
    { "g2", PARAMETER               }
};

data
{
    float2 x; // lens position
    mat22 m;  // rotation matrix for position angle
    mat22 w;  // inverse rotation matrix
    mat22 g;  // shear matrix
    float b;  // scale length
    float t;  // slope
    float f;  // second flattening of ellipse
    float n;  // normalisation
};

static float2 deflection(constant data* this, float2 x)
{
    float r, phi;
    float2 a, A;
    float c, s, c2, s2;
    mat22 R;

    const float T = 2 - this->t;
    const float f = this->f;

    float2 dx = x - this->x;

    // translate to central coordinates
    // rotate by position angle and make elliptical
    x = mv22(this->m, dx);

    // elliptical radius and polar angle
    r = length(x);
    phi = atan2(x.y, x.x);

    // sines and cosines
    s = sincos(phi, &c);
    s2 = sincos(2*phi, &c2);

    // rotation matrix
    R = (mat22)(c2, -s2, s2, c2);

    // angular part of deflection, up to tenth order
    a  = A = (float2)(c, s);
    a += A = -f*(2* 1 - T)/(2* 1 + T)*mv22(R, A);
    a += A = -f*(2* 2 - T)/(2* 2 + T)*mv22(R, A);
    a += A = -f*(2* 3 - T)/(2* 3 + T)*mv22(R, A);
    a += A = -f*(2* 4 - T)/(2* 4 + T)*mv22(R, A);
    a += A = -f*(2* 5 - T)/(2* 5 + T)*mv22(R, A);
    a += A = -f*(2* 6 - T)/(2* 6 + T)*mv22(R, A);
    a += A = -f*(2* 7 - T)/(2* 7 + T)*mv22(R, A);
    a += A = -f*(2* 8 - T)/(2* 8 + T)*mv22(R, A);
    a += A = -f*(2* 9 - T)/(2* 9 + T)*mv22(R, A);
    a += A = -f*(2*10 - T)/(2*10 + T)*mv22(R, A);

    // radial part of deflection
    a *= this->n*powr(r, 1-this->t);

    // reverse coordinate rotation
    float2 y = mv22(this->w, a);

    // add shear
    return y + mv22(this->g, dx);
}

static void set(global data* this,
                float x1, float x2, float r, float t, float q, float pa, float g1, float g2)
{
    float c;
    float s = sincos(pa*DEG2RAD, &c);

    // lens position
    this->x = (float2)(x1, x2);

    // rotation matrix with elliptical factor and scaling
    this->m = (1/r)*(mat22)(q*c, q*s, -s, c);

    // inverse rotation matrix
    this->w = (mat22)(c, -s, s, c);

    // slope of power law profile
    this->t = t;

    // second flattening of ellipse with axis ratio q
    this->f = (1 - q)/(1 + q);

    // normalisation of deflection
    this->n = 2*r*sqrt(q)/(1 + q);

    // shear matrix
    this->g = (mat22)(g1,g2,g2,-g1);
}

error: pathspec 'objects/epl_plus_shear.cl' did not match any file(s) known to git


added cl sample code folder

added cl sample code folder

const sampler_t samp =
	CLK_NORMALIZED_COORDS_FALSE|
	CLK_ADDRESS_REPEAT|
	CLK_FILTER_NEAREST;
__kernel void main(
	__global read_only image3d_t data,
	__global unsigned char* result,
	unsigned int x,
	unsigned int y,
	unsigned int z)
{
	int4 coord = (int4)(get_global_id(0),
		get_global_id(1), get_global_id(2), 1);
	float4 dvalue = read_imagef(data, samp, coord);
	unsigned int index = x*y*coord.z + x*coord.y + coord.x;
	result[index] = dvalue.x*255.0;
}

error: pathspec 'CL_code/copy.cl' did not match any file(s) known to git


Added test case for static memory collection to different address spaces.

// RUN: echo "Compiling with nvptx target to get IR with proper address spaces. With llvm 3.3 maybe could be changed to SPIR." &&
// RUN: TARGET_FLAGS="-target nvptx" $OCLANG $TEST_SRC -S -O0 -o $OUT_FILE.ll &&
// RUN: opt -load $CLAMP_PLUGIN -clamp-pointers -allow-unsafe-exceptions -S $OUT_FILE.ll -o $OUT_FILE.clamped.ll &&
// RUN: if ! grep "@AddressSpace0StaticData" $OUT_FILE.clamped.ll > /dev/null; then echo "Private address space was not found." && false; fi &&
// RUN: if grep "@AddressSpace1StaticData" $OUT_FILE.clamped.ll > /dev/null; then echo "No static allocations from global AS allowed." && false; fi &&
// RUN: if ! grep "@AddressSpace3StaticData" $OUT_FILE.clamped.ll > /dev/null; then echo "Local address space was not found." && false; fi &&
// RUN: if ! grep "@AddressSpace4StaticData" $OUT_FILE.clamped.ll > /dev/null; then echo "Constant address space was not found." && false; fi

typedef struct {
  int i;
  long l;
  float f;
} test_struct;

// Actually this is not allowed in OpenCL ( kernel cannot allocate from global )
/* __global float test_global[3] = { 1, 2, 3 }; */

__constant float test_constant[3] = { 1, 2, 3 };
__private float private_float = 1;
__local float local_float;

__kernel void test(__global float* in, __global float* out) {
  unsigned int i = 1; //get_global_id(0);
  // compiler does not allow this..
  /* __constant float constant_zero = 0; */
  __local float test_local[3];
  float test_private[3] = { 1, 2, 3 };
  __private float test_private2[3] = { 1, 2, 3 };
  __local test_struct struct_table[3];

  //  __global float* another_test_global[3];
  //  __global float* global_test_val_float;
  //  __private test_struct private_struct_table[3];
  //  __global test_struct* global_struct_table[3];

  __global float *test = in;
  test_local[i] = test[i];
  // test = out; // uncomment this to fail simple data dependency check
  test_local[i] = test[i];

  test_local[i] = in[i];
  out[i] = in[i];
  struct_table[i].f = test_local[i];
  struct_table[i].l = struct_table[i].f;
}

error: pathspec 'tests/test_static_memory_consolidation.cl' did not match any file(s) known to git


added asp tests

added asp tests

#const width = 500.
#const height = 500.

polyline(0,0,0).
polyline(1,60,0).
polyline(2,60,40).
polyline(3,0,40).

inside(0, 1, bottom).
inside(1, 2, left).
inside(2, 3, top).
inside(3, 0, right).

coordinates(-width..width).

tileIds(0..1).

tileSize(wall1, 11, 8). % Wall1 / vertical
tileSize(wall1_2, 11, 8). % Wall1_2
tileSize(wall2, 13, 6). % Wall2 / vertical
tileSize(wall2_2, 13, 6).
tileSize(wall3, 10, 9). % Wall3 / horizontal
tileSize(wall3_2, 10, 9).
tileSize(wall4, 12, 9). % Wall4 / horizontal / vertical
tileSize(wall4_2, 12, 9).
tileSize(wall5, 16, 8). % Wall5 / horizontal
tileSize(wall5_2, 16, 8).
tileSize(wall6, 13, 7). % Wall6 / horizontal
tileSize(wall6_2, 13, 7).

tileBaselinePoly(wall1, topLeft, 3, 2).
tileBaselinePoly(wall1, bottomRight, 8, 8).
tileBaselinePoly(wall1_2, topLeft, 3, 2).
tileBaselinePoly(wall1_2, bottomRight, 8, 8).

tileBaselinePoly(wall2, topLeft, 3, 2).
tileBaselinePoly(wall2, bottomRight, 8, 8).
tileBaselinePoly(wall2_2, topLeft, 3, 2).
tileBaselinePoly(wall2_2, bottomRight, 8, 8).

tileBaselinePoly(wall3, topLeft, 3, 2).
tileBaselinePoly(wall3, bottomRight, 8, 8).
tileBaselinePoly(wall3_2, topLeft, 2, 2).
tileBaselinePoly(wall3_2, bottomRight, 7, 8).

tileBaselinePoly(wall4, topLeft, 3, 2).
tileBaselinePoly(wall4, bottomRight, 8, 8).
tileBaselinePoly(wall4_2, topLeft, 2, 2).
tileBaselinePoly(wall4_2, bottomRight, 7, 8).

tileBaselinePoly(wall5, topLeft, 3, 2).
tileBaselinePoly(wall5, bottomRight, 8, 8).
tileBaselinePoly(wall5_2, topLeft, 2, 2).
tileBaselinePoly(wall5_2, bottomRight, 7, 8).

tileBaselinePoly(wall6, topLeft, 3, 2).
tileBaselinePoly(wall6, bottomRight, 8, 8).
tileBaselinePoly(wall6_2, topLeft, 2, 2).
tileBaselinePoly(wall6_2, bottomRight, 7, 8).

polyIds(PId) :- polyline(PId, _, _).

nextPoly(N, X, Y) :- polyline(N+1, X, Y) ; N != 3.
nextPoly(3, X, Y) :- polyline(0, X, Y).

initInstance(0, 0, X, Y, TileId) :-
	coordinates(X), coordinates(Y)
	, polyline(0, X1, Y1)
	, nextPoly(0, X2, Y2)
	, tileBaselinePoly(TileId, bottomRight, BaselineX, BaselineY)
	, X + BaselineX == X1, Y + BaselineY == Y1
	.

initInstance(N, 0, X, Y, TileId) :-
	coordinates(X), coordinates(Y)
	, initInstance(N-1, 0, OldX, OldY, OldTileId)

	, tileBaselinePoly(OldTileId, bottomRight, OldBaselineX, OldBaselineY)
	, tileSize(OldTileId, OldW, OldH)

	, polyline(0, X1, Y1)
	, nextPoly(0, X2, Y1)
	, tileSize(TileId, W, H)
	, tileBaselinePoly(TileId, bottomRight, BaselineX, BaselineY)
	, 1 { X + BaselineX == X2; X + BaselineX < X2 }
	, Y + BaselineY == Y1
	, X >= OldX + OldBaselineX
	, X <= OldX + OldW
	.

1 { instances(N, 0, X, Y, TileId) : initInstance(N, 0, X, Y, TileId) }.

:- instances(N, 0, X, Y, TileId), instances(N, 0, X2, Y2, TileId2)
	, 1 { X != X2; Y != Y2; TileId != TileId2 }
	.

corner(N, 0, X, Y, TileId) :- instances(N, 0, X, Y, TileId)
	, polyline(0, X1, Y1)
	, nextPoly(0, X2, Y1)
	, tileSize(TileId, W, H)
	, tileBaselinePoly(TileId, bottomRight, BaselineX, BaselineY)
	, X + BaselineX == X2
	.

:- instances(N, 0, X, Y, TileId), not corner(N, 0, X, Y, TileId).

#show instances/5.
#show corner/5.
%#show pointsOccupied/2.

error: pathspec 'tools/tests/input.cl' did not match any file(s) known to git


"always shadow boxing"

"always shadow boxing"

started to work on an sbcl interface to callEmulator but got bored by the idea
of setting up another boatload of arrays for in-data, out-data etc. lame

(cl:defpackage "CALL-EMULATOR" (:use "CL" "SB-ALIEN" "SB-C-CALL"))
(cl:in-package "CALL-EMULATOR")

(defparameter *nmodel-points* 10)
(defparameter *nemu-points* 40)

;;; Define the lisp function interface to the C routine
;;; not sure about the declaim call
(declaim (inline callEmulator))
(define-alien-routine callEmulator
		(void)
	(xmodel-in (* (array double *nmodel-points*)))
	(nparams-in (* int))
	(training-in (* (array double *nmodel-points*)))
	(nmodelpts (* int))
	(nthetas-in (* int))
	(final-emulated-x (* (array double *nemu-points*)))
	(nemupts-in (* int))
	(final-emulated-y (* (array double *nemu-points*)))
	(final-emulated-var (* (array double *nemu-points*)))
	(range-min  (* double))
	(range-max (* double)))

;;;  a function which sets up the values we want to pass
;;; and then actually calls the emulator
(defun call-emulator ()
	...

error: pathspec 'src/call-sblc.cl' did not match any file(s) known to git