• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************
2 Copyright (c) 2016 The Khronos Group Inc. All Rights Reserved.
3 
4 This code is protected by copyright laws and contains material proprietary to the Khronos Group, Inc.
5 This is UNPUBLISHED PROPRIETARY SOURCE CODE that may not be disclosed in whole or in part to
6 third parties, and may not be reproduced, republished, distributed, transmitted, displayed,
7 broadcast or otherwise exploited in any manner without the express prior written permission
8 of Khronos Group. The receipt or possession of this code does not convey any rights to reproduce,
9 disclose, or distribute its contents, or to manufacture, use, or sell anything that it may describe,
10 in whole or in part other than under the terms of the Khronos Adopters Agreement
11 or Khronos Conformance Test Source License Agreement as executed between Khronos and the recipient.
12 ******************************************************************/
13 
14 #include "testBase.h"
15 #include "types.hpp"
16 
17 template<typename T>
test_composite_construct(cl_device_id deviceID,cl_context context,cl_command_queue queue,const char * name,std::vector<T> & results,bool (* notEqual)(const T &,const T &)=isNotEqual<T>)18 int test_composite_construct(cl_device_id deviceID, cl_context context,
19                 cl_command_queue queue, const char *name,
20                 std::vector<T> &results,
21                 bool (*notEqual)(const T&, const T&) = isNotEqual<T>)
22 {
23     clProgramWrapper prog;
24     cl_int err = get_program_with_il(prog, deviceID, context, name);
25     SPIRV_CHECK_ERROR(err, "Failed to build program");
26 
27     clKernelWrapper kernel = clCreateKernel(prog, name, &err);
28     SPIRV_CHECK_ERROR(err, "Failed to create kernel");
29 
30     int num = (int)results.size();
31 
32     size_t bytes = num * sizeof(T);
33     clMemWrapper mem = clCreateBuffer(context, CL_MEM_READ_WRITE, bytes, NULL, &err);
34     SPIRV_CHECK_ERROR(err, "Failed to create buffer");
35 
36     err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &mem);
37     SPIRV_CHECK_ERROR(err, "Failed to set kernel argument");
38 
39     size_t global = num;
40     err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, NULL, 0, NULL, NULL);
41     SPIRV_CHECK_ERROR(err, "Failed to enqueue kernel");
42 
43     std::vector<T> host(num);
44     err = clEnqueueReadBuffer(queue, mem, CL_TRUE, 0, bytes, &host[0], 0, NULL, NULL);
45     SPIRV_CHECK_ERROR(err, "Failed to copy from cl_buffer");
46 
47     for (int i = 0; i < num; i++) {
48         if (notEqual(host[i], results[i])) {
49             log_error("Values do not match at location %d\n", i);
50             return -1;
51         }
52     }
53     return 0;
54 }
55 
TEST_SPIRV_FUNC(op_composite_construct_int4)56 TEST_SPIRV_FUNC(op_composite_construct_int4)
57 {
58     cl_int4 value = {123, 122, 121, 119};
59     std::vector<cl_int4> results(256, value);
60     return test_composite_construct(deviceID, context, queue, "composite_construct_int4", results);
61 }
62 
TEST_SPIRV_FUNC(op_composite_construct_struct)63 TEST_SPIRV_FUNC(op_composite_construct_struct)
64 {
65     typedef AbstractStruct2<int, char> CustomType1;
66     typedef AbstractStruct2<cl_int2, CustomType1> CustomType2;
67 
68     CustomType1 value1 = {2100483600, 128};
69     cl_int2 intvals = {2100480000, 2100480000};
70     CustomType2 value2 = {intvals, value1};
71 
72     std::vector<CustomType2> results(256, value2);
73     return test_composite_construct(deviceID, context, queue, "composite_construct_struct", results);
74 }
75