1 //
2 // Copyright (c) 2017 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "../testBase.h"
17
18 extern int test_get_image_info_single( cl_context context, image_descriptor *imageInfo, MTdata d, cl_mem_flags flags, size_t row_pitch, size_t slice_pitch );
19
20
test_get_image_info_1D(cl_device_id device,cl_context context,cl_image_format * format,cl_mem_flags flags)21 int test_get_image_info_1D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags )
22 {
23 size_t maxWidth;
24 cl_ulong maxAllocSize, memSize;
25 image_descriptor imageInfo = { 0 };
26 RandomSeed seed( gRandomSeed );
27 size_t pixelSize;
28
29 cl_mem_flags all_host_ptr_flags[5] = {
30 flags,
31 CL_MEM_ALLOC_HOST_PTR | flags,
32 CL_MEM_COPY_HOST_PTR | flags,
33 CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | flags,
34 CL_MEM_USE_HOST_PTR | flags
35 };
36
37 memset(&imageInfo, 0x0, sizeof(image_descriptor));
38 imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
39 imageInfo.format = format;
40 pixelSize = get_pixel_size( imageInfo.format );
41
42 int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
43 error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
44 error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
45 test_error( error, "Unable to get max image 1D size from device" );
46
47 if (memSize > (cl_ulong)SIZE_MAX) {
48 memSize = (cl_ulong)SIZE_MAX;
49 maxAllocSize = (cl_ulong)SIZE_MAX;
50 }
51
52 if( gTestSmallImages )
53 {
54 for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
55 {
56 imageInfo.rowPitch = imageInfo.width * pixelSize;
57 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
58 {
59 if( gDebugTrace )
60 log_info( " at size %d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch );
61 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
62 return -1;
63 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
64 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
65 return -1;
66 }
67 }
68 }
69 }
70 else if( gTestMaxImages )
71 {
72 // Try a specific set of maximum sizes
73 size_t numbeOfSizes;
74 size_t sizes[100][3];
75
76 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D, imageInfo.format);
77
78 for( size_t idx = 0; idx < numbeOfSizes; idx++ )
79 {
80 imageInfo.width = sizes[ idx ][ 0 ];
81 imageInfo.rowPitch = imageInfo.width * pixelSize;
82 log_info( "Testing %d x 1\n", (int)sizes[ idx ][ 0 ]);
83 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
84 {
85 if( gDebugTrace )
86 log_info( " at max size %d (flags[%u] 0x%x pitch %d)\n", (int)imageInfo.width, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch );
87 if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
88 return -1;
89 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
90 if( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
91 return -1;
92 }
93 }
94 }
95 }
96 else
97 {
98 for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
99 {
100 cl_ulong size;
101 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
102 // image, the result array, plus offset arrays, will fit in the global ram space
103 do
104 {
105 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
106
107 imageInfo.rowPitch = imageInfo.width * pixelSize;
108 size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
109 imageInfo.rowPitch += extraWidth;
110
111 do {
112 extraWidth++;
113 imageInfo.rowPitch += extraWidth;
114 } while ((imageInfo.rowPitch % pixelSize) != 0);
115
116 size = (cl_ulong)imageInfo.rowPitch * 4;
117 } while( size > maxAllocSize || ( size * 3 ) > memSize );
118
119 for (unsigned int j=0; j < sizeof(all_host_ptr_flags)/sizeof(cl_mem_flags); j++)
120 {
121 if( gDebugTrace )
122 log_info( " at size %d (flags[%u] 0x%x pitch %d) out of %d\n", (int)imageInfo.width, j, (unsigned int) all_host_ptr_flags[j], (int)imageInfo.rowPitch, (int)maxWidth );
123 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], 0, 0 ) )
124 return -1;
125 if (all_host_ptr_flags[j] & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) { // skip test when host_ptr is NULL
126 if ( test_get_image_info_single( context, &imageInfo, seed, all_host_ptr_flags[j], imageInfo.rowPitch, 0 ) )
127 return -1;
128 }
129 }
130 }
131 }
132
133 return 0;
134 }
135