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,
19 cl_command_queue queue,
20 image_descriptor *imageInfo, MTdata d,
21 cl_mem_flags flags);
22
test_get_image_info_3D(cl_device_id device,cl_context context,cl_command_queue queue,cl_image_format * format,cl_mem_flags flags)23 int test_get_image_info_3D(cl_device_id device, cl_context context,
24 cl_command_queue queue, cl_image_format *format,
25 cl_mem_flags flags)
26 {
27 size_t maxWidth, maxHeight, maxDepth;
28 cl_ulong maxAllocSize, memSize;
29 image_descriptor imageInfo = { 0 };
30 RandomSeed seed( gRandomSeed );
31 size_t pixelSize;
32
33 if ((flags != CL_MEM_READ_ONLY)
34 && !is_extension_available(device, "cl_khr_3d_image_writes"))
35 {
36 log_info("-----------------------------------------------------\n");
37 log_info("This device does not support cl_khr_3d_image_writes.\n"
38 "Skipping 3d image write test.\n");
39 log_info("-----------------------------------------------------\n\n");
40 return 0;
41 }
42
43 imageInfo.type = CL_MEM_OBJECT_IMAGE3D;
44 imageInfo.format = format;
45 pixelSize = get_pixel_size( imageInfo.format );
46
47 int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
48 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
49 error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, NULL );
50 error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
51 error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
52 test_error( error, "Unable to get max image 3D size from device" );
53
54 if (memSize > (cl_ulong)SIZE_MAX) {
55 memSize = (cl_ulong)SIZE_MAX;
56 }
57
58 if( gTestSmallImages )
59 {
60 for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
61 {
62 imageInfo.rowPitch = imageInfo.width * pixelSize;
63
64 for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
65 {
66 imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
67 for( imageInfo.depth = 2; imageInfo.depth < 9; imageInfo.depth++ )
68 {
69 if( gDebugTrace )
70 log_info( " at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth );
71 int ret = test_get_image_info_single(
72 context, queue, &imageInfo, seed, flags);
73 if( ret )
74 return -1;
75 }
76 }
77 }
78 }
79 else if( gTestMaxImages )
80 {
81 // Try a specific set of maximum sizes
82 size_t numbeOfSizes;
83 size_t sizes[100][3];
84
85 get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, maxHeight, maxDepth, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE3D, imageInfo.format);
86
87 for( size_t idx = 0; idx < numbeOfSizes; idx++ )
88 {
89 imageInfo.width = sizes[ idx ][ 0 ];
90 imageInfo.height = sizes[ idx ][ 1 ];
91 imageInfo.depth = sizes[ idx ][ 2 ];
92 imageInfo.rowPitch = imageInfo.width * pixelSize;
93 imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
94
95 log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
96 if( gDebugTrace )
97 log_info( " at max size %d,%d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
98 if (test_get_image_info_single(context, queue, &imageInfo, seed,
99 flags))
100 return -1;
101 }
102 }
103 else
104 {
105 for( int i = 0; i < NUM_IMAGE_ITERATIONS; i++ )
106 {
107 cl_ulong size;
108 cl_ulong slicePitch;
109 cl_ulong rowPitch;
110
111 // Loop until we get a size that a) will fit in the max alloc size and b) that an allocation of that
112 // image, the result array, plus offset arrays, will fit in the global ram space
113 do
114 {
115 imageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
116 imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
117 imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
118
119 rowPitch = imageInfo.width * pixelSize;
120 slicePitch = imageInfo.rowPitch * imageInfo.height;
121
122 size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
123 rowPitch += extraWidth;
124
125 do {
126 extraWidth++;
127 rowPitch += extraWidth;
128 } while ((rowPitch % pixelSize) != 0);
129
130 size_t extraHeight = (int)random_log_in_range( 0, 8, seed );
131 slicePitch = rowPitch * (imageInfo.height + extraHeight);
132
133 size = slicePitch * imageInfo.depth * 4 * 4;
134 } while( size > maxAllocSize || ( size * 3 ) > memSize );
135
136 imageInfo.slicePitch = slicePitch;
137 imageInfo.rowPitch = rowPitch;
138
139 if( gDebugTrace )
140 log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxDepth );
141 int ret = test_get_image_info_single(context, queue, &imageInfo,
142 seed, flags);
143 if( ret )
144 return -1;
145 }
146 }
147
148 return 0;
149 }
150
151