Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commonfns&vectors&basic:initialize the output buffer to zeros #1894

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test_conformance/basic/test_basic_parameter_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int test_parameter_types_long(cl_device_id device, cl_context context,
clMemWrapper results;
int error;
size_t global[3] = { 1, 1, 1 };
float results_back[2 * 16];
float results_back[2 * 16] = { 0.0f };
int count, index;
const char *types[] = { "long", "ulong" };
char kernel_string[8192];
Expand Down Expand Up @@ -85,8 +85,8 @@ int test_parameter_types_long(cl_device_id device, cl_context context,
test_error(error, "Unable to get max parameter size from device");

// Create the results buffer
results = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(cl_float) * 2 * 16, NULL, &error);
results = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(cl_float) * 2 * 16, results_back, &error);
test_error(error, "clCreateBuffer failed");

// Go over all the vector sizes
Expand Down Expand Up @@ -202,7 +202,7 @@ int test_parameter_types(cl_device_id device, cl_context context,
clMemWrapper results;
int error;
size_t global[3] = { 1, 1, 1 };
float results_back[7 * 16];
float results_back[7 * 16] = { 0.0f };
int count, index;
const char *types[] = { "char", "uchar", "short", "ushort",
"int", "uint", "float" };
Expand Down Expand Up @@ -248,8 +248,8 @@ int test_parameter_types(cl_device_id device, cl_context context,
test_error(error, "Unable to get max parameter size from device");

// Create the results buffer
results = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(cl_float) * 7 * 16, NULL, &error);
results = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(cl_float) * 7 * 16, results_back, &error);
test_error(error, "clCreateBuffer failed");

// Go over all the vector sizes
Expand Down
43 changes: 24 additions & 19 deletions test_conformance/basic/test_numeric_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ int test_kernel_numeric_constants(cl_device_id deviceID, cl_context context, cl_
cl_mem streams[3];

size_t threads[] = {1,1,1};
cl_float float_out[16];
cl_int int_out[19];
cl_uint uint_out[1];
cl_long long_out[7];
cl_ulong ulong_out[1];
cl_double double_out[16];
cl_float float_out[16] = { 0.0f };
cl_int int_out[19] = { 0 };
cl_uint uint_out[1] = { 0 };
cl_long long_out[7] = { 0 };
cl_ulong ulong_out[1] = { 0 };
cl_double double_out[16] = { 0.0 };

/** INTs and FLOATs **/

Expand All @@ -242,14 +242,17 @@ int test_kernel_numeric_constants(cl_device_id deviceID, cl_context context, cl_
}

/* Create some I/O streams */
streams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float_out),
NULL, &error);
streams[0] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(float_out), float_out, &error);
test_error( error, "Creating test array failed" );
streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int_out),
NULL, &error);
streams[1] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(int_out), int_out, &error);
test_error( error, "Creating test array failed" );
streams[2] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(uint_out),
NULL, &error);
streams[2] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(uint_out), uint_out, &error);
test_error( error, "Creating test array failed" );

error = clSetKernelArg(kernel, 1, sizeof( streams[1] ), &streams[1]);
Expand Down Expand Up @@ -534,17 +537,19 @@ int test_kernel_limit_constants(cl_device_id deviceID, cl_context context, cl_co
int error;
size_t threads[] = {1,1,1};
clMemWrapper intStream, floatStream, doubleStream;
cl_int intOut[ 32 ];
cl_float floatOut[ 3 ];
cl_double doubleOut[ 1 ];
cl_int intOut[32] = { 0 };
cl_float floatOut[3] = { 0.0f };
cl_double doubleOut[1] = { 0.0 };


/* Create some I/O streams */
intStream = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(intOut), NULL,
&error);
intStream =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(intOut), intOut, &error);
test_error( error, "Creating test array failed" );
floatStream = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(floatOut),
NULL, &error);
floatStream =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(floatOut), floatOut, &error);
test_error( error, "Creating test array failed" );

// Stage 1: basic limits on MAXFLOAT
Expand Down
10 changes: 9 additions & 1 deletion test_conformance/commonfns/test_binary_fn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,22 @@ int test_binary_fn(cl_device_id device, cl_context context,

for (i = 0; i < 2; i++) input_ptr[i].resize(num_elements);
output_ptr.resize(num_elements);
// Initialized output buffers to zero to prevent undefined behavior
// As their sizes exceed the number of work items in the kernel.
output_ptr.assign(num_elements, 0);

for( i = 0; i < 3; i++ )
for (i = 0; i < 2; i++)
{
streams[i] = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(T) * num_elements, NULL, &err);
test_error( err, "clCreateBuffer failed");
}

streams[2] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * num_elements, &output_ptr[0], &err);
test_error(err, "clCreateBuffer failed");

