mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-22 15:19:02 +00:00
Synchronise with Khronos-private Gitlab branch
The maintenance of the conformance tests is moving to Github. This commit contains all the changes that have been done in Gitlab since the first public release of the conformance tests. Signed-off-by: Kevin Petit <kevin.petit@arm.com>
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
project
|
||||
: requirements
|
||||
<toolset>gcc:<cflags>-xc++
|
||||
<toolset>msvc:<cflags>"/TP"
|
||||
;
|
||||
|
||||
exe test_buffers
|
||||
: array_info.c
|
||||
main.c
|
||||
test_buffer_copy.c
|
||||
test_buffer_map.c
|
||||
test_buffer_mem.c
|
||||
test_buffer_read.c
|
||||
test_buffer_write.c
|
||||
test_buffer_fill.c
|
||||
: <library>../..//glew
|
||||
;
|
||||
|
||||
install dist
|
||||
: test_buffers
|
||||
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/buffers
|
||||
<variant>release:<location>$(DIST)/release/tests/test_conformance/buffers
|
||||
;
|
||||
|
||||
project
|
||||
: requirements
|
||||
<toolset>gcc:<cflags>-xc++
|
||||
<toolset>msvc:<cflags>"/TP"
|
||||
;
|
||||
|
||||
exe test_buffers
|
||||
: array_info.c
|
||||
main.c
|
||||
test_buffer_copy.c
|
||||
test_buffer_map.c
|
||||
test_buffer_mem.c
|
||||
test_buffer_read.c
|
||||
test_buffer_write.c
|
||||
test_buffer_fill.c
|
||||
: <library>../..//glew
|
||||
;
|
||||
|
||||
install dist
|
||||
: test_buffers
|
||||
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/buffers
|
||||
<variant>release:<location>$(DIST)/release/tests/test_conformance/buffers
|
||||
;
|
||||
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
ifdef BUILD_WITH_ATF
|
||||
ATF = -framework ATF
|
||||
USE_ATF = -DUSE_ATF
|
||||
endif
|
||||
|
||||
SRCS = main.c test_buffer_copy.c test_buffer_read.c test_buffer_write.c \
|
||||
test_buffer_mem.c array_info.c test_buffer_map.c \
|
||||
test_sub_buffers.cpp test_buffer_fill.c \
|
||||
test_buffer_migrate.c test_image_migrate.c \
|
||||
../../test_common/harness/errorHelpers.c \
|
||||
../../test_common/harness/threadTesting.c \
|
||||
../../test_common/harness/testHarness.c \
|
||||
../../test_common/harness/kernelHelpers.c \
|
||||
../../test_common/harness/conversions.c \
|
||||
../../test_common/harness/mt19937.c \
|
||||
../../test_common/harness/typeWrappers.cpp
|
||||
|
||||
|
||||
|
||||
DEFINES =
|
||||
|
||||
SOURCES = $(abspath $(SRCS))
|
||||
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
|
||||
LIBPATH += -L.
|
||||
FRAMEWORK = $(SOURCES)
|
||||
HEADERS =
|
||||
TARGET = test_buffers
|
||||
INCLUDE =
|
||||
COMPILERFLAGS = -c -Wall -g -O0 -Wshorten-64-to-32
|
||||
CC = c++
|
||||
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%)
|
||||
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%)
|
||||
LIBRARIES = -framework OpenCL -framework AppKit ${ATF}
|
||||
|
||||
OBJECTS := ${SOURCES:.c=.o}
|
||||
OBJECTS := ${OBJECTS:.cpp=.o}
|
||||
|
||||
TARGETOBJECT =
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(RC_CFLAGS) $(OBJECTS) -o $@ $(LIBPATH) $(LIBRARIES)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECTS)
|
||||
|
||||
.DEFAULT:
|
||||
@echo The target \"$@\" does not exist in Makefile.
|
||||
|
||||
ifdef BUILD_WITH_ATF
|
||||
ATF = -framework ATF
|
||||
USE_ATF = -DUSE_ATF
|
||||
endif
|
||||
|
||||
SRCS = main.c test_buffer_copy.c test_buffer_read.c test_buffer_write.c \
|
||||
test_buffer_mem.c array_info.c test_buffer_map.c \
|
||||
test_sub_buffers.cpp test_buffer_fill.c \
|
||||
test_buffer_migrate.c test_image_migrate.c \
|
||||
../../test_common/harness/errorHelpers.c \
|
||||
../../test_common/harness/threadTesting.c \
|
||||
../../test_common/harness/testHarness.c \
|
||||
../../test_common/harness/kernelHelpers.c \
|
||||
../../test_common/harness/conversions.c \
|
||||
../../test_common/harness/mt19937.c \
|
||||
../../test_common/harness/typeWrappers.cpp
|
||||
|
||||
|
||||
|
||||
DEFINES =
|
||||
|
||||
SOURCES = $(abspath $(SRCS))
|
||||
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
|
||||
LIBPATH += -L.
|
||||
FRAMEWORK = $(SOURCES)
|
||||
HEADERS =
|
||||
TARGET = test_buffers
|
||||
INCLUDE =
|
||||
COMPILERFLAGS = -c -Wall -g -O0 -Wshorten-64-to-32
|
||||
CC = c++
|
||||
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%)
|
||||
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%)
|
||||
LIBRARIES = -framework OpenCL -framework AppKit ${ATF}
|
||||
|
||||
OBJECTS := ${SOURCES:.c=.o}
|
||||
OBJECTS := ${OBJECTS:.cpp=.o}
|
||||
|
||||
TARGETOBJECT =
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(RC_CFLAGS) $(OBJECTS) -o $@ $(LIBPATH) $(LIBRARIES)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECTS)
|
||||
|
||||
.DEFAULT:
|
||||
@echo The target \"$@\" does not exist in Makefile.
|
||||
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
//#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "procs.h"
|
||||
|
||||
|
||||
|
||||
int testBufferSize( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
|
||||
{
|
||||
cl_mem memobj;
|
||||
cl_int err;
|
||||
size_t w = 32, h = 32, d = 32;
|
||||
size_t retSize;
|
||||
size_t elementSize = sizeof( cl_int );
|
||||
|
||||
memobj = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), elementSize * w*h*d, NULL, &err);
|
||||
test_error(err, "clCreateBuffer failed.");
|
||||
|
||||
err = clGetMemObjectInfo(memobj, CL_MEM_SIZE, sizeof( size_t ), (void *)&retSize, NULL);
|
||||
if ( err ){
|
||||
log_error( "Error calling clGetMemObjectInfo(): %d\n", err );
|
||||
clReleaseMemObject(memobj);
|
||||
return -1;
|
||||
}
|
||||
if ( (elementSize * w * h * d) != retSize ) {
|
||||
log_error( "Error in clGetMemObjectInfo() check of size\n" );
|
||||
clReleaseMemObject(memobj);
|
||||
return -1;
|
||||
}
|
||||
else{
|
||||
log_info( " CL_MEM_SIZE passed.\n" );
|
||||
}
|
||||
|
||||
// cleanup
|
||||
clReleaseMemObject(memobj);
|
||||
|
||||
return err;
|
||||
|
||||
} // end testArrayElementSize()
|
||||
|
||||
|
||||
// FIXME: need to test other flags
|
||||
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
//#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "procs.h"
|
||||
|
||||
|
||||
|
||||
int testBufferSize( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
|
||||
{
|
||||
cl_mem memobj;
|
||||
cl_int err;
|
||||
size_t w = 32, h = 32, d = 32;
|
||||
size_t retSize;
|
||||
size_t elementSize = sizeof( cl_int );
|
||||
|
||||
memobj = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), elementSize * w*h*d, NULL, &err);
|
||||
test_error(err, "clCreateBuffer failed.");
|
||||
|
||||
err = clGetMemObjectInfo(memobj, CL_MEM_SIZE, sizeof( size_t ), (void *)&retSize, NULL);
|
||||
if ( err ){
|
||||
log_error( "Error calling clGetMemObjectInfo(): %d\n", err );
|
||||
clReleaseMemObject(memobj);
|
||||
return -1;
|
||||
}
|
||||
if ( (elementSize * w * h * d) != retSize ) {
|
||||
log_error( "Error in clGetMemObjectInfo() check of size\n" );
|
||||
clReleaseMemObject(memobj);
|
||||
return -1;
|
||||
}
|
||||
else{
|
||||
log_info( " CL_MEM_SIZE passed.\n" );
|
||||
}
|
||||
|
||||
// cleanup
|
||||
clReleaseMemObject(memobj);
|
||||
|
||||
return err;
|
||||
|
||||
} // end testArrayElementSize()
|
||||
|
||||
|
||||
// FIXME: need to test other flags
|
||||
|
||||
|
||||
@@ -1,247 +1,247 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/testHarness.h"
|
||||
|
||||
basefn bufferfn_list[] = {
|
||||
test_buffer_read_async_int,
|
||||
test_buffer_read_async_uint,
|
||||
test_buffer_read_async_long,
|
||||
test_buffer_read_async_ulong,
|
||||
test_buffer_read_async_short,
|
||||
test_buffer_read_async_ushort,
|
||||
test_buffer_read_async_char,
|
||||
test_buffer_read_async_uchar,
|
||||
test_buffer_read_async_float,
|
||||
test_buffer_read_array_barrier_int,
|
||||
test_buffer_read_array_barrier_uint,
|
||||
test_buffer_read_array_barrier_long,
|
||||
test_buffer_read_array_barrier_ulong,
|
||||
test_buffer_read_array_barrier_short,
|
||||
test_buffer_read_array_barrier_ushort,
|
||||
test_buffer_read_array_barrier_char,
|
||||
test_buffer_read_array_barrier_uchar,
|
||||
test_buffer_read_array_barrier_float,
|
||||
test_buffer_read_int,
|
||||
test_buffer_read_uint,
|
||||
test_buffer_read_long,
|
||||
test_buffer_read_ulong,
|
||||
test_buffer_read_short,
|
||||
test_buffer_read_ushort,
|
||||
test_buffer_read_float,
|
||||
0, //test_buffer_read_half,
|
||||
test_buffer_read_char,
|
||||
test_buffer_read_uchar,
|
||||
test_buffer_read_struct,
|
||||
test_buffer_read_random_size,
|
||||
test_buffer_map_read_int,
|
||||
test_buffer_map_read_uint,
|
||||
test_buffer_map_read_long,
|
||||
test_buffer_map_read_ulong,
|
||||
test_buffer_map_read_short,
|
||||
test_buffer_map_read_ushort,
|
||||
test_buffer_map_read_char,
|
||||
test_buffer_map_read_uchar,
|
||||
test_buffer_map_read_float,
|
||||
test_buffer_map_read_struct,
|
||||
|
||||
test_buffer_map_write_int,
|
||||
test_buffer_map_write_uint,
|
||||
test_buffer_map_write_long,
|
||||
test_buffer_map_write_ulong,
|
||||
test_buffer_map_write_short,
|
||||
test_buffer_map_write_ushort,
|
||||
test_buffer_map_write_char,
|
||||
test_buffer_map_write_uchar,
|
||||
test_buffer_map_write_float,
|
||||
test_buffer_map_write_struct,
|
||||
|
||||
test_buffer_write_int,
|
||||
test_buffer_write_uint,
|
||||
test_buffer_write_short,
|
||||
test_buffer_write_ushort,
|
||||
test_buffer_write_char,
|
||||
test_buffer_write_uchar,
|
||||
test_buffer_write_float,
|
||||
0, //test_buffer_write_half,
|
||||
test_buffer_write_long,
|
||||
test_buffer_write_ulong,
|
||||
test_buffer_write_struct,
|
||||
test_buffer_write_async_int,
|
||||
test_buffer_write_async_uint,
|
||||
test_buffer_write_async_short,
|
||||
test_buffer_write_async_ushort,
|
||||
test_buffer_write_async_char,
|
||||
test_buffer_write_async_uchar,
|
||||
test_buffer_write_async_float,
|
||||
test_buffer_write_async_long,
|
||||
test_buffer_write_async_ulong,
|
||||
test_buffer_copy,
|
||||
test_buffer_partial_copy,
|
||||
test_mem_read_write_flags,
|
||||
test_mem_write_flags,
|
||||
test_mem_read_flags,
|
||||
test_mem_copy_host_flags,
|
||||
0, //test_mem_alloc_ref_flags,
|
||||
testBufferSize,
|
||||
|
||||
test_sub_buffers_read_write,
|
||||
test_sub_buffers_read_write_dual_devices,
|
||||
test_sub_buffers_overlapping,
|
||||
|
||||
test_buffer_fill_int,
|
||||
test_buffer_fill_uint,
|
||||
test_buffer_fill_short,
|
||||
test_buffer_fill_ushort,
|
||||
test_buffer_fill_char,
|
||||
test_buffer_fill_uchar,
|
||||
test_buffer_fill_long,
|
||||
test_buffer_fill_ulong,
|
||||
test_buffer_fill_float,
|
||||
test_buffer_fill_struct,
|
||||
|
||||
test_buffer_migrate,
|
||||
test_image_migrate,
|
||||
};
|
||||
|
||||
const char *bufferfn_names[] = {
|
||||
"buffer_read_async_int",
|
||||
"buffer_read_async_uint",
|
||||
"buffer_read_async_long",
|
||||
"buffer_read_async_ulong",
|
||||
"buffer_read_async_short",
|
||||
"buffer_read_async_ushort",
|
||||
"buffer_read_async_char",
|
||||
"buffer_read_async_uchar",
|
||||
"buffer_read_async_float",
|
||||
"buffer_read_array_barrier_int",
|
||||
"buffer_read_array_barrier_uint",
|
||||
"buffer_read_array_barrier_long",
|
||||
"buffer_read_array_barrier_ulong",
|
||||
"buffer_read_array_barrier_short",
|
||||
"buffer_read_array_barrier_ushort",
|
||||
"buffer_read_array_barrier_char",
|
||||
"buffer_read_array_barrier_uchar",
|
||||
"buffer_read_array_barrier_float",
|
||||
"buffer_read_int",
|
||||
"buffer_read_uint",
|
||||
"buffer_read_long",
|
||||
"buffer_read_ulong",
|
||||
"buffer_read_short",
|
||||
"buffer_read_ushort",
|
||||
"buffer_read_float",
|
||||
"buffer_read_half",
|
||||
"buffer_read_char",
|
||||
"buffer_read_uchar",
|
||||
"buffer_read_struct",
|
||||
"buffer_read_random_size",
|
||||
"buffer_map_read_int",
|
||||
"buffer_map_read_uint",
|
||||
"buffer_map_read_long",
|
||||
"buffer_map_read_ulong",
|
||||
"buffer_map_read_short",
|
||||
"buffer_map_read_ushort",
|
||||
"buffer_map_read_char",
|
||||
"buffer_map_read_uchar",
|
||||
"buffer_map_read_float",
|
||||
"buffer_map_read_struct",
|
||||
|
||||
"buffer_map_write_int",
|
||||
"buffer_map_write_uint",
|
||||
"buffer_map_write_long",
|
||||
"buffer_map_write_ulong",
|
||||
"buffer_map_write_short",
|
||||
"buffer_map_write_ushort",
|
||||
"buffer_map_write_char",
|
||||
"buffer_map_write_uchar",
|
||||
"buffer_map_write_float",
|
||||
"buffer_map_write_struct",
|
||||
|
||||
"buffer_write_int",
|
||||
"buffer_write_uint",
|
||||
"buffer_write_short",
|
||||
"buffer_write_ushort",
|
||||
"buffer_write_char",
|
||||
"buffer_write_uchar",
|
||||
"buffer_write_float",
|
||||
"buffer_write_half",
|
||||
"buffer_write_long",
|
||||
"buffer_write_ulong",
|
||||
"buffer_write_struct",
|
||||
"buffer_write_async_int",
|
||||
"buffer_write_async_uint",
|
||||
"buffer_write_async_short",
|
||||
"buffer_write_async_ushort",
|
||||
"buffer_write_async_char",
|
||||
"buffer_write_async_uchar",
|
||||
"buffer_write_async_float",
|
||||
"buffer_write_async_long",
|
||||
"buffer_write_async_ulong",
|
||||
"buffer_copy",
|
||||
"buffer_partial_copy",
|
||||
"mem_read_write_flags",
|
||||
"mem_write_only_flags",
|
||||
"mem_read_only_flags",
|
||||
"mem_copy_host_flags",
|
||||
"mem_alloc_ref_flags",
|
||||
"array_info_size",
|
||||
"sub_buffers_read_write",
|
||||
"sub_buffers_read_write_dual_devices",
|
||||
"sub_buffers_overlapping",
|
||||
"buffer_fill_int",
|
||||
"buffer_fill_uint",
|
||||
"buffer_fill_short",
|
||||
"buffer_fill_ushort",
|
||||
"buffer_fill_char",
|
||||
"buffer_fill_uchar",
|
||||
"buffer_fill_long",
|
||||
"buffer_fill_ulong",
|
||||
"buffer_fill_float",
|
||||
"buffer_fill_struct",
|
||||
"buffer_migrate",
|
||||
"image_migrate",
|
||||
"all"
|
||||
};
|
||||
|
||||
ct_assert((sizeof(bufferfn_names) / sizeof(bufferfn_names[0]) - 1) == (sizeof(bufferfn_list) / sizeof(bufferfn_list[0])));
|
||||
|
||||
int num_bufferfns = sizeof(bufferfn_names) / sizeof(char *);
|
||||
|
||||
const cl_mem_flags flag_set[] = {
|
||||
CL_MEM_ALLOC_HOST_PTR,
|
||||
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
|
||||
CL_MEM_USE_HOST_PTR,
|
||||
CL_MEM_COPY_HOST_PTR,
|
||||
0
|
||||
};
|
||||
const char* flag_set_names[] = {
|
||||
"CL_MEM_ALLOC_HOST_PTR",
|
||||
"CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR",
|
||||
"CL_MEM_USE_HOST_PTR",
|
||||
"CL_MEM_COPY_HOST_PTR",
|
||||
"0"
|
||||
};
|
||||
|
||||
int main( int argc, const char *argv[] )
|
||||
{
|
||||
return runTestHarness( argc, argv, num_bufferfns, bufferfn_list, bufferfn_names,
|
||||
false, false, 0 );
|
||||
}
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/testHarness.h"
|
||||
|
||||
basefn bufferfn_list[] = {
|
||||
test_buffer_read_async_int,
|
||||
test_buffer_read_async_uint,
|
||||
test_buffer_read_async_long,
|
||||
test_buffer_read_async_ulong,
|
||||
test_buffer_read_async_short,
|
||||
test_buffer_read_async_ushort,
|
||||
test_buffer_read_async_char,
|
||||
test_buffer_read_async_uchar,
|
||||
test_buffer_read_async_float,
|
||||
test_buffer_read_array_barrier_int,
|
||||
test_buffer_read_array_barrier_uint,
|
||||
test_buffer_read_array_barrier_long,
|
||||
test_buffer_read_array_barrier_ulong,
|
||||
test_buffer_read_array_barrier_short,
|
||||
test_buffer_read_array_barrier_ushort,
|
||||
test_buffer_read_array_barrier_char,
|
||||
test_buffer_read_array_barrier_uchar,
|
||||
test_buffer_read_array_barrier_float,
|
||||
test_buffer_read_int,
|
||||
test_buffer_read_uint,
|
||||
test_buffer_read_long,
|
||||
test_buffer_read_ulong,
|
||||
test_buffer_read_short,
|
||||
test_buffer_read_ushort,
|
||||
test_buffer_read_float,
|
||||
0, //test_buffer_read_half,
|
||||
test_buffer_read_char,
|
||||
test_buffer_read_uchar,
|
||||
test_buffer_read_struct,
|
||||
test_buffer_read_random_size,
|
||||
test_buffer_map_read_int,
|
||||
test_buffer_map_read_uint,
|
||||
test_buffer_map_read_long,
|
||||
test_buffer_map_read_ulong,
|
||||
test_buffer_map_read_short,
|
||||
test_buffer_map_read_ushort,
|
||||
test_buffer_map_read_char,
|
||||
test_buffer_map_read_uchar,
|
||||
test_buffer_map_read_float,
|
||||
test_buffer_map_read_struct,
|
||||
|
||||
test_buffer_map_write_int,
|
||||
test_buffer_map_write_uint,
|
||||
test_buffer_map_write_long,
|
||||
test_buffer_map_write_ulong,
|
||||
test_buffer_map_write_short,
|
||||
test_buffer_map_write_ushort,
|
||||
test_buffer_map_write_char,
|
||||
test_buffer_map_write_uchar,
|
||||
test_buffer_map_write_float,
|
||||
test_buffer_map_write_struct,
|
||||
|
||||
test_buffer_write_int,
|
||||
test_buffer_write_uint,
|
||||
test_buffer_write_short,
|
||||
test_buffer_write_ushort,
|
||||
test_buffer_write_char,
|
||||
test_buffer_write_uchar,
|
||||
test_buffer_write_float,
|
||||
0, //test_buffer_write_half,
|
||||
test_buffer_write_long,
|
||||
test_buffer_write_ulong,
|
||||
test_buffer_write_struct,
|
||||
test_buffer_write_async_int,
|
||||
test_buffer_write_async_uint,
|
||||
test_buffer_write_async_short,
|
||||
test_buffer_write_async_ushort,
|
||||
test_buffer_write_async_char,
|
||||
test_buffer_write_async_uchar,
|
||||
test_buffer_write_async_float,
|
||||
test_buffer_write_async_long,
|
||||
test_buffer_write_async_ulong,
|
||||
test_buffer_copy,
|
||||
test_buffer_partial_copy,
|
||||
test_mem_read_write_flags,
|
||||
test_mem_write_flags,
|
||||
test_mem_read_flags,
|
||||
test_mem_copy_host_flags,
|
||||
0, //test_mem_alloc_ref_flags,
|
||||
testBufferSize,
|
||||
|
||||
test_sub_buffers_read_write,
|
||||
test_sub_buffers_read_write_dual_devices,
|
||||
test_sub_buffers_overlapping,
|
||||
|
||||
test_buffer_fill_int,
|
||||
test_buffer_fill_uint,
|
||||
test_buffer_fill_short,
|
||||
test_buffer_fill_ushort,
|
||||
test_buffer_fill_char,
|
||||
test_buffer_fill_uchar,
|
||||
test_buffer_fill_long,
|
||||
test_buffer_fill_ulong,
|
||||
test_buffer_fill_float,
|
||||
test_buffer_fill_struct,
|
||||
|
||||
test_buffer_migrate,
|
||||
test_image_migrate,
|
||||
};
|
||||
|
||||
const char *bufferfn_names[] = {
|
||||
"buffer_read_async_int",
|
||||
"buffer_read_async_uint",
|
||||
"buffer_read_async_long",
|
||||
"buffer_read_async_ulong",
|
||||
"buffer_read_async_short",
|
||||
"buffer_read_async_ushort",
|
||||
"buffer_read_async_char",
|
||||
"buffer_read_async_uchar",
|
||||
"buffer_read_async_float",
|
||||
"buffer_read_array_barrier_int",
|
||||
"buffer_read_array_barrier_uint",
|
||||
"buffer_read_array_barrier_long",
|
||||
"buffer_read_array_barrier_ulong",
|
||||
"buffer_read_array_barrier_short",
|
||||
"buffer_read_array_barrier_ushort",
|
||||
"buffer_read_array_barrier_char",
|
||||
"buffer_read_array_barrier_uchar",
|
||||
"buffer_read_array_barrier_float",
|
||||
"buffer_read_int",
|
||||
"buffer_read_uint",
|
||||
"buffer_read_long",
|
||||
"buffer_read_ulong",
|
||||
"buffer_read_short",
|
||||
"buffer_read_ushort",
|
||||
"buffer_read_float",
|
||||
"buffer_read_half",
|
||||
"buffer_read_char",
|
||||
"buffer_read_uchar",
|
||||
"buffer_read_struct",
|
||||
"buffer_read_random_size",
|
||||
"buffer_map_read_int",
|
||||
"buffer_map_read_uint",
|
||||
"buffer_map_read_long",
|
||||
"buffer_map_read_ulong",
|
||||
"buffer_map_read_short",
|
||||
"buffer_map_read_ushort",
|
||||
"buffer_map_read_char",
|
||||
"buffer_map_read_uchar",
|
||||
"buffer_map_read_float",
|
||||
"buffer_map_read_struct",
|
||||
|
||||
"buffer_map_write_int",
|
||||
"buffer_map_write_uint",
|
||||
"buffer_map_write_long",
|
||||
"buffer_map_write_ulong",
|
||||
"buffer_map_write_short",
|
||||
"buffer_map_write_ushort",
|
||||
"buffer_map_write_char",
|
||||
"buffer_map_write_uchar",
|
||||
"buffer_map_write_float",
|
||||
"buffer_map_write_struct",
|
||||
|
||||
"buffer_write_int",
|
||||
"buffer_write_uint",
|
||||
"buffer_write_short",
|
||||
"buffer_write_ushort",
|
||||
"buffer_write_char",
|
||||
"buffer_write_uchar",
|
||||
"buffer_write_float",
|
||||
"buffer_write_half",
|
||||
"buffer_write_long",
|
||||
"buffer_write_ulong",
|
||||
"buffer_write_struct",
|
||||
"buffer_write_async_int",
|
||||
"buffer_write_async_uint",
|
||||
"buffer_write_async_short",
|
||||
"buffer_write_async_ushort",
|
||||
"buffer_write_async_char",
|
||||
"buffer_write_async_uchar",
|
||||
"buffer_write_async_float",
|
||||
"buffer_write_async_long",
|
||||
"buffer_write_async_ulong",
|
||||
"buffer_copy",
|
||||
"buffer_partial_copy",
|
||||
"mem_read_write_flags",
|
||||
"mem_write_only_flags",
|
||||
"mem_read_only_flags",
|
||||
"mem_copy_host_flags",
|
||||
"mem_alloc_ref_flags",
|
||||
"array_info_size",
|
||||
"sub_buffers_read_write",
|
||||
"sub_buffers_read_write_dual_devices",
|
||||
"sub_buffers_overlapping",
|
||||
"buffer_fill_int",
|
||||
"buffer_fill_uint",
|
||||
"buffer_fill_short",
|
||||
"buffer_fill_ushort",
|
||||
"buffer_fill_char",
|
||||
"buffer_fill_uchar",
|
||||
"buffer_fill_long",
|
||||
"buffer_fill_ulong",
|
||||
"buffer_fill_float",
|
||||
"buffer_fill_struct",
|
||||
"buffer_migrate",
|
||||
"image_migrate",
|
||||
"all"
|
||||
};
|
||||
|
||||
ct_assert((sizeof(bufferfn_names) / sizeof(bufferfn_names[0]) - 1) == (sizeof(bufferfn_list) / sizeof(bufferfn_list[0])));
|
||||
|
||||
int num_bufferfns = sizeof(bufferfn_names) / sizeof(char *);
|
||||
|
||||
const cl_mem_flags flag_set[] = {
|
||||
CL_MEM_ALLOC_HOST_PTR,
|
||||
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR,
|
||||
CL_MEM_USE_HOST_PTR,
|
||||
CL_MEM_COPY_HOST_PTR,
|
||||
0
|
||||
};
|
||||
const char* flag_set_names[] = {
|
||||
"CL_MEM_ALLOC_HOST_PTR",
|
||||
"CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR",
|
||||
"CL_MEM_USE_HOST_PTR",
|
||||
"CL_MEM_COPY_HOST_PTR",
|
||||
"0"
|
||||
};
|
||||
|
||||
int main( int argc, const char *argv[] )
|
||||
{
|
||||
return runTestHarness( argc, argv, num_bufferfns, bufferfn_list, bufferfn_names,
|
||||
false, false, 0 );
|
||||
}
|
||||
|
||||
@@ -1,132 +1,132 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef __PROCS_H__
|
||||
#define __PROCS_H__
|
||||
|
||||
#include "../../test_common/harness/kernelHelpers.h"
|
||||
#include "../../test_common/harness/testHarness.h"
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include "../../test_common/harness/mt19937.h"
|
||||
#include "../../test_common/harness/conversions.h"
|
||||
|
||||
#ifndef __APPLE__
|
||||
#include <CL/cl.h>
|
||||
#endif
|
||||
|
||||
extern const cl_mem_flags flag_set[];
|
||||
extern const char* flag_set_names[];
|
||||
#define NUM_FLAGS 5
|
||||
|
||||
extern int test_buffer_read_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_random_size( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_copy( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_partial_copy( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int testBufferSize( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_read_write_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_write_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_read_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_copy_host_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_alloc_ref_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
|
||||
extern int test_buffer_map_write_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
|
||||
extern int test_sub_buffers_read_write( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_sub_buffers_read_write_dual_devices( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_sub_buffers_overlapping( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_image_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
|
||||
extern int test_buffer_fill_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
|
||||
#endif // #ifndef __PROCS_H__
|
||||
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef __PROCS_H__
|
||||
#define __PROCS_H__
|
||||
|
||||
#include "../../test_common/harness/kernelHelpers.h"
|
||||
#include "../../test_common/harness/testHarness.h"
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/typeWrappers.h"
|
||||
#include "../../test_common/harness/mt19937.h"
|
||||
#include "../../test_common/harness/conversions.h"
|
||||
|
||||
#ifndef __APPLE__
|
||||
#include <CL/cl.h>
|
||||
#endif
|
||||
|
||||
extern const cl_mem_flags flag_set[];
|
||||
extern const char* flag_set_names[];
|
||||
#define NUM_FLAGS 5
|
||||
|
||||
extern int test_buffer_read_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_random_size( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_async_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_read_array_barrier_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_write_async_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_copy( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_partial_copy( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int testBufferSize( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_read_write_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_write_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_read_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_copy_host_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_mem_alloc_ref_flags( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_read_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
|
||||
extern int test_buffer_map_write_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_map_write_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
|
||||
extern int test_sub_buffers_read_write( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_sub_buffers_read_write_dual_devices( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_sub_buffers_overlapping( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
extern int test_image_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
|
||||
|
||||
extern int test_buffer_fill_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
extern int test_buffer_fill_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements );
|
||||
|
||||
#endif // #ifndef __PROCS_H__
|
||||
|
||||
|
||||
@@ -1,295 +1,295 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
//#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
|
||||
|
||||
static int verify_copy_buffer(int *inptr, int *outptr, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<n; i++){
|
||||
if ( outptr[i] != inptr[i] )
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int test_copy( cl_command_queue queue, cl_context context, int num_elements, MTdata d )
|
||||
{
|
||||
cl_mem buffers[2];
|
||||
cl_int *int_input_ptr, *int_output_ptr;
|
||||
cl_int err;
|
||||
int i;
|
||||
int src_flag_id, dst_flag_id;
|
||||
int errors = 0;
|
||||
|
||||
size_t min_alignment = get_min_alignment(context);
|
||||
|
||||
int_input_ptr = (cl_int*) align_malloc(sizeof(cl_int) * num_elements, min_alignment);
|
||||
int_output_ptr = (cl_int*)align_malloc(sizeof(cl_int) * num_elements, min_alignment);
|
||||
|
||||
for (src_flag_id=0; src_flag_id < NUM_FLAGS; src_flag_id++) {
|
||||
for (dst_flag_id=0; dst_flag_id < NUM_FLAGS; dst_flag_id++) {
|
||||
log_info("Testing with cl_mem_flags src: %s dst: %s\n", flag_set_names[src_flag_id], flag_set_names[dst_flag_id]);
|
||||
|
||||
for (i=0; i<num_elements; i++){
|
||||
int_input_ptr[i] = (int)genrand_int32( d );
|
||||
int_output_ptr[i] = 0xdeaddead; // seed with incorrect data
|
||||
}
|
||||
|
||||
if ((flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], sizeof(cl_int) * num_elements, int_input_ptr, &err);
|
||||
else
|
||||
buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], sizeof(cl_int) * num_elements, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error(err, " clCreateBuffer failed\n" );
|
||||
align_free( (void *)int_input_ptr );
|
||||
align_free( (void *)int_output_ptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((flag_set[dst_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[dst_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[1] = clCreateBuffer(context, flag_set[dst_flag_id], sizeof(cl_int) * num_elements, int_output_ptr, &err);
|
||||
else
|
||||
buffers[1] = clCreateBuffer(context, flag_set[dst_flag_id], sizeof(cl_int) * num_elements, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error(err, " clCreateBuffer failed\n" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)int_input_ptr );
|
||||
align_free( (void *)int_output_ptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) && !(flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR)) {
|
||||
err = clEnqueueWriteBuffer(queue, buffers[0], CL_TRUE, 0, sizeof(cl_int)*num_elements, (void *)int_input_ptr, 0, NULL, NULL);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clEnqueueWriteBuffer failed" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
align_free( (void *)int_output_ptr );
|
||||
align_free( (void *)int_input_ptr );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
err = clEnqueueCopyBuffer(queue, buffers[0], buffers[1], 0, 0, sizeof(cl_int)*num_elements, 0, NULL, NULL);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clCopyArray failed" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
align_free( (void *)int_output_ptr );
|
||||
align_free( (void *)int_input_ptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = clEnqueueReadBuffer( queue, buffers[1], true, 0, sizeof(int)*num_elements, (void *)int_output_ptr, 0, NULL, NULL );
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clEnqueueReadBuffer failed" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
align_free( (void *)int_output_ptr );
|
||||
align_free( (void *)int_input_ptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( verify_copy_buffer(int_input_ptr, int_output_ptr, num_elements) ){
|
||||
log_error( " test failed\n" );
|
||||
errors++;
|
||||
}
|
||||
else{
|
||||
log_info( " test passed\n" );
|
||||
}
|
||||
// cleanup
|
||||
clReleaseMemObject( buffers[0] );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
} // dst flags
|
||||
} // src flags
|
||||
// cleanup
|
||||
align_free( (void *)int_output_ptr );
|
||||
align_free( (void *)int_input_ptr );
|
||||
|
||||
return errors;
|
||||
|
||||
} // end test_copy()
|
||||
|
||||
|
||||
static int testPartialCopy( cl_command_queue queue, cl_context context, int num_elements, cl_uint srcStart, cl_uint dstStart, int size, MTdata d )
|
||||
{
|
||||
cl_mem buffers[2];
|
||||
int *inptr, *outptr;
|
||||
cl_int err;
|
||||
int i;
|
||||
int src_flag_id, dst_flag_id;
|
||||
int errors = 0;
|
||||
|
||||
size_t min_alignment = get_min_alignment(context);
|
||||
|
||||
inptr = (int *)align_malloc( sizeof(int) * num_elements, min_alignment);
|
||||
if ( ! inptr ){
|
||||
log_error( " unable to allocate %d bytes of memory\n", (int)sizeof(int) * num_elements );
|
||||
return -1;
|
||||
}
|
||||
outptr = (int *)align_malloc( sizeof(int) * num_elements, min_alignment);
|
||||
if ( ! outptr ){
|
||||
log_error( " unable to allocate %d bytes of memory\n", (int)sizeof(int) * num_elements );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (src_flag_id=0; src_flag_id < NUM_FLAGS; src_flag_id++) {
|
||||
for (dst_flag_id=0; dst_flag_id < NUM_FLAGS; dst_flag_id++) {
|
||||
log_info("Testing with cl_mem_flags src: %s dst: %s\n", flag_set_names[src_flag_id], flag_set_names[dst_flag_id]);
|
||||
|
||||
for (i=0; i<num_elements; i++){
|
||||
inptr[i] = (int)genrand_int32( d );
|
||||
outptr[i] = (int)0xdeaddead; // seed with incorrect data
|
||||
}
|
||||
|
||||
if ((flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], sizeof(cl_int) * num_elements, inptr, &err);
|
||||
else
|
||||
buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], sizeof(cl_int) * num_elements, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error(err, " clCreateBuffer failed\n" )
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((flag_set[dst_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[dst_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[1] = clCreateBuffer(context, flag_set[dst_flag_id], sizeof(cl_int) * num_elements, outptr, &err);
|
||||
else
|
||||
buffers[1] = clCreateBuffer(context, flag_set[dst_flag_id], sizeof(cl_int) * num_elements, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error(err, " clCreateBuffer failed\n" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) && !(flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR)){
|
||||
err = clEnqueueWriteBuffer(queue, buffers[0], CL_TRUE, 0, sizeof(cl_int)*num_elements, (void *)inptr, 0, NULL, NULL);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clEnqueueWriteBuffer failed" );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
err = clEnqueueCopyBuffer(queue, buffers[0], buffers[1], srcStart*sizeof(cl_int), dstStart*sizeof(cl_int), sizeof(cl_int)*size, 0, NULL, NULL);
|
||||
if ( err != CL_SUCCESS){
|
||||
print_error( err, "clEnqueueCopyBuffer failed" );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = clEnqueueReadBuffer( queue, buffers[1], true, 0, sizeof(int)*num_elements, (void *)outptr, 0, NULL, NULL );
|
||||
if ( err != CL_SUCCESS){
|
||||
print_error( err, "clEnqueueReadBuffer failed" );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( verify_copy_buffer(inptr + srcStart, outptr + dstStart, size) ){
|
||||
log_error("buffer_COPY test failed\n");
|
||||
errors++;
|
||||
}
|
||||
else{
|
||||
log_info("buffer_COPY test passed\n");
|
||||
}
|
||||
// cleanup
|
||||
clReleaseMemObject( buffers[1] );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
} // dst mem flags
|
||||
} // src mem flags
|
||||
// cleanup
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
|
||||
return errors;
|
||||
|
||||
} // end testPartialCopy()
|
||||
|
||||
|
||||
int test_buffer_copy( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
|
||||
{
|
||||
int i, err = 0;
|
||||
int size;
|
||||
MTdata d = init_genrand( gRandomSeed );
|
||||
|
||||
// test the preset size
|
||||
log_info( "set size: %d: ", num_elements );
|
||||
if (test_copy( queue, context, num_elements, d ))
|
||||
err++;
|
||||
|
||||
// now test random sizes
|
||||
for ( i = 0; i < 8; i++ ){
|
||||
size = (int)get_random_float(2.f,131072.f, d);
|
||||
log_info( "random size: %d: ", size );
|
||||
if (test_copy( queue, context, size, d ))
|
||||
err++;
|
||||
}
|
||||
|
||||
free_mtdata(d);
|
||||
|
||||
return err;
|
||||
|
||||
} // end test_buffer_copy()
|
||||
|
||||
|
||||
int test_buffer_partial_copy( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
|
||||
{
|
||||
int i, err = 0;
|
||||
int size;
|
||||
cl_uint srcStart, dstStart;
|
||||
MTdata d = init_genrand( gRandomSeed );
|
||||
|
||||
// now test copy of partial sizes
|
||||
for ( i = 0; i < 8; i++ ){
|
||||
srcStart = (cl_uint)get_random_float( 0.f, (float)(num_elements - 8), d );
|
||||
size = (int)get_random_float( 8.f, (float)(num_elements - srcStart), d );
|
||||
dstStart = (cl_uint)get_random_float( 0.f, (float)(num_elements - size), d );
|
||||
log_info( "random partial copy from %d to %d, size: %d: ", (int)srcStart, (int)dstStart, size );
|
||||
if (testPartialCopy( queue, context, num_elements, srcStart, dstStart, size, d ))
|
||||
err++;
|
||||
}
|
||||
|
||||
free_mtdata(d);
|
||||
return err;
|
||||
|
||||
} // end test_buffer_partial_copy()
|
||||
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
//#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
|
||||
|
||||
static int verify_copy_buffer(int *inptr, int *outptr, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<n; i++){
|
||||
if ( outptr[i] != inptr[i] )
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int test_copy( cl_command_queue queue, cl_context context, int num_elements, MTdata d )
|
||||
{
|
||||
cl_mem buffers[2];
|
||||
cl_int *int_input_ptr, *int_output_ptr;
|
||||
cl_int err;
|
||||
int i;
|
||||
int src_flag_id, dst_flag_id;
|
||||
int errors = 0;
|
||||
|
||||
size_t min_alignment = get_min_alignment(context);
|
||||
|
||||
int_input_ptr = (cl_int*) align_malloc(sizeof(cl_int) * num_elements, min_alignment);
|
||||
int_output_ptr = (cl_int*)align_malloc(sizeof(cl_int) * num_elements, min_alignment);
|
||||
|
||||
for (src_flag_id=0; src_flag_id < NUM_FLAGS; src_flag_id++) {
|
||||
for (dst_flag_id=0; dst_flag_id < NUM_FLAGS; dst_flag_id++) {
|
||||
log_info("Testing with cl_mem_flags src: %s dst: %s\n", flag_set_names[src_flag_id], flag_set_names[dst_flag_id]);
|
||||
|
||||
for (i=0; i<num_elements; i++){
|
||||
int_input_ptr[i] = (int)genrand_int32( d );
|
||||
int_output_ptr[i] = 0xdeaddead; // seed with incorrect data
|
||||
}
|
||||
|
||||
if ((flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], sizeof(cl_int) * num_elements, int_input_ptr, &err);
|
||||
else
|
||||
buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], sizeof(cl_int) * num_elements, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error(err, " clCreateBuffer failed\n" );
|
||||
align_free( (void *)int_input_ptr );
|
||||
align_free( (void *)int_output_ptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((flag_set[dst_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[dst_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[1] = clCreateBuffer(context, flag_set[dst_flag_id], sizeof(cl_int) * num_elements, int_output_ptr, &err);
|
||||
else
|
||||
buffers[1] = clCreateBuffer(context, flag_set[dst_flag_id], sizeof(cl_int) * num_elements, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error(err, " clCreateBuffer failed\n" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)int_input_ptr );
|
||||
align_free( (void *)int_output_ptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) && !(flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR)) {
|
||||
err = clEnqueueWriteBuffer(queue, buffers[0], CL_TRUE, 0, sizeof(cl_int)*num_elements, (void *)int_input_ptr, 0, NULL, NULL);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clEnqueueWriteBuffer failed" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
align_free( (void *)int_output_ptr );
|
||||
align_free( (void *)int_input_ptr );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
err = clEnqueueCopyBuffer(queue, buffers[0], buffers[1], 0, 0, sizeof(cl_int)*num_elements, 0, NULL, NULL);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clCopyArray failed" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
align_free( (void *)int_output_ptr );
|
||||
align_free( (void *)int_input_ptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = clEnqueueReadBuffer( queue, buffers[1], true, 0, sizeof(int)*num_elements, (void *)int_output_ptr, 0, NULL, NULL );
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clEnqueueReadBuffer failed" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
align_free( (void *)int_output_ptr );
|
||||
align_free( (void *)int_input_ptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( verify_copy_buffer(int_input_ptr, int_output_ptr, num_elements) ){
|
||||
log_error( " test failed\n" );
|
||||
errors++;
|
||||
}
|
||||
else{
|
||||
log_info( " test passed\n" );
|
||||
}
|
||||
// cleanup
|
||||
clReleaseMemObject( buffers[0] );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
} // dst flags
|
||||
} // src flags
|
||||
// cleanup
|
||||
align_free( (void *)int_output_ptr );
|
||||
align_free( (void *)int_input_ptr );
|
||||
|
||||
return errors;
|
||||
|
||||
} // end test_copy()
|
||||
|
||||
|
||||
static int testPartialCopy( cl_command_queue queue, cl_context context, int num_elements, cl_uint srcStart, cl_uint dstStart, int size, MTdata d )
|
||||
{
|
||||
cl_mem buffers[2];
|
||||
int *inptr, *outptr;
|
||||
cl_int err;
|
||||
int i;
|
||||
int src_flag_id, dst_flag_id;
|
||||
int errors = 0;
|
||||
|
||||
size_t min_alignment = get_min_alignment(context);
|
||||
|
||||
inptr = (int *)align_malloc( sizeof(int) * num_elements, min_alignment);
|
||||
if ( ! inptr ){
|
||||
log_error( " unable to allocate %d bytes of memory\n", (int)sizeof(int) * num_elements );
|
||||
return -1;
|
||||
}
|
||||
outptr = (int *)align_malloc( sizeof(int) * num_elements, min_alignment);
|
||||
if ( ! outptr ){
|
||||
log_error( " unable to allocate %d bytes of memory\n", (int)sizeof(int) * num_elements );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (src_flag_id=0; src_flag_id < NUM_FLAGS; src_flag_id++) {
|
||||
for (dst_flag_id=0; dst_flag_id < NUM_FLAGS; dst_flag_id++) {
|
||||
log_info("Testing with cl_mem_flags src: %s dst: %s\n", flag_set_names[src_flag_id], flag_set_names[dst_flag_id]);
|
||||
|
||||
for (i=0; i<num_elements; i++){
|
||||
inptr[i] = (int)genrand_int32( d );
|
||||
outptr[i] = (int)0xdeaddead; // seed with incorrect data
|
||||
}
|
||||
|
||||
if ((flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], sizeof(cl_int) * num_elements, inptr, &err);
|
||||
else
|
||||
buffers[0] = clCreateBuffer(context, flag_set[src_flag_id], sizeof(cl_int) * num_elements, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error(err, " clCreateBuffer failed\n" )
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((flag_set[dst_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[dst_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[1] = clCreateBuffer(context, flag_set[dst_flag_id], sizeof(cl_int) * num_elements, outptr, &err);
|
||||
else
|
||||
buffers[1] = clCreateBuffer(context, flag_set[dst_flag_id], sizeof(cl_int) * num_elements, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error(err, " clCreateBuffer failed\n" );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) && !(flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR)){
|
||||
err = clEnqueueWriteBuffer(queue, buffers[0], CL_TRUE, 0, sizeof(cl_int)*num_elements, (void *)inptr, 0, NULL, NULL);
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clEnqueueWriteBuffer failed" );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
err = clEnqueueCopyBuffer(queue, buffers[0], buffers[1], srcStart*sizeof(cl_int), dstStart*sizeof(cl_int), sizeof(cl_int)*size, 0, NULL, NULL);
|
||||
if ( err != CL_SUCCESS){
|
||||
print_error( err, "clEnqueueCopyBuffer failed" );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = clEnqueueReadBuffer( queue, buffers[1], true, 0, sizeof(int)*num_elements, (void *)outptr, 0, NULL, NULL );
|
||||
if ( err != CL_SUCCESS){
|
||||
print_error( err, "clEnqueueReadBuffer failed" );
|
||||
clReleaseMemObject( buffers[1] );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( verify_copy_buffer(inptr + srcStart, outptr + dstStart, size) ){
|
||||
log_error("buffer_COPY test failed\n");
|
||||
errors++;
|
||||
}
|
||||
else{
|
||||
log_info("buffer_COPY test passed\n");
|
||||
}
|
||||
// cleanup
|
||||
clReleaseMemObject( buffers[1] );
|
||||
clReleaseMemObject( buffers[0] );
|
||||
} // dst mem flags
|
||||
} // src mem flags
|
||||
// cleanup
|
||||
align_free( (void *)outptr );
|
||||
align_free( (void *)inptr );
|
||||
|
||||
return errors;
|
||||
|
||||
} // end testPartialCopy()
|
||||
|
||||
|
||||
int test_buffer_copy( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
|
||||
{
|
||||
int i, err = 0;
|
||||
int size;
|
||||
MTdata d = init_genrand( gRandomSeed );
|
||||
|
||||
// test the preset size
|
||||
log_info( "set size: %d: ", num_elements );
|
||||
if (test_copy( queue, context, num_elements, d ))
|
||||
err++;
|
||||
|
||||
// now test random sizes
|
||||
for ( i = 0; i < 8; i++ ){
|
||||
size = (int)get_random_float(2.f,131072.f, d);
|
||||
log_info( "random size: %d: ", size );
|
||||
if (test_copy( queue, context, size, d ))
|
||||
err++;
|
||||
}
|
||||
|
||||
free_mtdata(d);
|
||||
|
||||
return err;
|
||||
|
||||
} // end test_buffer_copy()
|
||||
|
||||
|
||||
int test_buffer_partial_copy( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
|
||||
{
|
||||
int i, err = 0;
|
||||
int size;
|
||||
cl_uint srcStart, dstStart;
|
||||
MTdata d = init_genrand( gRandomSeed );
|
||||
|
||||
// now test copy of partial sizes
|
||||
for ( i = 0; i < 8; i++ ){
|
||||
srcStart = (cl_uint)get_random_float( 0.f, (float)(num_elements - 8), d );
|
||||
size = (int)get_random_float( 8.f, (float)(num_elements - srcStart), d );
|
||||
dstStart = (cl_uint)get_random_float( 0.f, (float)(num_elements - size), d );
|
||||
log_info( "random partial copy from %d to %d, size: %d: ", (int)srcStart, (int)dstStart, size );
|
||||
if (testPartialCopy( queue, context, num_elements, srcStart, dstStart, size, d ))
|
||||
err++;
|
||||
}
|
||||
|
||||
free_mtdata(d);
|
||||
return err;
|
||||
|
||||
} // end test_buffer_partial_copy()
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,417 +1,417 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/testHarness.h"
|
||||
|
||||
#define MAX_SUB_DEVICES 16 // Limit the sub-devices to ensure no out of resource errors.
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
// Kernel source code
|
||||
static const char *buffer_migrate_kernel_code =
|
||||
"__kernel void test_buffer_migrate(__global uint *dst, __global uint *src1, __global uint *src2, uint x)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dst[tid] = src1[tid] ^ src2[tid] ^ x;\n"
|
||||
"}\n";
|
||||
|
||||
enum migrations { MIGRATE_PREFERRED, // migrate to the preferred sub-device
|
||||
MIGRATE_NON_PREFERRED, // migrate to a randomly chosen non-preferred sub-device
|
||||
MIGRATE_RANDOM, // migrate to a randomly chosen sub-device with randomly chosen flags
|
||||
NUMBER_OF_MIGRATIONS };
|
||||
|
||||
static cl_mem init_buffer(cl_command_queue cmd_q, cl_mem buffer, cl_uint *data)
|
||||
{
|
||||
cl_int err;
|
||||
|
||||
if (buffer) {
|
||||
if ((err = clEnqueueWriteBuffer(cmd_q, buffer, CL_TRUE, 0, sizeof(cl_uint)*BUFFER_SIZE, data, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed on enqueue write of buffer data.");
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static cl_int migrateMemObject(enum migrations migrate, cl_command_queue *queues, cl_mem *mem_objects, cl_uint num_devices, cl_mem_migration_flags *flags, MTdata d)
|
||||
{
|
||||
cl_uint i, j;
|
||||
cl_int err = CL_SUCCESS;
|
||||
|
||||
for (i=0; i<num_devices; i++) {
|
||||
j = genrand_int32(d) % num_devices;
|
||||
flags[i] = 0;
|
||||
switch (migrate) {
|
||||
case MIGRATE_PREFERRED:
|
||||
// Force the device to be preferred
|
||||
j = i;
|
||||
break;
|
||||
case MIGRATE_NON_PREFERRED:
|
||||
// Coerce the device to be non-preferred
|
||||
if ((j == i) && (num_devices > 1)) j = (j+1) % num_devices;
|
||||
break;
|
||||
case MIGRATE_RANDOM:
|
||||
// Choose a random set of flags
|
||||
flags[i] = (cl_mem_migration_flags)(genrand_int32(d) & (CL_MIGRATE_MEM_OBJECT_HOST | CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED));;
|
||||
break;
|
||||
}
|
||||
if ((err = clEnqueueMigrateMemObjects(queues[j], 1, (const cl_mem *)(&mem_objects[i]), flags[i], 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed migrating memory object.");
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static cl_int restoreBuffer(cl_command_queue *queues, cl_mem *buffers, cl_uint num_devices, cl_mem_migration_flags *flags, cl_uint *buffer)
|
||||
{
|
||||
cl_uint i, j;
|
||||
cl_int err;
|
||||
|
||||
// If the buffer was previously migrated with undefined content, reload the content.
|
||||
|
||||
for (i=0; i<num_devices; i++) {
|
||||
if (flags[i] & CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED) {
|
||||
if ((err = clEnqueueWriteBuffer(queues[i], buffers[i], CL_TRUE, 0, sizeof(cl_uint)*BUFFER_SIZE, buffer, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed on restoration enqueue write of buffer data.");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int test_buffer_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
int failed = 0;
|
||||
cl_uint i, j;
|
||||
cl_int err;
|
||||
cl_uint max_sub_devices = 0;
|
||||
cl_uint num_devices, num_devices_limited;
|
||||
cl_uint A[BUFFER_SIZE], B[BUFFER_SIZE], C[BUFFER_SIZE];
|
||||
cl_uint test_number = 1;
|
||||
cl_device_affinity_domain domain, domains;
|
||||
cl_device_id *devices;
|
||||
cl_command_queue *queues;
|
||||
cl_mem_migration_flags *flagsA, *flagsB, *flagsC;
|
||||
cl_device_partition_property property[] = {CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN, 0, 0};
|
||||
cl_mem *bufferA, *bufferB, *bufferC;
|
||||
cl_program program = NULL;
|
||||
cl_kernel kernel = NULL;
|
||||
cl_context ctx = NULL; // context for all sub-devices
|
||||
enum migrations migrateA, migrateB, migrateC;
|
||||
MTdata d = init_genrand(gRandomSeed);
|
||||
const size_t wgs[1] = {BUFFER_SIZE};
|
||||
|
||||
/* Allocate arrays whose size varies according to the maximum number of sub-devices */
|
||||
if ((err = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(max_sub_devices), &max_sub_devices, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "clGetDeviceInfo(CL_DEVICE_MAX_COMPUTE_UNITS) failed");
|
||||
return -1;
|
||||
}
|
||||
if (max_sub_devices < 1) {
|
||||
log_error("ERROR: Invalid number of compute units returned.\n");
|
||||
return -1;
|
||||
}
|
||||
devices = (cl_device_id *)malloc(max_sub_devices * sizeof(cl_device_id));
|
||||
queues = (cl_command_queue *)malloc(max_sub_devices * sizeof(cl_command_queue));
|
||||
flagsA = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
flagsB = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
flagsC = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
bufferA = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
bufferB = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
bufferC = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
|
||||
if ((devices == NULL) || (queues == NULL) ||
|
||||
(flagsA == NULL) || (flagsB == NULL) || (flagsC == NULL) ||
|
||||
(bufferA == NULL) || (bufferB == NULL) || (bufferC == NULL)) {
|
||||
log_error("ERROR: Failed to successfully allocate required local buffers.\n");
|
||||
failed = -1;
|
||||
goto cleanup_allocations;
|
||||
}
|
||||
|
||||
for (i=0; i<max_sub_devices; i++) {
|
||||
devices[i] = NULL;
|
||||
queues [i] = NULL;
|
||||
bufferA[i] = bufferB[i] = bufferC[i] = NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<BUFFER_SIZE; i++) {
|
||||
A[i] = genrand_int32(d);
|
||||
B[i] = genrand_int32(d);
|
||||
}
|
||||
|
||||
// Attempt to partition the device along each of the allowed affinity domain.
|
||||
if ((err = clGetDeviceInfo(deviceID, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, sizeof(domains), &domains, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "clGetDeviceInfo(CL_PARTITION_AFFINITY_DOMAIN) failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
domains &= (CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE | CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE |
|
||||
CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE | CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE | CL_DEVICE_AFFINITY_DOMAIN_NUMA);
|
||||
|
||||
do {
|
||||
if (domains) {
|
||||
for (domain = 1; (domain & domains) == 0; domain <<= 1) {};
|
||||
domains &= ~domain;
|
||||
} else {
|
||||
domain = 0;
|
||||
}
|
||||
|
||||
// Determine the number of partitions for the device given the specific domain.
|
||||
if (domain) {
|
||||
property[1] = domain;
|
||||
err = clCreateSubDevices(deviceID, (const cl_device_partition_property *)property, -1, NULL, &num_devices);
|
||||
if ((err != CL_SUCCESS) || (num_devices == 0)) {
|
||||
print_error(err, "Obtaining the number of partions by affinity failed.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
num_devices = 1;
|
||||
}
|
||||
|
||||
if (num_devices > 1) {
|
||||
// Create each of the sub-devices and a corresponding context.
|
||||
if ((err = clCreateSubDevices(deviceID, (const cl_device_partition_property *)property, num_devices, devices, &num_devices)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed creating sub devices.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create a context containing all the sub-devices
|
||||
ctx = clCreateContext(NULL, num_devices, devices, notify_callback, NULL, &err);
|
||||
if (ctx == NULL) {
|
||||
print_error(err, "Failed creating context containing the sub-devices.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create a command queue for each sub-device
|
||||
for (i=0; i<num_devices; i++) {
|
||||
if (devices[i]) {
|
||||
if ((queues[i] = clCreateCommandQueue(ctx, devices[i], 0, &err)) == NULL) {
|
||||
print_error(err, "Failed creating command queues.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No partitioning available. Just exercise the APIs on a single device.
|
||||
devices[0] = deviceID;
|
||||
queues[0] = queue;
|
||||
ctx = context;
|
||||
}
|
||||
|
||||
// Build the kernel program.
|
||||
if (err = create_single_kernel_helper(ctx, &program, &kernel, 1, &buffer_migrate_kernel_code, "test_buffer_migrate")) {
|
||||
print_error(err, "Failed creating kernel.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
num_devices_limited = num_devices;
|
||||
|
||||
// Allocate memory buffers. 3 buffers (2 input, 1 output) for each sub-device.
|
||||
// If we run out of memory, then restrict the number of sub-devices to be tested.
|
||||
for (i=0; i<num_devices; i++) {
|
||||
bufferA[i] = init_buffer(queues[i], clCreateBuffer(ctx, (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR), sizeof(cl_uint) * BUFFER_SIZE, NULL, &err), A);
|
||||
bufferB[i] = init_buffer(queues[i], clCreateBuffer(ctx, (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR), sizeof(cl_uint) * BUFFER_SIZE, NULL, &err), B);
|
||||
bufferC[i] = clCreateBuffer(ctx, (CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR), sizeof(cl_uint) * BUFFER_SIZE, NULL, &err);
|
||||
|
||||
if ((bufferA[i] == NULL) || (bufferB[i] == NULL) || (bufferC[i] == NULL)) {
|
||||
if (i == 0) {
|
||||
log_error("Failed to allocate even 1 set of buffers.\n");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
num_devices_limited = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// For each partition, we will execute the test kernel with each of the 3 buffers migrated to one of the migrate options
|
||||
for (migrateA=(enum migrations)(0); migrateA<NUMBER_OF_MIGRATIONS; migrateA = (enum migrations)((int)migrateA + 1)) {
|
||||
if (migrateMemObject(migrateA, queues, bufferA, num_devices_limited, flagsA, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (migrateC=(enum migrations)(0); migrateC<NUMBER_OF_MIGRATIONS; migrateC = (enum migrations)((int)migrateC + 1)) {
|
||||
if (migrateMemObject(migrateC, queues, bufferC, num_devices_limited, flagsC, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (migrateB=(enum migrations)(0); migrateB<NUMBER_OF_MIGRATIONS; migrateB = (enum migrations)((int)migrateB + 1)) {
|
||||
if (migrateMemObject(migrateB, queues, bufferB, num_devices_limited, flagsB, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
// Run the test on each of the partitions.
|
||||
for (i=0; i<num_devices_limited; i++) {
|
||||
cl_uint x;
|
||||
|
||||
x = i + test_number;
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 0, sizeof(cl_mem), (const void *)&bufferC[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 0.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 1, sizeof(cl_mem), (const void *)&bufferA[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 1.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 2, sizeof(cl_mem), (const void *)&bufferB[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 2.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 3, sizeof(cl_uint), (const void *)&x)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 3.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clEnqueueNDRangeKernel(queues[i], kernel, 1, NULL, wgs, NULL, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed enqueueing the NDRange kernel.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
// Verify the results as long as neither input is an undefined migration
|
||||
for (i=0; i<num_devices_limited; i++, test_number++) {
|
||||
if (((flagsA[i] | flagsB[i]) & CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED) == 0) {
|
||||
if ((err = clEnqueueReadBuffer(queues[i], bufferC[i], CL_TRUE, 0, sizeof(cl_uint)*BUFFER_SIZE, C, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed reading output buffer.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (j=0; j<BUFFER_SIZE; j++) {
|
||||
cl_uint expected;
|
||||
|
||||
expected = A[j] ^ B[j] ^ test_number;
|
||||
if (C[j] != expected) {
|
||||
log_error("Failed on device %d, work item %4d, expected 0x%08x got 0x%08x (0x%08x ^ 0x%08x ^ 0x%08x)\n", i, j, expected, C[j], A[j], B[j], test_number);
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (failed) goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (restoreBuffer(queues, bufferB, num_devices_limited, flagsB, B) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (restoreBuffer(queues, bufferA, num_devices_limited, flagsA, A) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
// Clean up all the allocted resources create by the test. This includes sub-devices,
|
||||
// command queues, and memory buffers.
|
||||
|
||||
for (i=0; i<max_sub_devices; i++) {
|
||||
// Memory buffer cleanup
|
||||
if (bufferA[i]) {
|
||||
if ((err = clReleaseMemObject(bufferA[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (bufferB[i]) {
|
||||
if ((err = clReleaseMemObject(bufferB[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (bufferC[i]) {
|
||||
if ((err = clReleaseMemObject(bufferC[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (num_devices > 1) {
|
||||
// Command queue cleanup
|
||||
if (queues[i]) {
|
||||
if ((err = clReleaseCommandQueue(queues[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing command queue.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Sub-device cleanup
|
||||
if (devices[i]) {
|
||||
if ((err = clReleaseDevice(devices[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing sub device.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
devices[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Context, program, and kernel cleanup
|
||||
if (program) {
|
||||
if ((err = clReleaseProgram(program)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing program.");
|
||||
failed = 1;
|
||||
}
|
||||
program = NULL;
|
||||
}
|
||||
|
||||
if (kernel) {
|
||||
if ((err = clReleaseKernel(kernel)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing kernel.");
|
||||
failed = 1;
|
||||
}
|
||||
kernel = NULL;
|
||||
}
|
||||
|
||||
if (ctx && (ctx != context)) {
|
||||
if ((err = clReleaseContext(ctx)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing context.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
ctx = NULL;
|
||||
|
||||
if (failed) goto cleanup_allocations;
|
||||
} while (domains);
|
||||
|
||||
cleanup_allocations:
|
||||
if (devices) free(devices);
|
||||
if (queues) free(queues);
|
||||
if (flagsA) free(flagsA);
|
||||
if (flagsB) free(flagsB);
|
||||
if (flagsC) free(flagsC);
|
||||
if (bufferA) free(bufferA);
|
||||
if (bufferB) free(bufferB);
|
||||
if (bufferC) free(bufferC);
|
||||
|
||||
return ((failed) ? -1 : 0);
|
||||
}
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/testHarness.h"
|
||||
|
||||
#define MAX_SUB_DEVICES 16 // Limit the sub-devices to ensure no out of resource errors.
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
// Kernel source code
|
||||
static const char *buffer_migrate_kernel_code =
|
||||
"__kernel void test_buffer_migrate(__global uint *dst, __global uint *src1, __global uint *src2, uint x)\n"
|
||||
"{\n"
|
||||
" int tid = get_global_id(0);\n"
|
||||
" dst[tid] = src1[tid] ^ src2[tid] ^ x;\n"
|
||||
"}\n";
|
||||
|
||||
enum migrations { MIGRATE_PREFERRED, // migrate to the preferred sub-device
|
||||
MIGRATE_NON_PREFERRED, // migrate to a randomly chosen non-preferred sub-device
|
||||
MIGRATE_RANDOM, // migrate to a randomly chosen sub-device with randomly chosen flags
|
||||
NUMBER_OF_MIGRATIONS };
|
||||
|
||||
static cl_mem init_buffer(cl_command_queue cmd_q, cl_mem buffer, cl_uint *data)
|
||||
{
|
||||
cl_int err;
|
||||
|
||||
if (buffer) {
|
||||
if ((err = clEnqueueWriteBuffer(cmd_q, buffer, CL_TRUE, 0, sizeof(cl_uint)*BUFFER_SIZE, data, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed on enqueue write of buffer data.");
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static cl_int migrateMemObject(enum migrations migrate, cl_command_queue *queues, cl_mem *mem_objects, cl_uint num_devices, cl_mem_migration_flags *flags, MTdata d)
|
||||
{
|
||||
cl_uint i, j;
|
||||
cl_int err = CL_SUCCESS;
|
||||
|
||||
for (i=0; i<num_devices; i++) {
|
||||
j = genrand_int32(d) % num_devices;
|
||||
flags[i] = 0;
|
||||
switch (migrate) {
|
||||
case MIGRATE_PREFERRED:
|
||||
// Force the device to be preferred
|
||||
j = i;
|
||||
break;
|
||||
case MIGRATE_NON_PREFERRED:
|
||||
// Coerce the device to be non-preferred
|
||||
if ((j == i) && (num_devices > 1)) j = (j+1) % num_devices;
|
||||
break;
|
||||
case MIGRATE_RANDOM:
|
||||
// Choose a random set of flags
|
||||
flags[i] = (cl_mem_migration_flags)(genrand_int32(d) & (CL_MIGRATE_MEM_OBJECT_HOST | CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED));;
|
||||
break;
|
||||
}
|
||||
if ((err = clEnqueueMigrateMemObjects(queues[j], 1, (const cl_mem *)(&mem_objects[i]), flags[i], 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed migrating memory object.");
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static cl_int restoreBuffer(cl_command_queue *queues, cl_mem *buffers, cl_uint num_devices, cl_mem_migration_flags *flags, cl_uint *buffer)
|
||||
{
|
||||
cl_uint i, j;
|
||||
cl_int err;
|
||||
|
||||
// If the buffer was previously migrated with undefined content, reload the content.
|
||||
|
||||
for (i=0; i<num_devices; i++) {
|
||||
if (flags[i] & CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED) {
|
||||
if ((err = clEnqueueWriteBuffer(queues[i], buffers[i], CL_TRUE, 0, sizeof(cl_uint)*BUFFER_SIZE, buffer, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed on restoration enqueue write of buffer data.");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int test_buffer_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
int failed = 0;
|
||||
cl_uint i, j;
|
||||
cl_int err;
|
||||
cl_uint max_sub_devices = 0;
|
||||
cl_uint num_devices, num_devices_limited;
|
||||
cl_uint A[BUFFER_SIZE], B[BUFFER_SIZE], C[BUFFER_SIZE];
|
||||
cl_uint test_number = 1;
|
||||
cl_device_affinity_domain domain, domains;
|
||||
cl_device_id *devices;
|
||||
cl_command_queue *queues;
|
||||
cl_mem_migration_flags *flagsA, *flagsB, *flagsC;
|
||||
cl_device_partition_property property[] = {CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN, 0, 0};
|
||||
cl_mem *bufferA, *bufferB, *bufferC;
|
||||
cl_program program = NULL;
|
||||
cl_kernel kernel = NULL;
|
||||
cl_context ctx = NULL; // context for all sub-devices
|
||||
enum migrations migrateA, migrateB, migrateC;
|
||||
MTdata d = init_genrand(gRandomSeed);
|
||||
const size_t wgs[1] = {BUFFER_SIZE};
|
||||
|
||||
/* Allocate arrays whose size varies according to the maximum number of sub-devices */
|
||||
if ((err = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(max_sub_devices), &max_sub_devices, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "clGetDeviceInfo(CL_DEVICE_MAX_COMPUTE_UNITS) failed");
|
||||
return -1;
|
||||
}
|
||||
if (max_sub_devices < 1) {
|
||||
log_error("ERROR: Invalid number of compute units returned.\n");
|
||||
return -1;
|
||||
}
|
||||
devices = (cl_device_id *)malloc(max_sub_devices * sizeof(cl_device_id));
|
||||
queues = (cl_command_queue *)malloc(max_sub_devices * sizeof(cl_command_queue));
|
||||
flagsA = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
flagsB = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
flagsC = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
bufferA = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
bufferB = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
bufferC = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
|
||||
if ((devices == NULL) || (queues == NULL) ||
|
||||
(flagsA == NULL) || (flagsB == NULL) || (flagsC == NULL) ||
|
||||
(bufferA == NULL) || (bufferB == NULL) || (bufferC == NULL)) {
|
||||
log_error("ERROR: Failed to successfully allocate required local buffers.\n");
|
||||
failed = -1;
|
||||
goto cleanup_allocations;
|
||||
}
|
||||
|
||||
for (i=0; i<max_sub_devices; i++) {
|
||||
devices[i] = NULL;
|
||||
queues [i] = NULL;
|
||||
bufferA[i] = bufferB[i] = bufferC[i] = NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<BUFFER_SIZE; i++) {
|
||||
A[i] = genrand_int32(d);
|
||||
B[i] = genrand_int32(d);
|
||||
}
|
||||
|
||||
// Attempt to partition the device along each of the allowed affinity domain.
|
||||
if ((err = clGetDeviceInfo(deviceID, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, sizeof(domains), &domains, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "clGetDeviceInfo(CL_PARTITION_AFFINITY_DOMAIN) failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
domains &= (CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE | CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE |
|
||||
CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE | CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE | CL_DEVICE_AFFINITY_DOMAIN_NUMA);
|
||||
|
||||
do {
|
||||
if (domains) {
|
||||
for (domain = 1; (domain & domains) == 0; domain <<= 1) {};
|
||||
domains &= ~domain;
|
||||
} else {
|
||||
domain = 0;
|
||||
}
|
||||
|
||||
// Determine the number of partitions for the device given the specific domain.
|
||||
if (domain) {
|
||||
property[1] = domain;
|
||||
err = clCreateSubDevices(deviceID, (const cl_device_partition_property *)property, -1, NULL, &num_devices);
|
||||
if ((err != CL_SUCCESS) || (num_devices == 0)) {
|
||||
print_error(err, "Obtaining the number of partions by affinity failed.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
num_devices = 1;
|
||||
}
|
||||
|
||||
if (num_devices > 1) {
|
||||
// Create each of the sub-devices and a corresponding context.
|
||||
if ((err = clCreateSubDevices(deviceID, (const cl_device_partition_property *)property, num_devices, devices, &num_devices)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed creating sub devices.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create a context containing all the sub-devices
|
||||
ctx = clCreateContext(NULL, num_devices, devices, notify_callback, NULL, &err);
|
||||
if (ctx == NULL) {
|
||||
print_error(err, "Failed creating context containing the sub-devices.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create a command queue for each sub-device
|
||||
for (i=0; i<num_devices; i++) {
|
||||
if (devices[i]) {
|
||||
if ((queues[i] = clCreateCommandQueue(ctx, devices[i], 0, &err)) == NULL) {
|
||||
print_error(err, "Failed creating command queues.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No partitioning available. Just exercise the APIs on a single device.
|
||||
devices[0] = deviceID;
|
||||
queues[0] = queue;
|
||||
ctx = context;
|
||||
}
|
||||
|
||||
// Build the kernel program.
|
||||
if (err = create_single_kernel_helper(ctx, &program, &kernel, 1, &buffer_migrate_kernel_code, "test_buffer_migrate")) {
|
||||
print_error(err, "Failed creating kernel.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
num_devices_limited = num_devices;
|
||||
|
||||
// Allocate memory buffers. 3 buffers (2 input, 1 output) for each sub-device.
|
||||
// If we run out of memory, then restrict the number of sub-devices to be tested.
|
||||
for (i=0; i<num_devices; i++) {
|
||||
bufferA[i] = init_buffer(queues[i], clCreateBuffer(ctx, (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR), sizeof(cl_uint) * BUFFER_SIZE, NULL, &err), A);
|
||||
bufferB[i] = init_buffer(queues[i], clCreateBuffer(ctx, (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR), sizeof(cl_uint) * BUFFER_SIZE, NULL, &err), B);
|
||||
bufferC[i] = clCreateBuffer(ctx, (CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR), sizeof(cl_uint) * BUFFER_SIZE, NULL, &err);
|
||||
|
||||
if ((bufferA[i] == NULL) || (bufferB[i] == NULL) || (bufferC[i] == NULL)) {
|
||||
if (i == 0) {
|
||||
log_error("Failed to allocate even 1 set of buffers.\n");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
num_devices_limited = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// For each partition, we will execute the test kernel with each of the 3 buffers migrated to one of the migrate options
|
||||
for (migrateA=(enum migrations)(0); migrateA<NUMBER_OF_MIGRATIONS; migrateA = (enum migrations)((int)migrateA + 1)) {
|
||||
if (migrateMemObject(migrateA, queues, bufferA, num_devices_limited, flagsA, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (migrateC=(enum migrations)(0); migrateC<NUMBER_OF_MIGRATIONS; migrateC = (enum migrations)((int)migrateC + 1)) {
|
||||
if (migrateMemObject(migrateC, queues, bufferC, num_devices_limited, flagsC, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (migrateB=(enum migrations)(0); migrateB<NUMBER_OF_MIGRATIONS; migrateB = (enum migrations)((int)migrateB + 1)) {
|
||||
if (migrateMemObject(migrateB, queues, bufferB, num_devices_limited, flagsB, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
// Run the test on each of the partitions.
|
||||
for (i=0; i<num_devices_limited; i++) {
|
||||
cl_uint x;
|
||||
|
||||
x = i + test_number;
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 0, sizeof(cl_mem), (const void *)&bufferC[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 0.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 1, sizeof(cl_mem), (const void *)&bufferA[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 1.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 2, sizeof(cl_mem), (const void *)&bufferB[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 2.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 3, sizeof(cl_uint), (const void *)&x)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 3.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clEnqueueNDRangeKernel(queues[i], kernel, 1, NULL, wgs, NULL, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed enqueueing the NDRange kernel.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
// Verify the results as long as neither input is an undefined migration
|
||||
for (i=0; i<num_devices_limited; i++, test_number++) {
|
||||
if (((flagsA[i] | flagsB[i]) & CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED) == 0) {
|
||||
if ((err = clEnqueueReadBuffer(queues[i], bufferC[i], CL_TRUE, 0, sizeof(cl_uint)*BUFFER_SIZE, C, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed reading output buffer.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (j=0; j<BUFFER_SIZE; j++) {
|
||||
cl_uint expected;
|
||||
|
||||
expected = A[j] ^ B[j] ^ test_number;
|
||||
if (C[j] != expected) {
|
||||
log_error("Failed on device %d, work item %4d, expected 0x%08x got 0x%08x (0x%08x ^ 0x%08x ^ 0x%08x)\n", i, j, expected, C[j], A[j], B[j], test_number);
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (failed) goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (restoreBuffer(queues, bufferB, num_devices_limited, flagsB, B) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (restoreBuffer(queues, bufferA, num_devices_limited, flagsA, A) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
// Clean up all the allocted resources create by the test. This includes sub-devices,
|
||||
// command queues, and memory buffers.
|
||||
|
||||
for (i=0; i<max_sub_devices; i++) {
|
||||
// Memory buffer cleanup
|
||||
if (bufferA[i]) {
|
||||
if ((err = clReleaseMemObject(bufferA[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (bufferB[i]) {
|
||||
if ((err = clReleaseMemObject(bufferB[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (bufferC[i]) {
|
||||
if ((err = clReleaseMemObject(bufferC[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (num_devices > 1) {
|
||||
// Command queue cleanup
|
||||
if (queues[i]) {
|
||||
if ((err = clReleaseCommandQueue(queues[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing command queue.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Sub-device cleanup
|
||||
if (devices[i]) {
|
||||
if ((err = clReleaseDevice(devices[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing sub device.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
devices[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Context, program, and kernel cleanup
|
||||
if (program) {
|
||||
if ((err = clReleaseProgram(program)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing program.");
|
||||
failed = 1;
|
||||
}
|
||||
program = NULL;
|
||||
}
|
||||
|
||||
if (kernel) {
|
||||
if ((err = clReleaseKernel(kernel)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing kernel.");
|
||||
failed = 1;
|
||||
}
|
||||
kernel = NULL;
|
||||
}
|
||||
|
||||
if (ctx && (ctx != context)) {
|
||||
if ((err = clReleaseContext(ctx)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing context.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
ctx = NULL;
|
||||
|
||||
if (failed) goto cleanup_allocations;
|
||||
} while (domains);
|
||||
|
||||
cleanup_allocations:
|
||||
if (devices) free(devices);
|
||||
if (queues) free(queues);
|
||||
if (flagsA) free(flagsA);
|
||||
if (flagsB) free(flagsB);
|
||||
if (flagsC) free(flagsC);
|
||||
if (bufferA) free(bufferA);
|
||||
if (bufferB) free(bufferB);
|
||||
if (bufferC) free(bufferC);
|
||||
|
||||
return ((failed) ? -1 : 0);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,479 +1,479 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
|
||||
#define MAX_SUB_DEVICES 16 // Limit the sub-devices to ensure no out of resource errors.
|
||||
#define MEM_OBJ_SIZE 1024
|
||||
#define IMAGE_DIM 16
|
||||
|
||||
// Kernel source code
|
||||
static const char *image_migrate_kernel_code =
|
||||
"__kernel void test_image_migrate(write_only image2d_t dst, read_only image2d_t src1,\n"
|
||||
" read_only image2d_t src2, sampler_t sampler, uint x)\n"
|
||||
"{\n"
|
||||
" int tidX = get_global_id(0), tidY = get_global_id(1);\n"
|
||||
" int2 coords = (int2) {tidX, tidY};\n"
|
||||
" uint4 val = read_imageui(src1, sampler, coords) ^\n"
|
||||
" read_imageui(src2, sampler, coords) ^\n"
|
||||
" x;\n"
|
||||
" write_imageui(dst, coords, val);\n"
|
||||
"}\n";
|
||||
|
||||
enum migrations { MIGRATE_PREFERRED, // migrate to the preferred sub-device
|
||||
MIGRATE_NON_PREFERRED, // migrate to a randomly chosen non-preferred sub-device
|
||||
MIGRATE_RANDOM, // migrate to a randomly chosen sub-device with randomly chosen flags
|
||||
NUMBER_OF_MIGRATIONS };
|
||||
|
||||
static cl_mem init_image(cl_command_queue cmd_q, cl_mem image, cl_uint *data)
|
||||
{
|
||||
cl_int err;
|
||||
|
||||
size_t origin[3] = {0, 0, 0};
|
||||
size_t region[3] = {IMAGE_DIM, IMAGE_DIM, 1};
|
||||
|
||||
if (image) {
|
||||
if ((err = clEnqueueWriteImage(cmd_q, image, CL_TRUE,
|
||||
origin, region, 0, 0, data, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed on enqueue write of image data.");
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
static cl_int migrateMemObject(enum migrations migrate, cl_command_queue *queues, cl_mem *mem_objects,
|
||||
cl_uint num_devices, cl_mem_migration_flags *flags, MTdata d)
|
||||
{
|
||||
cl_uint i, j;
|
||||
cl_int err = CL_SUCCESS;
|
||||
|
||||
for (i=0; i<num_devices; i++) {
|
||||
j = genrand_int32(d) % num_devices;
|
||||
flags[i] = 0;
|
||||
switch (migrate) {
|
||||
case MIGRATE_PREFERRED:
|
||||
// Force the device to be preferred
|
||||
j = i;
|
||||
break;
|
||||
case MIGRATE_NON_PREFERRED:
|
||||
// Coerce the device to be non-preferred
|
||||
if ((j == i) && (num_devices > 1)) j = (j+1) % num_devices;
|
||||
break;
|
||||
case MIGRATE_RANDOM:
|
||||
// Choose a random set of flags
|
||||
flags[i] = (cl_mem_migration_flags)(genrand_int32(d) & (CL_MIGRATE_MEM_OBJECT_HOST | CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED));
|
||||
break;
|
||||
}
|
||||
if ((err = clEnqueueMigrateMemObjects(queues[j], 1, (const cl_mem *)(&mem_objects[i]),
|
||||
flags[i], 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed migrating memory object.");
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static cl_int restoreImage(cl_command_queue *queues, cl_mem *mem_objects, cl_uint num_devices,
|
||||
cl_mem_migration_flags *flags, cl_uint *buffer)
|
||||
{
|
||||
cl_uint i;
|
||||
cl_int err;
|
||||
|
||||
const size_t origin[3] = {0, 0, 0};
|
||||
const size_t region[3] = {IMAGE_DIM, IMAGE_DIM, 1};
|
||||
|
||||
// If the image was previously migrated with undefined content, reload the content.
|
||||
|
||||
for (i=0; i<num_devices; i++) {
|
||||
if (flags[i] & CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED) {
|
||||
if ((err = clEnqueueWriteImage(queues[i], mem_objects[i], CL_TRUE,
|
||||
origin, region, 0, 0, buffer, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed on restoration enqueue write of image data.");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int test_image_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
int failed = 0;
|
||||
cl_uint i, j;
|
||||
cl_int err;
|
||||
cl_uint max_sub_devices = 0;
|
||||
cl_uint num_devices, num_devices_limited;
|
||||
cl_uint A[MEM_OBJ_SIZE], B[MEM_OBJ_SIZE], C[MEM_OBJ_SIZE];
|
||||
cl_uint test_number = 1;
|
||||
cl_device_affinity_domain domain, domains;
|
||||
cl_device_id *devices;
|
||||
cl_command_queue *queues;
|
||||
cl_mem_migration_flags *flagsA, *flagsB, *flagsC;
|
||||
cl_device_partition_property property[] = {CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN, 0, 0};
|
||||
cl_mem *imageA, *imageB, *imageC;
|
||||
cl_mem_flags flags;
|
||||
cl_image_format format;
|
||||
cl_sampler sampler = NULL;
|
||||
cl_program program = NULL;
|
||||
cl_kernel kernel = NULL;
|
||||
cl_context ctx = NULL;
|
||||
enum migrations migrateA, migrateB, migrateC;
|
||||
MTdata d = init_genrand(gRandomSeed);
|
||||
const size_t wgs[2] = {IMAGE_DIM, IMAGE_DIM};
|
||||
const size_t wls[2] = {1, 1};
|
||||
|
||||
// Check for image support.
|
||||
if(checkForImageSupport(deviceID) == CL_IMAGE_FORMAT_NOT_SUPPORTED) {
|
||||
log_info("Device does not support images. Skipping test.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allocate arrays whose size varies according to the maximum number of sub-devices.
|
||||
if ((err = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(max_sub_devices), &max_sub_devices, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "clGetDeviceInfo(CL_DEVICE_MAX_COMPUTE_UNITS) failed");
|
||||
return -1;
|
||||
}
|
||||
if (max_sub_devices < 1) {
|
||||
log_error("ERROR: Invalid number of compute units returned.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
devices = (cl_device_id *)malloc(max_sub_devices * sizeof(cl_device_id));
|
||||
queues = (cl_command_queue *)malloc(max_sub_devices * sizeof(cl_command_queue));
|
||||
flagsA = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
flagsB = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
flagsC = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
imageA = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
imageB = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
imageC = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
|
||||
if ((devices == NULL) || (queues == NULL) ||
|
||||
(flagsA == NULL) || (flagsB == NULL) || (flagsC == NULL) ||
|
||||
(imageA == NULL) || (imageB == NULL) || (imageC == NULL)) {
|
||||
log_error("ERROR: Failed to successfully allocate required local buffers.\n");
|
||||
failed = -1;
|
||||
goto cleanup_allocations;
|
||||
}
|
||||
|
||||
for (i=0; i<max_sub_devices; i++) {
|
||||
devices[i] = NULL;
|
||||
queues [i] = NULL;
|
||||
imageA[i] = imageB[i] = imageC[i] = NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<MEM_OBJ_SIZE; i++) {
|
||||
A[i] = genrand_int32(d);
|
||||
B[i] = genrand_int32(d);
|
||||
}
|
||||
|
||||
// Set image format.
|
||||
format.image_channel_order = CL_RGBA;
|
||||
format.image_channel_data_type = CL_UNSIGNED_INT32;
|
||||
|
||||
|
||||
// Attempt to partition the device along each of the allowed affinity domain.
|
||||
if ((err = clGetDeviceInfo(deviceID, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, sizeof(domains), &domains, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "clGetDeviceInfo(CL_PARTITION_AFFINITY_DOMAIN) failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
domains &= (CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE | CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE |
|
||||
CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE | CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE | CL_DEVICE_AFFINITY_DOMAIN_NUMA);
|
||||
|
||||
do {
|
||||
if (domains) {
|
||||
for (domain = 1; (domain & domains) == 0; domain <<= 1) {};
|
||||
domains &= ~domain;
|
||||
} else {
|
||||
domain = 0;
|
||||
}
|
||||
|
||||
// Determine the number of partitions for the device given the specific domain.
|
||||
if (domain) {
|
||||
property[1] = domain;
|
||||
err = clCreateSubDevices(deviceID, (const cl_device_partition_property *)property, -1, NULL, &num_devices);
|
||||
if ((err != CL_SUCCESS) || (num_devices == 0)) {
|
||||
print_error(err, "Obtaining the number of partions by affinity failed.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
num_devices = 1;
|
||||
}
|
||||
|
||||
if (num_devices > 1) {
|
||||
// Create each of the sub-devices and a corresponding context.
|
||||
if ((err = clCreateSubDevices(deviceID, (const cl_device_partition_property *)property, num_devices, devices, &num_devices)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed creating sub devices.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create a context containing all the sub-devices
|
||||
ctx = clCreateContext(NULL, num_devices, devices, notify_callback, NULL, &err);
|
||||
if (ctx == NULL) {
|
||||
print_error(err, "Failed creating context containing the sub-devices.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create a command queue for each sub-device
|
||||
for (i=0; i<num_devices; i++) {
|
||||
if (devices[i]) {
|
||||
if ((queues[i] = clCreateCommandQueue(ctx, devices[i], 0, &err)) == NULL) {
|
||||
print_error(err, "Failed creating command queues.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No partitioning available. Just exercise the APIs on a single device.
|
||||
devices[0] = deviceID;
|
||||
queues[0] = queue;
|
||||
ctx = context;
|
||||
}
|
||||
|
||||
// Build the kernel program.
|
||||
if (err = create_single_kernel_helper(ctx, &program, &kernel, 1, &image_migrate_kernel_code, "test_image_migrate")) {
|
||||
print_error(err, "Failed creating kernel.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create sampler.
|
||||
sampler = clCreateSampler(context, CL_FALSE, CL_ADDRESS_CLAMP, CL_FILTER_NEAREST, &err);
|
||||
if ((err != CL_SUCCESS) || !sampler) {
|
||||
print_error(err, "Failed to create a sampler.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
num_devices_limited = num_devices;
|
||||
|
||||
// Allocate memory buffers. 3 buffers (2 input, 1 output) for each sub-device.
|
||||
// If we run out of memory, then restrict the number of sub-devices to be tested.
|
||||
for (i=0; i<num_devices; i++) {
|
||||
imageA[i] = init_image(queues[i], create_image_2d(ctx, (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR),
|
||||
&format, IMAGE_DIM, IMAGE_DIM, 0, NULL, &err), A);
|
||||
imageB[i] = init_image(queues[i], create_image_2d(ctx, (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR),
|
||||
&format, IMAGE_DIM, IMAGE_DIM, 0, NULL, &err), B);
|
||||
imageC[i] = create_image_2d(ctx, (CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR),
|
||||
&format, IMAGE_DIM, IMAGE_DIM, 0, NULL, &err);
|
||||
|
||||
if ((imageA[i] == NULL) || (imageB[i] == NULL) || (imageC[i] == NULL)) {
|
||||
if (i == 0) {
|
||||
log_error("Failed to allocate even 1 set of buffers.\n");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
num_devices_limited = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// For each partition, we will execute the test kernel with each of the 3 buffers migrated to one of the migrate options
|
||||
for (migrateA=(enum migrations)(0); migrateA<NUMBER_OF_MIGRATIONS; migrateA = (enum migrations)((int)migrateA + 1)) {
|
||||
if (migrateMemObject(migrateA, queues, imageA, num_devices_limited, flagsA, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (migrateC=(enum migrations)(0); migrateC<NUMBER_OF_MIGRATIONS; migrateC = (enum migrations)((int)migrateC + 1)) {
|
||||
if (migrateMemObject(migrateC, queues, imageC, num_devices_limited, flagsC, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (migrateB=(enum migrations)(0); migrateB<NUMBER_OF_MIGRATIONS; migrateB = (enum migrations)((int)migrateB + 1)) {
|
||||
if (migrateMemObject(migrateB, queues, imageB, num_devices_limited, flagsB, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
// Run the test on each of the partitions.
|
||||
for (i=0; i<num_devices_limited; i++) {
|
||||
cl_uint x;
|
||||
|
||||
x = i + test_number;
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 0, sizeof(cl_mem), (const void *)&imageC[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 0.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 1, sizeof(cl_mem), (const void *)&imageA[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 1.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 2, sizeof(cl_mem), (const void *)&imageB[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 2.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 3, sizeof(cl_sampler), (const void *)&sampler)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 3.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 4, sizeof(cl_uint), (const void *)&x)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 4.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clEnqueueNDRangeKernel(queues[i], kernel, 2, NULL, wgs, wls, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed enqueueing the NDRange kernel.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
// Verify the results as long as neither input is an undefined migration
|
||||
const size_t origin[3] = {0, 0, 0};
|
||||
const size_t region[3] = {IMAGE_DIM, IMAGE_DIM, 1};
|
||||
|
||||
for (i=0; i<num_devices_limited; i++, test_number++) {
|
||||
if (((flagsA[i] | flagsB[i]) & CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED) == 0) {
|
||||
if ((err = clEnqueueReadImage(queues[i], imageC[i], CL_TRUE,
|
||||
origin, region, 0, 0, C, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed reading output buffer.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (j=0; j<MEM_OBJ_SIZE; j++) {
|
||||
cl_uint expected;
|
||||
|
||||
expected = A[j] ^ B[j] ^ test_number;
|
||||
if (C[j] != expected) {
|
||||
log_error("Failed on device %d, work item %4d, expected 0x%08x got 0x%08x (0x%08x ^ 0x%08x ^ 0x%08x)\n", i, j, expected, C[j], A[j], B[j], test_number);
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (failed) goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (restoreImage(queues, imageB, num_devices_limited, flagsB, B) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (restoreImage(queues, imageA, num_devices_limited, flagsA, A) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
// Clean up all the allocted resources create by the test. This includes sub-devices,
|
||||
// command queues, and memory buffers.
|
||||
|
||||
for (i=0; i<max_sub_devices; i++) {
|
||||
// Memory buffer cleanup
|
||||
if (imageA[i]) {
|
||||
if ((err = clReleaseMemObject(imageA[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (imageB[i]) {
|
||||
if ((err = clReleaseMemObject(imageB[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (imageC[i]) {
|
||||
if ((err = clReleaseMemObject(imageC[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_devices > 1) {
|
||||
// Command queue cleanup
|
||||
if (queues[i]) {
|
||||
if ((err = clReleaseCommandQueue(queues[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing command queue.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Sub-device cleanup
|
||||
if (devices[i]) {
|
||||
if ((err = clReleaseDevice(devices[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing sub device.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
devices[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Sampler cleanup
|
||||
if (sampler) {
|
||||
if ((err = clReleaseSampler(sampler)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing sampler.");
|
||||
failed = 1;
|
||||
}
|
||||
sampler = NULL;
|
||||
}
|
||||
|
||||
// Context, program, and kernel cleanup
|
||||
if (program) {
|
||||
if ((err = clReleaseProgram(program)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing program.");
|
||||
failed = 1;
|
||||
}
|
||||
program = NULL;
|
||||
}
|
||||
|
||||
if (kernel) {
|
||||
if ((err = clReleaseKernel(kernel)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing kernel.");
|
||||
failed = 1;
|
||||
}
|
||||
kernel = NULL;
|
||||
}
|
||||
|
||||
if (ctx && (ctx != context)) {
|
||||
if ((err = clReleaseContext(ctx)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing context.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
ctx = NULL;
|
||||
|
||||
if (failed) goto cleanup_allocations;
|
||||
} while (domains);
|
||||
|
||||
cleanup_allocations:
|
||||
if (devices) free(devices);
|
||||
if (queues) free(queues);
|
||||
if (flagsA) free(flagsA);
|
||||
if (flagsB) free(flagsB);
|
||||
if (flagsC) free(flagsC);
|
||||
if (imageA) free(imageA);
|
||||
if (imageB) free(imageB);
|
||||
if (imageC) free(imageC);
|
||||
|
||||
return ((failed) ? -1 : 0);
|
||||
}
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "procs.h"
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
|
||||
#define MAX_SUB_DEVICES 16 // Limit the sub-devices to ensure no out of resource errors.
|
||||
#define MEM_OBJ_SIZE 1024
|
||||
#define IMAGE_DIM 16
|
||||
|
||||
// Kernel source code
|
||||
static const char *image_migrate_kernel_code =
|
||||
"__kernel void test_image_migrate(write_only image2d_t dst, read_only image2d_t src1,\n"
|
||||
" read_only image2d_t src2, sampler_t sampler, uint x)\n"
|
||||
"{\n"
|
||||
" int tidX = get_global_id(0), tidY = get_global_id(1);\n"
|
||||
" int2 coords = (int2) {tidX, tidY};\n"
|
||||
" uint4 val = read_imageui(src1, sampler, coords) ^\n"
|
||||
" read_imageui(src2, sampler, coords) ^\n"
|
||||
" x;\n"
|
||||
" write_imageui(dst, coords, val);\n"
|
||||
"}\n";
|
||||
|
||||
enum migrations { MIGRATE_PREFERRED, // migrate to the preferred sub-device
|
||||
MIGRATE_NON_PREFERRED, // migrate to a randomly chosen non-preferred sub-device
|
||||
MIGRATE_RANDOM, // migrate to a randomly chosen sub-device with randomly chosen flags
|
||||
NUMBER_OF_MIGRATIONS };
|
||||
|
||||
static cl_mem init_image(cl_command_queue cmd_q, cl_mem image, cl_uint *data)
|
||||
{
|
||||
cl_int err;
|
||||
|
||||
size_t origin[3] = {0, 0, 0};
|
||||
size_t region[3] = {IMAGE_DIM, IMAGE_DIM, 1};
|
||||
|
||||
if (image) {
|
||||
if ((err = clEnqueueWriteImage(cmd_q, image, CL_TRUE,
|
||||
origin, region, 0, 0, data, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed on enqueue write of image data.");
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
static cl_int migrateMemObject(enum migrations migrate, cl_command_queue *queues, cl_mem *mem_objects,
|
||||
cl_uint num_devices, cl_mem_migration_flags *flags, MTdata d)
|
||||
{
|
||||
cl_uint i, j;
|
||||
cl_int err = CL_SUCCESS;
|
||||
|
||||
for (i=0; i<num_devices; i++) {
|
||||
j = genrand_int32(d) % num_devices;
|
||||
flags[i] = 0;
|
||||
switch (migrate) {
|
||||
case MIGRATE_PREFERRED:
|
||||
// Force the device to be preferred
|
||||
j = i;
|
||||
break;
|
||||
case MIGRATE_NON_PREFERRED:
|
||||
// Coerce the device to be non-preferred
|
||||
if ((j == i) && (num_devices > 1)) j = (j+1) % num_devices;
|
||||
break;
|
||||
case MIGRATE_RANDOM:
|
||||
// Choose a random set of flags
|
||||
flags[i] = (cl_mem_migration_flags)(genrand_int32(d) & (CL_MIGRATE_MEM_OBJECT_HOST | CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED));
|
||||
break;
|
||||
}
|
||||
if ((err = clEnqueueMigrateMemObjects(queues[j], 1, (const cl_mem *)(&mem_objects[i]),
|
||||
flags[i], 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed migrating memory object.");
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static cl_int restoreImage(cl_command_queue *queues, cl_mem *mem_objects, cl_uint num_devices,
|
||||
cl_mem_migration_flags *flags, cl_uint *buffer)
|
||||
{
|
||||
cl_uint i;
|
||||
cl_int err;
|
||||
|
||||
const size_t origin[3] = {0, 0, 0};
|
||||
const size_t region[3] = {IMAGE_DIM, IMAGE_DIM, 1};
|
||||
|
||||
// If the image was previously migrated with undefined content, reload the content.
|
||||
|
||||
for (i=0; i<num_devices; i++) {
|
||||
if (flags[i] & CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED) {
|
||||
if ((err = clEnqueueWriteImage(queues[i], mem_objects[i], CL_TRUE,
|
||||
origin, region, 0, 0, buffer, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed on restoration enqueue write of image data.");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int test_image_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
int failed = 0;
|
||||
cl_uint i, j;
|
||||
cl_int err;
|
||||
cl_uint max_sub_devices = 0;
|
||||
cl_uint num_devices, num_devices_limited;
|
||||
cl_uint A[MEM_OBJ_SIZE], B[MEM_OBJ_SIZE], C[MEM_OBJ_SIZE];
|
||||
cl_uint test_number = 1;
|
||||
cl_device_affinity_domain domain, domains;
|
||||
cl_device_id *devices;
|
||||
cl_command_queue *queues;
|
||||
cl_mem_migration_flags *flagsA, *flagsB, *flagsC;
|
||||
cl_device_partition_property property[] = {CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN, 0, 0};
|
||||
cl_mem *imageA, *imageB, *imageC;
|
||||
cl_mem_flags flags;
|
||||
cl_image_format format;
|
||||
cl_sampler sampler = NULL;
|
||||
cl_program program = NULL;
|
||||
cl_kernel kernel = NULL;
|
||||
cl_context ctx = NULL;
|
||||
enum migrations migrateA, migrateB, migrateC;
|
||||
MTdata d = init_genrand(gRandomSeed);
|
||||
const size_t wgs[2] = {IMAGE_DIM, IMAGE_DIM};
|
||||
const size_t wls[2] = {1, 1};
|
||||
|
||||
// Check for image support.
|
||||
if(checkForImageSupport(deviceID) == CL_IMAGE_FORMAT_NOT_SUPPORTED) {
|
||||
log_info("Device does not support images. Skipping test.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allocate arrays whose size varies according to the maximum number of sub-devices.
|
||||
if ((err = clGetDeviceInfo(deviceID, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(max_sub_devices), &max_sub_devices, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "clGetDeviceInfo(CL_DEVICE_MAX_COMPUTE_UNITS) failed");
|
||||
return -1;
|
||||
}
|
||||
if (max_sub_devices < 1) {
|
||||
log_error("ERROR: Invalid number of compute units returned.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
devices = (cl_device_id *)malloc(max_sub_devices * sizeof(cl_device_id));
|
||||
queues = (cl_command_queue *)malloc(max_sub_devices * sizeof(cl_command_queue));
|
||||
flagsA = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
flagsB = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
flagsC = (cl_mem_migration_flags *)malloc(max_sub_devices * sizeof(cl_mem_migration_flags));
|
||||
imageA = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
imageB = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
imageC = (cl_mem *)malloc(max_sub_devices * sizeof(cl_mem));
|
||||
|
||||
if ((devices == NULL) || (queues == NULL) ||
|
||||
(flagsA == NULL) || (flagsB == NULL) || (flagsC == NULL) ||
|
||||
(imageA == NULL) || (imageB == NULL) || (imageC == NULL)) {
|
||||
log_error("ERROR: Failed to successfully allocate required local buffers.\n");
|
||||
failed = -1;
|
||||
goto cleanup_allocations;
|
||||
}
|
||||
|
||||
for (i=0; i<max_sub_devices; i++) {
|
||||
devices[i] = NULL;
|
||||
queues [i] = NULL;
|
||||
imageA[i] = imageB[i] = imageC[i] = NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<MEM_OBJ_SIZE; i++) {
|
||||
A[i] = genrand_int32(d);
|
||||
B[i] = genrand_int32(d);
|
||||
}
|
||||
|
||||
// Set image format.
|
||||
format.image_channel_order = CL_RGBA;
|
||||
format.image_channel_data_type = CL_UNSIGNED_INT32;
|
||||
|
||||
|
||||
// Attempt to partition the device along each of the allowed affinity domain.
|
||||
if ((err = clGetDeviceInfo(deviceID, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, sizeof(domains), &domains, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "clGetDeviceInfo(CL_PARTITION_AFFINITY_DOMAIN) failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
domains &= (CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE | CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE |
|
||||
CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE | CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE | CL_DEVICE_AFFINITY_DOMAIN_NUMA);
|
||||
|
||||
do {
|
||||
if (domains) {
|
||||
for (domain = 1; (domain & domains) == 0; domain <<= 1) {};
|
||||
domains &= ~domain;
|
||||
} else {
|
||||
domain = 0;
|
||||
}
|
||||
|
||||
// Determine the number of partitions for the device given the specific domain.
|
||||
if (domain) {
|
||||
property[1] = domain;
|
||||
err = clCreateSubDevices(deviceID, (const cl_device_partition_property *)property, -1, NULL, &num_devices);
|
||||
if ((err != CL_SUCCESS) || (num_devices == 0)) {
|
||||
print_error(err, "Obtaining the number of partions by affinity failed.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
num_devices = 1;
|
||||
}
|
||||
|
||||
if (num_devices > 1) {
|
||||
// Create each of the sub-devices and a corresponding context.
|
||||
if ((err = clCreateSubDevices(deviceID, (const cl_device_partition_property *)property, num_devices, devices, &num_devices)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed creating sub devices.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create a context containing all the sub-devices
|
||||
ctx = clCreateContext(NULL, num_devices, devices, notify_callback, NULL, &err);
|
||||
if (ctx == NULL) {
|
||||
print_error(err, "Failed creating context containing the sub-devices.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create a command queue for each sub-device
|
||||
for (i=0; i<num_devices; i++) {
|
||||
if (devices[i]) {
|
||||
if ((queues[i] = clCreateCommandQueue(ctx, devices[i], 0, &err)) == NULL) {
|
||||
print_error(err, "Failed creating command queues.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No partitioning available. Just exercise the APIs on a single device.
|
||||
devices[0] = deviceID;
|
||||
queues[0] = queue;
|
||||
ctx = context;
|
||||
}
|
||||
|
||||
// Build the kernel program.
|
||||
if (err = create_single_kernel_helper(ctx, &program, &kernel, 1, &image_migrate_kernel_code, "test_image_migrate")) {
|
||||
print_error(err, "Failed creating kernel.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create sampler.
|
||||
sampler = clCreateSampler(context, CL_FALSE, CL_ADDRESS_CLAMP, CL_FILTER_NEAREST, &err);
|
||||
if ((err != CL_SUCCESS) || !sampler) {
|
||||
print_error(err, "Failed to create a sampler.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
num_devices_limited = num_devices;
|
||||
|
||||
// Allocate memory buffers. 3 buffers (2 input, 1 output) for each sub-device.
|
||||
// If we run out of memory, then restrict the number of sub-devices to be tested.
|
||||
for (i=0; i<num_devices; i++) {
|
||||
imageA[i] = init_image(queues[i], create_image_2d(ctx, (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR),
|
||||
&format, IMAGE_DIM, IMAGE_DIM, 0, NULL, &err), A);
|
||||
imageB[i] = init_image(queues[i], create_image_2d(ctx, (CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR),
|
||||
&format, IMAGE_DIM, IMAGE_DIM, 0, NULL, &err), B);
|
||||
imageC[i] = create_image_2d(ctx, (CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR),
|
||||
&format, IMAGE_DIM, IMAGE_DIM, 0, NULL, &err);
|
||||
|
||||
if ((imageA[i] == NULL) || (imageB[i] == NULL) || (imageC[i] == NULL)) {
|
||||
if (i == 0) {
|
||||
log_error("Failed to allocate even 1 set of buffers.\n");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
num_devices_limited = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// For each partition, we will execute the test kernel with each of the 3 buffers migrated to one of the migrate options
|
||||
for (migrateA=(enum migrations)(0); migrateA<NUMBER_OF_MIGRATIONS; migrateA = (enum migrations)((int)migrateA + 1)) {
|
||||
if (migrateMemObject(migrateA, queues, imageA, num_devices_limited, flagsA, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (migrateC=(enum migrations)(0); migrateC<NUMBER_OF_MIGRATIONS; migrateC = (enum migrations)((int)migrateC + 1)) {
|
||||
if (migrateMemObject(migrateC, queues, imageC, num_devices_limited, flagsC, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (migrateB=(enum migrations)(0); migrateB<NUMBER_OF_MIGRATIONS; migrateB = (enum migrations)((int)migrateB + 1)) {
|
||||
if (migrateMemObject(migrateB, queues, imageB, num_devices_limited, flagsB, d) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
// Run the test on each of the partitions.
|
||||
for (i=0; i<num_devices_limited; i++) {
|
||||
cl_uint x;
|
||||
|
||||
x = i + test_number;
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 0, sizeof(cl_mem), (const void *)&imageC[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 0.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 1, sizeof(cl_mem), (const void *)&imageA[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 1.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 2, sizeof(cl_mem), (const void *)&imageB[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 2.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 3, sizeof(cl_sampler), (const void *)&sampler)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 3.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clSetKernelArg(kernel, 4, sizeof(cl_uint), (const void *)&x)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed set kernel argument 4.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = clEnqueueNDRangeKernel(queues[i], kernel, 2, NULL, wgs, wls, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed enqueueing the NDRange kernel.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
// Verify the results as long as neither input is an undefined migration
|
||||
const size_t origin[3] = {0, 0, 0};
|
||||
const size_t region[3] = {IMAGE_DIM, IMAGE_DIM, 1};
|
||||
|
||||
for (i=0; i<num_devices_limited; i++, test_number++) {
|
||||
if (((flagsA[i] | flagsB[i]) & CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED) == 0) {
|
||||
if ((err = clEnqueueReadImage(queues[i], imageC[i], CL_TRUE,
|
||||
origin, region, 0, 0, C, 0, NULL, NULL)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed reading output buffer.");
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
for (j=0; j<MEM_OBJ_SIZE; j++) {
|
||||
cl_uint expected;
|
||||
|
||||
expected = A[j] ^ B[j] ^ test_number;
|
||||
if (C[j] != expected) {
|
||||
log_error("Failed on device %d, work item %4d, expected 0x%08x got 0x%08x (0x%08x ^ 0x%08x ^ 0x%08x)\n", i, j, expected, C[j], A[j], B[j], test_number);
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (failed) goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (restoreImage(queues, imageB, num_devices_limited, flagsB, B) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (restoreImage(queues, imageA, num_devices_limited, flagsA, A) != CL_SUCCESS) {
|
||||
failed = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
// Clean up all the allocted resources create by the test. This includes sub-devices,
|
||||
// command queues, and memory buffers.
|
||||
|
||||
for (i=0; i<max_sub_devices; i++) {
|
||||
// Memory buffer cleanup
|
||||
if (imageA[i]) {
|
||||
if ((err = clReleaseMemObject(imageA[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (imageB[i]) {
|
||||
if ((err = clReleaseMemObject(imageB[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
if (imageC[i]) {
|
||||
if ((err = clReleaseMemObject(imageC[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing memory object.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_devices > 1) {
|
||||
// Command queue cleanup
|
||||
if (queues[i]) {
|
||||
if ((err = clReleaseCommandQueue(queues[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing command queue.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Sub-device cleanup
|
||||
if (devices[i]) {
|
||||
if ((err = clReleaseDevice(devices[i])) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing sub device.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
devices[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Sampler cleanup
|
||||
if (sampler) {
|
||||
if ((err = clReleaseSampler(sampler)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing sampler.");
|
||||
failed = 1;
|
||||
}
|
||||
sampler = NULL;
|
||||
}
|
||||
|
||||
// Context, program, and kernel cleanup
|
||||
if (program) {
|
||||
if ((err = clReleaseProgram(program)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing program.");
|
||||
failed = 1;
|
||||
}
|
||||
program = NULL;
|
||||
}
|
||||
|
||||
if (kernel) {
|
||||
if ((err = clReleaseKernel(kernel)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing kernel.");
|
||||
failed = 1;
|
||||
}
|
||||
kernel = NULL;
|
||||
}
|
||||
|
||||
if (ctx && (ctx != context)) {
|
||||
if ((err = clReleaseContext(ctx)) != CL_SUCCESS) {
|
||||
print_error(err, "Failed releasing context.");
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
ctx = NULL;
|
||||
|
||||
if (failed) goto cleanup_allocations;
|
||||
} while (domains);
|
||||
|
||||
cleanup_allocations:
|
||||
if (devices) free(devices);
|
||||
if (queues) free(queues);
|
||||
if (flagsA) free(flagsA);
|
||||
if (flagsB) free(flagsB);
|
||||
if (flagsC) free(flagsC);
|
||||
if (imageA) free(imageA);
|
||||
if (imageB) free(imageB);
|
||||
if (imageC) free(imageC);
|
||||
|
||||
return ((failed) ? -1 : 0);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user