[gegl] Changed data types in cl-random producing differences with gegl-random
- From: Téo Mazars <teom src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] Changed data types in cl-random producing differences with gegl-random
- Date: Thu, 31 Oct 2013 11:01:15 +0000 (UTC)
commit 426a315c69d0751ef25e3be19aee00c0d8396d16
Author: Carlos Zubieta <czubieta dev gmail com>
Date: Mon Sep 9 18:16:45 2013 -0500
Changed data types in cl-random producing differences with gegl-random
gegl/opencl/gegl-cl-init.c | 4 +-
opencl/random.cl | 96 +++++-------------------------------------
opencl/random.cl.h | 98 ++++++--------------------------------------
3 files changed, 27 insertions(+), 171 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 0d39202..9ac6fc5 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -446,8 +446,8 @@ gegl_cl_compile_and_build (const char *program_source, const char *kernel_name[]
if ((cl_data = (GeglClRunData *)g_hash_table_lookup(cl_program_hash, program_source)) == NULL)
{
- const size_t lengths[] = {strlen(cl_random_source), strlen(program_source)};
- const char *sources[] = {cl_random_source , program_source};
+ const size_t lengths[] = {strlen(random_cl_source), strlen(program_source)};
+ const char *sources[] = {random_cl_source , program_source};
gint i;
guint kernel_n = 0;
diff --git a/opencl/random.cl b/opencl/random.cl
index 86b4b3b..77f5320 100644
--- a/opencl/random.cl
+++ b/opencl/random.cl
@@ -22,9 +22,9 @@
#define NPRIME 101111
#define RANDOM_DATA_SIZE (15083+15091+15101)
-#define PRIME_SIZE 533
+#define PRIME_SIZE 533u
-static inline int
+inline uint
_gegl_cl_random_int (__global const int *cl_random_data,
__global const long *cl_random_primes,
int seed,
@@ -40,16 +40,16 @@ _gegl_cl_random_int (__global const int *cl_random_data,
/* 3 rounds gives a reasonably high cycle for */
/* our synthesized larger random set. */
unsigned long seed_idx = seed % (PRIME_SIZE - 1 - ROUNDS);
- int prime0 = convert_int(cl_random_primes[seed_idx]),
- prime1 = convert_int(cl_random_primes[seed_idx+1]),
- prime2 = convert_int(cl_random_primes[seed_idx+2]);
+ int prime0 = cl_random_primes[seed_idx],
+ prime1 = cl_random_primes[seed_idx+1],
+ prime2 = cl_random_primes[seed_idx+2];
int r0 = cl_random_data[idx % prime0],
r1 = cl_random_data[prime0 + (idx % (prime1))],
r2 = cl_random_data[prime0 + prime1 + (idx % (prime2))];
return r0 ^ r1 ^ r2;
}
-int
+uint
gegl_cl_random_int (__global const int *cl_random_data,
__global const long *cl_random_primes,
int seed,
@@ -73,48 +73,13 @@ gegl_cl_random_int_range (__global const int *cl_random_data,
int min,
int max)
{
- int ret = _gegl_cl_random_int (cl_random_data, cl_random_primes,
- seed, x, y, z, n);
- return (ret % (max-min)) + min;
-}
-
-int4
-gegl_cl_random_int4 (__global const int *cl_random_data,
- __global const long *cl_random_primes,
- int seed,
- int x,
- int y,
- int z,
- int n)
-{
- int r0 = _gegl_cl_random_int(cl_random_data, cl_random_primes,
- seed, x, y, z, n);
- int r1 = _gegl_cl_random_int(cl_random_data, cl_random_primes,
- seed, x, y, z, n+1);
- int r2 = _gegl_cl_random_int(cl_random_data, cl_random_primes,
- seed, x, y, z, n+2);
- int r3 = _gegl_cl_random_int(cl_random_data, cl_random_primes,
- seed, x, y, z, n+3);
- return (int4)(r0, r1, r2, r3);
-}
-
-int4
-gegl_cl_random_int4_range (__global const int *cl_random_data,
- __global const long *cl_random_primes,
- int seed,
- int x,
- int y,
- int z,
- int n,
- int min,
- int max)
-{
- int4 ret = gegl_cl_random_int4 (cl_random_data, cl_random_primes,
+ uint ret = _gegl_cl_random_int (cl_random_data, cl_random_primes,
seed, x, y, z, n);
return (ret % (max-min)) + min;
}
-#define G_RAND_FLOAT_TRANSFORM 0.00001525902189669642175f
+
+#define G_RAND_FLOAT_TRANSFORM 0.00001525902189669642175
float
gegl_cl_random_float (__global const int *cl_random_data,
@@ -125,9 +90,9 @@ gegl_cl_random_float (__global const int *cl_random_data,
int z,
int n)
{
- int u = _gegl_cl_random_int (cl_random_data, cl_random_primes,
- seed, x, y, z, n);
- return convert_float(u & 0xffff) * G_RAND_FLOAT_TRANSFORM;
+ uint u = _gegl_cl_random_int (cl_random_data, cl_random_primes,
+ seed, x, y, z, n);
+ return (u & 0xffff) * G_RAND_FLOAT_TRANSFORM;
}
float
@@ -145,40 +110,3 @@ gegl_cl_random_float_range (__global const int *cl_random_data,
seed, x, y, z, n);
return f * (max - min) + min;
}
-/*
-float4
-gegl_cl_random_float4 (__global const int *cl_random_data,
- __global const long *cl_random_primes,
- int seed,
- int x,
- int y,
- int z,
- int n)
-{
- float r0 = gegl_cl_random_float(cl_random_data, cl_random_primes,
- seed x, y, z, n);
- float r1 = gegl_cl_random_float(cl_random_data, cl_random_primes,
- seed x, y, z, n+1);
- float r2 = gegl_cl_random_float(cl_random_data, cl_random_primes,
- seed x, y, z, n+2);
- float r3 = gegl_cl_random_float(cl_random_data, cl_random_primes,
- seed x, y, z, n+3);
- return (float4)(r0, r1, r2, r3);
-}
-
-float4
-gegl_cl_random_float4_range (__global const int *cl_random_data,
- __global const long *cl_random_primes,
- int seed,
- int x,
- int y,
- int z,
- int n,
- float min,
- float max)
-{
- float4 f = gegl_cl_random_float4 (cl_random_data, cl_random_primes,
- seed, x, y, z, n);
- return f4 * (float4)((max - min) + min);
-}
-*/
diff --git a/opencl/random.cl.h b/opencl/random.cl.h
index d5b651d..a0e7a63 100644
--- a/opencl/random.cl.h
+++ b/opencl/random.cl.h
@@ -1,4 +1,4 @@
-static const char* cl_random_source =
+static const char* random_cl_source =
"/* This file is part of GEGL \n"
" * \n"
" * GEGL is free software; you can redistribute it and/or \n"
@@ -23,9 +23,9 @@ static const char* cl_random_source =
"#define NPRIME 101111 \n"
" \n"
"#define RANDOM_DATA_SIZE (15083+15091+15101) \n"
-"#define PRIME_SIZE 533 \n"
+"#define PRIME_SIZE 533u \n"
" \n"
-"static inline int \n"
+"inline uint \n"
"_gegl_cl_random_int (__global const int *cl_random_data, \n"
" __global const long *cl_random_primes, \n"
" int seed, \n"
@@ -41,16 +41,16 @@ static const char* cl_random_source =
" /* 3 rounds gives a reasonably high cycle for */ \n"
" /* our synthesized larger random set. */ \n"
" unsigned long seed_idx = seed % (PRIME_SIZE - 1 - ROUNDS); \n"
-" int prime0 = convert_int(cl_random_primes[seed_idx]), \n"
-" prime1 = convert_int(cl_random_primes[seed_idx+1]), \n"
-" prime2 = convert_int(cl_random_primes[seed_idx+2]); \n"
+" int prime0 = cl_random_primes[seed_idx], \n"
+" prime1 = cl_random_primes[seed_idx+1], \n"
+" prime2 = cl_random_primes[seed_idx+2]; \n"
" int r0 = cl_random_data[idx % prime0], \n"
" r1 = cl_random_data[prime0 + (idx % (prime1))], \n"
" r2 = cl_random_data[prime0 + prime1 + (idx % (prime2))]; \n"
" return r0 ^ r1 ^ r2; \n"
"} \n"
" \n"
-"int \n"
+"uint \n"
"gegl_cl_random_int (__global const int *cl_random_data, \n"
" __global const long *cl_random_primes, \n"
" int seed, \n"
@@ -74,48 +74,13 @@ static const char* cl_random_source =
" int min, \n"
" int max) \n"
"{ \n"
-" int ret = _gegl_cl_random_int (cl_random_data, cl_random_primes, \n"
-" seed, x, y, z, n); \n"
-" return (ret % (max-min)) + min; \n"
-"} \n"
-" \n"
-"int4 \n"
-"gegl_cl_random_int4 (__global const int *cl_random_data, \n"
-" __global const long *cl_random_primes, \n"
-" int seed, \n"
-" int x, \n"
-" int y, \n"
-" int z, \n"
-" int n) \n"
-"{ \n"
-" int r0 = _gegl_cl_random_int(cl_random_data, cl_random_primes, \n"
-" seed, x, y, z, n); \n"
-" int r1 = _gegl_cl_random_int(cl_random_data, cl_random_primes, \n"
-" seed, x, y, z, n+1); \n"
-" int r2 = _gegl_cl_random_int(cl_random_data, cl_random_primes, \n"
-" seed, x, y, z, n+2); \n"
-" int r3 = _gegl_cl_random_int(cl_random_data, cl_random_primes, \n"
-" seed, x, y, z, n+3); \n"
-" return (int4)(r0, r1, r2, r3); \n"
-"} \n"
-" \n"
-"int4 \n"
-"gegl_cl_random_int4_range (__global const int *cl_random_data, \n"
-" __global const long *cl_random_primes, \n"
-" int seed, \n"
-" int x, \n"
-" int y, \n"
-" int z, \n"
-" int n, \n"
-" int min, \n"
-" int max) \n"
-"{ \n"
-" int4 ret = gegl_cl_random_int4 (cl_random_data, cl_random_primes, \n"
+" uint ret = _gegl_cl_random_int (cl_random_data, cl_random_primes, \n"
" seed, x, y, z, n); \n"
" return (ret % (max-min)) + min; \n"
"} \n"
" \n"
-"#define G_RAND_FLOAT_TRANSFORM 0.00001525902189669642175f \n"
+" \n"
+"#define G_RAND_FLOAT_TRANSFORM 0.00001525902189669642175 \n"
" \n"
"float \n"
"gegl_cl_random_float (__global const int *cl_random_data, \n"
@@ -126,9 +91,9 @@ static const char* cl_random_source =
" int z, \n"
" int n) \n"
"{ \n"
-" int u = _gegl_cl_random_int (cl_random_data, cl_random_primes, \n"
-" seed, x, y, z, n); \n"
-" return convert_float(u & 0xffff) * G_RAND_FLOAT_TRANSFORM; \n"
+" uint u = _gegl_cl_random_int (cl_random_data, cl_random_primes, \n"
+" seed, x, y, z, n); \n"
+" return (u & 0xffff) * G_RAND_FLOAT_TRANSFORM; \n"
"} \n"
" \n"
"float \n"
@@ -147,40 +112,3 @@ static const char* cl_random_source =
" return f * (max - min) + min; \n"
"} \n"
;
-/*
-float4
-gegl_cl_random_float4 (__global const int *cl_random_data,
- __global const long *cl_random_primes,
- int seed,
- int x,
- int y,
- int z,
- int n)
-{
- float r0 = gegl_cl_random_float(cl_random_data, cl_random_primes,
- seed x, y, z, n);
- float r1 = gegl_cl_random_float(cl_random_data, cl_random_primes,
- seed x, y, z, n+1);
- float r2 = gegl_cl_random_float(cl_random_data, cl_random_primes,
- seed x, y, z, n+2);
- float r3 = gegl_cl_random_float(cl_random_data, cl_random_primes,
- seed x, y, z, n+3);
- return (float4)(r0, r1, r2, r3);
-}
-
-float4
-gegl_cl_random_float4_range (__global const int *cl_random_data,
- __global const long *cl_random_primes,
- int seed,
- int x,
- int y,
- int z,
- int n,
- float min,
- float max)
-{
- float4 f = gegl_cl_random_float4 (cl_random_data, cl_random_primes,
- seed, x, y, z, n);
- return f4 * (float4)((max - min) + min);
-}
-*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]