std::string pragma_str;
if (std::is_same<T, float>::value)
{
Expand Down
9 changes: 8 additions & 1 deletion test_conformance/commonfns/test_clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,20 @@ int test_clamp_fn(cl_device_id device, cl_context context,

for (i = 0; i < 3; i++) input_ptr[i].resize(num_elements);
output_ptr.resize(num_elements);
// Initialized output buffers to zero to prevent undefined behavior
// As their sizes exceed the number of work items in the kernel.
output_ptr.assign(num_elements, 0);

for (i = 0; i < 4; i++)
for (i = 0; i < 3; i++)
{
streams[i] = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(T) * num_elements, NULL, &err);
test_error(err, "clCreateBuffer failed");
}
streams[3] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * num_elements, &output_ptr[0], &err);
test_error(err, "clCreateBuffer failed");

if (std::is_same<T, float>::value)
{
Expand Down
9 changes: 8 additions & 1 deletion test_conformance/commonfns/test_mix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,20 @@ int test_mix_fn(cl_device_id device, cl_context context, cl_command_queue queue,

for (i = 0; i < 3; i++) input_ptr[i].resize(num_elements);
output_ptr.resize(num_elements);
// Initialized output buffers to zero to prevent undefined behavior
// As their sizes exceed the number of work items in the kernel.
output_ptr.assign(num_elements, 0);

for (i = 0; i < 4; i++)
for (i = 0; i < 3; i++)
{
streams[i] = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(T) * num_elements, NULL, &err);
test_error(err, "clCreateBuffer failed");
}
streams[3] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * num_elements, &output_ptr[0], &err);
test_error(err, "clCreateBuffer failed");

std::string pragma_str;
if (std::is_same<T, double>::value)
Expand Down
9 changes: 8 additions & 1 deletion test_conformance/commonfns/test_smoothstep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,20 @@ int test_smoothstep_fn(cl_device_id device, cl_context context,

for (i = 0; i < 3; i++) input_ptr[i].resize(num_elements);
output_ptr.resize(num_elements);
// Initialized output buffers to zero to prevent undefined behavior
// As their sizes exceed the number of work items in the kernel.
output_ptr.assign(num_elements, 0);

for (i = 0; i < 4; i++)
for (i = 0; i < 3; i++)
{
streams[i] = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(T) * num_elements, NULL, &err);
test_error(err, "clCreateBuffer failed");
}
streams[3] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * num_elements, &output_ptr[0], &err);
test_error(err, "clCreateBuffer failed");

std::string pragma_str;
if (std::is_same<T, float>::value)
Expand Down
10 changes: 9 additions & 1 deletion test_conformance/commonfns/test_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,22 @@ int test_step_fn(cl_device_id device, cl_context context,

for (i = 0; i < 2; i++) input_ptr[i].resize(num_elements);
output_ptr.resize(num_elements);
// Initialized output buffers to zero to prevent undefined behavior
// As their sizes exceed the number of work items in the kernel.
output_ptr.assign(num_elements, 0);

for (i = 0; i < 3; i++)
for (i = 0; i < 2; i++)
{
streams[i] = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(T) * num_elements, NULL, &err);
test_error(err, "clCreateBuffer failed");
}

streams[2] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * num_elements, &output_ptr[0], &err);
test_error(err, "clCreateBuffer failed");

std::string pragma_str;
if (std::is_same<T, float>::value)
{
Expand Down
19 changes: 12 additions & 7 deletions test_conformance/commonfns/test_unary_fn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,18 @@ int test_unary_fn(cl_device_id device, cl_context context,

input_ptr.resize(num_elements);
output_ptr.resize(num_elements);

for (i = 0; i < 2; i++)
{
streams[i] = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(T) * num_elements, NULL, &err);
test_error(err, "clCreateBuffer failed");
}
// Initialized output buffers to zero to prevent undefined behavior
// As their sizes exceed the number of work items in the kernel.
output_ptr.assign(num_elements, 0);

streams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(T) * num_elements, NULL, &err);
test_error(err, "clCreateBuffer failed");

streams[1] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE,
sizeof(T) * num_elements, &output_ptr[0], &err);
test_error(err, "clCreateBuffer failed");

std::string pragma_str;
if (std::is_same<T, float>::value)
Expand Down
6 changes: 5 additions & 1 deletion test_conformance/vectors/structs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ bufferStruct *newBufferStruct(size_t inSize, size_t outSize, clState *pClState)

pResult->m_pIn = malloc(inSize);
pResult->m_pOut = malloc(outSize);
// Initialized output buffers to zero to prevent undefined behavior
// As their sizes exceed the number of work items in the kernel.
memset(pResult->m_pOut, 0, outSize);
#if DEBUG_MEM_ALLOC
log_info("malloc m_pIn %x\n", pResult->m_pIn);
log_info("malloc m_pOut %x\n", pResult->m_pOut);
Expand All @@ -137,7 +140,8 @@ bufferStruct *newBufferStruct(size_t inSize, size_t outSize, clState *pClState)
#endif

pResult->m_outBuffer = clCreateBuffer(
pClState->m_context, CL_MEM_WRITE_ONLY, outSize, NULL, &error);
pClState->m_context, CL_MEM_COPY_HOST_PTR | CL_MEM_WRITE_ONLY, outSize,
pResult->m_pOut, &error);
if (pResult->m_outBuffer == NULL)
{
vlog_error("clCreateArray failed for output (%d)\n", error);
Expand Down
Loading