[Beignet] [PATCH 2/2] Add the test case for clGetCommandQueueInfo API

junyan.he at linux.intel.com junyan.he at linux.intel.com
Tue Jun 25 03:15:32 PDT 2013


From: Junyan He <junyan.he at linux.intel.com>

Because all the get clGetXXXInfo API have similar
structure in function type, we will integrate them
together, and rename the get_program_info.cpp to get_cl_info.cpp

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 kernels/get_program_info.cl |   10 --
 utests/CMakeLists.txt       |    2 +-
 utests/get_cl_info.cpp      |  319 +++++++++++++++++++++++++++++++++++++++++++
 utests/get_program_info.cpp |  247 ---------------------------------
 4 files changed, 320 insertions(+), 258 deletions(-)
 delete mode 100644 kernels/get_program_info.cl
 create mode 100644 utests/get_cl_info.cpp
 delete mode 100644 utests/get_program_info.cpp

diff --git a/kernels/get_program_info.cl b/kernels/get_program_info.cl
deleted file mode 100644
index 8e0dd94..0000000
--- a/kernels/get_program_info.cl
+++ /dev/null
@@ -1,10 +0,0 @@
-kernel void get_program_info( __global int *ret ) {
-    uint x = get_work_dim();
-    size_t y = get_global_size(0);
-    y = get_global_id(0);
-    y = get_local_size(0);
-    y = get_local_id(0);
-    y = get_num_groups(0);
-    y = get_group_id(0);
-    y = get_global_offset(0);
-}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index c009d99..ab8e598 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -85,7 +85,7 @@ set (utests_sources
   compiler_get_image_info.cpp
   compiler_vector_load_store.cpp
   compiler_cl_finish.cpp
-  get_program_info.cpp
+  get_cl_info.cpp
   buildin_work_dim.cpp
   builtin_global_size.cpp
   runtime_createcontext.cpp
diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp
new file mode 100644
index 0000000..6d5e7bb
--- /dev/null
+++ b/utests/get_cl_info.cpp
@@ -0,0 +1,319 @@
+#include <string.h>
+#include <string>
+#include <map>
+#include <iostream>
+#include <fstream>
+#include <algorithm>
+#include "utest_helper.hpp"
+
+using namespace std;
+
+/* ***************************************************** *
+ * This file to test all the API like: clGetXXXXInfo     *
+ * ***************************************************** */
+#define NO_STANDARD_REF 0xFFFFF
+
+template <typename T = cl_uint>
+struct Info_Result {
+    T ret;
+    T refer;
+    int size;
+    typedef T type_value;
+
+    void * get_ret(void) {
+        return (void *)&ret;
+    }
+
+    Info_Result(T other) {
+        refer = other;
+        size = sizeof(T);
+    }
+
+    bool check_result (void) {
+        if (ret != refer && refer != (T)NO_STANDARD_REF)
+            return false;
+
+        return true;
+    }
+};
+
+template <>
+struct Info_Result<char *> {
+    char * ret;
+    char * refer;
+    int size;
+    typedef char* type_value;
+
+    Info_Result(char *other, int sz) {
+        size = sz;
+        ret = (char *)malloc(sizeof(char) * sz);
+        if (other) {
+            refer = (char *)malloc(sizeof(char) * sz);
+            memcpy(refer, other, sz);
+        }
+    }
+
+    ~Info_Result(void) {
+        free(refer);
+        free(ret);
+    }
+
+    void * get_ret(void) {
+        return (void *)ret;
+    }
+
+    bool check_result (void) {
+        if (refer && ::memcmp(ret, refer, size))
+            return false;
+
+        return true;
+    }
+};
+
+template <> //Used for such as CL_PROGRAM_BINARIES
+struct Info_Result<char **> {
+    char ** ret;
+    char ** refer;
+    int *elt_size;
+    int size;
+    typedef char** type_value;
+
+    Info_Result(char **other, int *sz, int elt_num) {
+        size = elt_num;
+
+        ret = (char **)malloc(elt_num * sizeof(char *));
+        memset(ret, 0, (elt_num * sizeof(char *)));
+        refer = (char **)malloc(elt_num * sizeof(char *));
+        memset(refer, 0, (elt_num * sizeof(char *)));
+        elt_size = (int *)malloc(elt_num * sizeof(int));
+        memset(elt_size, 0, (elt_num * sizeof(int)));
+        if (sz) {
+            int i = 0;
+            for (; i < elt_num; i++) {
+                elt_size[i] = sz[i];
+                ret[i] = (char *)malloc(sz[i] * sizeof(char));
+
+                if (other[i] && elt_size[i] > 0) {
+                    refer[i] = (char *)malloc(sz[i] * sizeof(char));
+                    memcpy(&refer[i], &other[i], sz[i]);
+                }
+                else
+                    refer[i] = NULL;
+            }
+        }
+    }
+
+    ~Info_Result(void) {
+        int i = 0;
+        for (; i < size; i++) {
+            if (refer[i])
+                free(refer[i]);
+            free(ret[i]);
+        }
+        free(ret);
+        free(refer);
+        free(elt_size);
+    }
+
+    void * get_ret(void) {
+        return (void *)ret;
+    }
+
+    bool check_result (void) {
+        int i = 0;
+        for (; i < size; i++) {
+            if (refer[i] && ::memcmp(ret[i], refer[i], elt_size[i]))
+                return false;
+        }
+
+        return true;
+    }
+};
+
+template <typename T1, typename T2>
+struct Traits {
+    static bool Is_Same(void) {
+        return false;
+    };
+};
+
+template <typename T1>
+struct Traits<T1, T1> {
+    static bool Is_Same(void) {
+        return true;
+    };
+};
+
+template <typename T>
+Info_Result<T>* cast_as(void *info)
+{
+    Info_Result<T>* ret;
+    ret = reinterpret_cast<Info_Result<T>*>(info);
+    OCL_ASSERT((Traits<T, typename Info_Result<T>::type_value>::Is_Same()));
+    return ret;
+}
+
+
+#define CALL_INFO_AND_RET(TYPE, FUNC, OBJ) \
+    do { \
+	cl_int ret; \
+	size_t ret_size; \
+	\
+	Info_Result<TYPE>* info = cast_as<TYPE>(x.second); \
+	ret = FUNC (OBJ, x.first, \
+		info->size, info->get_ret(), &ret_size); \
+	OCL_ASSERT((!ret)); \
+	OCL_ASSERT((info->check_result())); \
+	delete info; \
+    } while(0)
+
+/* ***************************************************** *
+ * clGetProgramInfo                                      *
+ * ***************************************************** */
+#define CALL_PROGINFO_AND_RET(TYPE) CALL_INFO_AND_RET(TYPE, clGetProgramInfo, program)
+
+void get_program_info(void)
+{
+    map<cl_program_info, void *> maps;
+    int expect_value;
+    char * expect_source;
+    int sz;
+    char *ker_path = (char *)malloc(4096 * sizeof(char));
+    const char *kiss_path = getenv("OCL_KERNEL_PATH");
+    string line;
+    string source_code;
+
+    sprintf(ker_path, "%s/%s", kiss_path, "compiler_if_else.cl");
+
+    ifstream in(ker_path);
+    while (getline(in,line)) {
+        source_code = (source_code == "") ?
+                      source_code + line : source_code + "\n" + line;
+    }
+    free(ker_path);
+    //cout<< source_code;
+    source_code = source_code + "\n";
+
+    expect_source = (char *)source_code.c_str();
+
+    OCL_CREATE_KERNEL("compiler_if_else");
+
+    /* First test for clGetProgramInfo. We just have 1 devices now */
+    expect_value = 2;//One program, one kernel.
+    maps.insert(make_pair(CL_PROGRAM_REFERENCE_COUNT,
+                          (void *)(new Info_Result<>(((cl_uint)expect_value)))));
+    maps.insert(make_pair(CL_PROGRAM_CONTEXT,
+                          (void *)(new Info_Result<cl_context>(ctx))));
+    expect_value = 1;
+    maps.insert(make_pair(CL_PROGRAM_NUM_DEVICES,
+                          (void *)(new Info_Result<>(((cl_uint)expect_value)))));
+    maps.insert(make_pair(CL_PROGRAM_DEVICES,
+                          (void *)(new Info_Result<cl_device_id>(device))));
+    sz = (strlen(expect_source) + 1);
+    maps.insert(make_pair(CL_PROGRAM_SOURCE,
+                          (void *)(new Info_Result<char *>(expect_source, sz))));
+    expect_value = NO_STANDARD_REF;
+    maps.insert(make_pair(CL_PROGRAM_BINARY_SIZES,
+                          (void *)(new Info_Result<size_t>((size_t)expect_value))));
+    sz = 4096; //big enough?
+    expect_source = NULL;
+    maps.insert(make_pair(CL_PROGRAM_BINARIES,
+                          (void *)(new Info_Result<char **>(&expect_source, &sz, 1))));
+
+    std::for_each(maps.begin(), maps.end(), [](pair<cl_program_info, void *> x) {
+        switch (x.first) {
+        case CL_PROGRAM_REFERENCE_COUNT:
+        case CL_PROGRAM_NUM_DEVICES:
+            CALL_PROGINFO_AND_RET(cl_uint);
+            break;
+        case CL_PROGRAM_CONTEXT:
+            CALL_PROGINFO_AND_RET(cl_context);
+            break;
+        case CL_PROGRAM_DEVICES:
+            CALL_PROGINFO_AND_RET(cl_device_id);
+            break;
+        case CL_PROGRAM_SOURCE:
+            CALL_PROGINFO_AND_RET(char *);
+            break;
+        case CL_PROGRAM_BINARY_SIZES:
+            CALL_PROGINFO_AND_RET(size_t);
+            break;
+        case CL_PROGRAM_BINARIES:
+            CALL_PROGINFO_AND_RET(char **);
+            break;
+        default:
+            break;
+        }
+    });
+}
+
+MAKE_UTEST_FROM_FUNCTION(get_program_info);
+
+/* ***************************************************** *
+ * clGetCommandQueueInfo                                 *
+ * ***************************************************** */
+#define CALL_QUEUEINFO_AND_RET(TYPE) CALL_INFO_AND_RET(TYPE, clGetCommandQueueInfo, queue)
+
+void get_queue_info(void)
+{
+    /* use the compiler_fabs case to test us. */
+    const size_t n = 16;
+    map<cl_program_info, void *> maps;
+    int expect_ref;
+    cl_command_queue_properties prop;
+
+    OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(float), NULL);
+    OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(float), NULL);
+    OCL_CREATE_KERNEL("compiler_fabs");
+
+    OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+    OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+
+    globals[0] = 16;
+    locals[0] = 16;
+
+    OCL_MAP_BUFFER(0);
+    for (int32_t i = 0; i < (int32_t) n; ++i)
+        ((float*)buf_data[0])[i] = .1f * (rand() & 15) - .75f;
+    OCL_UNMAP_BUFFER(0);
+
+    // Run the kernel on GPU
+    OCL_NDRANGE(1);
+
+    /* Do our test.*/
+    maps.insert(make_pair(CL_QUEUE_CONTEXT,
+                          (void *)(new Info_Result<cl_context>(ctx))));
+    maps.insert(make_pair(CL_QUEUE_DEVICE,
+                          (void *)(new Info_Result<cl_device_id>(device))));
+
+    expect_ref = 1;
+    maps.insert(make_pair(CL_QUEUE_REFERENCE_COUNT,
+                          (void *)(new Info_Result<>(((cl_uint)expect_ref)))));
+
+    prop = 0;
+    maps.insert(make_pair(CL_QUEUE_PROPERTIES,
+                          (void *)(new Info_Result<cl_command_queue_properties>(
+                                       ((cl_command_queue_properties)prop)))));
+
+    std::for_each(maps.begin(), maps.end(), [](pair<cl_program_info, void *> x) {
+        switch (x.first) {
+        case CL_QUEUE_CONTEXT:
+            CALL_QUEUEINFO_AND_RET(cl_context);
+            break;
+        case CL_QUEUE_DEVICE:
+            CALL_QUEUEINFO_AND_RET(cl_device_id);
+            break;
+        case CL_QUEUE_REFERENCE_COUNT:
+            CALL_QUEUEINFO_AND_RET(cl_uint);
+            break;
+        case CL_QUEUE_PROPERTIES:
+            CALL_QUEUEINFO_AND_RET(cl_command_queue_properties);
+            break;
+        default:
+            break;
+        }
+    });
+}
+
+MAKE_UTEST_FROM_FUNCTION(get_queue_info);
+
diff --git a/utests/get_program_info.cpp b/utests/get_program_info.cpp
deleted file mode 100644
index 20248e8..0000000
--- a/utests/get_program_info.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-#include <string.h>
-#include <string>
-#include <map>
-#include <iostream>
-#include <fstream>
-#include <algorithm>
-#include "utest_helper.hpp"
-
-using namespace std;
-
-/* ********************************************** *
- * This file to test the API of:                  *
- * clGetProgramInfo                               *
- * ********************************************** */
-#define NO_STANDARD_REF 0xFFFFF
-
-template <typename T = cl_uint>
-struct Info_Result {
-    T ret;
-    T refer;
-    int size;
-    typedef T type_value;
-
-    void * get_ret(void) {
-        return (void *)&ret;
-    }
-
-    Info_Result(T other) {
-        refer = other;
-        size = sizeof(T);
-    }
-
-    bool check_result (void) {
-        if (ret != refer && refer != (T)NO_STANDARD_REF)
-            return false;
-
-        return true;
-    }
-};
-
-template <>
-struct Info_Result<char *> {
-    char * ret;
-    char * refer;
-    int size;
-    typedef char* type_value;
-
-    Info_Result(char *other, int sz) {
-        size = sz;
-        ret = (char *)malloc(sizeof(char) * sz);
-        if (other) {
-            refer = (char *)malloc(sizeof(char) * sz);
-            memcpy(refer, other, sz);
-        }
-    }
-
-    ~Info_Result(void) {
-        free(refer);
-        free(ret);
-    }
-
-    void * get_ret(void) {
-        return (void *)ret;
-    }
-
-    bool check_result (void) {
-        if (refer && ::memcmp(ret, refer, size))
-            return false;
-
-        return true;
-    }
-};
-
-template <> //Used for such as CL_PROGRAM_BINARIES
-struct Info_Result<char **> {
-    char ** ret;
-    char ** refer;
-    int *elt_size;
-    int size;
-    typedef char** type_value;
-
-    Info_Result(char **other, int *sz, int elt_num) {
-        size = elt_num;
-
-        ret = (char **)malloc(elt_num * sizeof(char *));
-        memset(ret, 0, (elt_num * sizeof(char *)));
-        refer = (char **)malloc(elt_num * sizeof(char *));
-        memset(refer, 0, (elt_num * sizeof(char *)));
-        elt_size = (int *)malloc(elt_num * sizeof(int));
-        memset(elt_size, 0, (elt_num * sizeof(int)));
-        if (sz) {
-            int i = 0;
-            for (; i < elt_num; i++) {
-                elt_size[i] = sz[i];
-                ret[i] = (char *)malloc(sz[i] * sizeof(char));
-
-                if (other[i] && elt_size[i] > 0) {
-                    refer[i] = (char *)malloc(sz[i] * sizeof(char));
-                    memcpy(&refer[i], &other[i], sz[i]);
-                }
-                else
-                    refer[i] = NULL;
-            }
-        }
-    }
-
-    ~Info_Result(void) {
-        int i = 0;
-        for (; i < size; i++) {
-            if (refer[i])
-                free(refer[i]);
-            free(ret[i]);
-        }
-        free(ret);
-        free(refer);
-        free(elt_size);
-    }
-
-    void * get_ret(void) {
-        return (void *)ret;
-    }
-
-    bool check_result (void) {
-        int i = 0;
-        for (; i < size; i++) {
-            if (refer[i] && ::memcmp(ret[i], refer[i], elt_size[i]))
-                return false;
-        }
-
-        return true;
-    }
-};
-
-template <typename T1, typename T2>
-struct Traits {
-    static bool Is_Same(void) {
-        return false;
-    };
-};
-
-template <typename T1>
-struct Traits<T1, T1> {
-    static bool Is_Same(void) {
-        return true;
-    };
-};
-
-template <typename T>
-Info_Result<T>* cast_as(void *info)
-{
-    Info_Result<T>* ret;
-    ret = reinterpret_cast<Info_Result<T>*>(info);
-    OCL_ASSERT((Traits<T, typename Info_Result<T>::type_value>::Is_Same()));
-    return ret;
-}
-
-
-#define CALL_PROGINFO_AND_RET(TYPE) \
-    do { \
-	cl_int ret; \
-	size_t ret_size; \
-	\
-	Info_Result<TYPE>* info = cast_as<TYPE>(x.second); \
-	ret = clGetProgramInfo(program, x.first, \
-		info->size, info->get_ret(), &ret_size); \
-	OCL_ASSERT((!ret)); \
-	OCL_ASSERT((info->check_result())); \
-	delete info; \
-    } while(0)
-
-void get_program_info(void)
-{
-    map<cl_program_info, void *> maps;
-    int expect_value;
-    char * expect_source;
-    int sz;
-    char *ker_path = (char *)malloc(4096 * sizeof(char));
-    const char *kiss_path = getenv("OCL_KERNEL_PATH");
-    string line;
-    string source_code;
-
-    sprintf(ker_path, "%s/%s", kiss_path, "get_program_info.cl");
-
-    ifstream in(ker_path);
-    while (getline(in,line)) {
-        source_code = (source_code == "") ?
-                      source_code + line : source_code + "\n" + line;
-    }
-    free(ker_path);
-    //cout<< source_code;
-    source_code = source_code + "\n";
-
-    expect_source = (char *)source_code.c_str();
-
-    OCL_CREATE_KERNEL("get_program_info");
-
-    /* First test for clGetProgramInfo. We just have 1 devices now */
-    expect_value = 2;//One program, one kernel.
-    maps.insert(make_pair(CL_PROGRAM_REFERENCE_COUNT,
-                          (void *)(new Info_Result<>(((cl_uint)expect_value)))));
-    maps.insert(make_pair(CL_PROGRAM_CONTEXT,
-                          (void *)(new Info_Result<cl_context>(ctx))));
-    expect_value = 1;
-    maps.insert(make_pair(CL_PROGRAM_NUM_DEVICES,
-                          (void *)(new Info_Result<>(((cl_uint)expect_value)))));
-    maps.insert(make_pair(CL_PROGRAM_DEVICES,
-                          (void *)(new Info_Result<cl_device_id>(device))));
-    sz = (strlen(expect_source) + 1);
-    maps.insert(make_pair(CL_PROGRAM_SOURCE,
-                          (void *)(new Info_Result<char *>(expect_source, sz))));
-    expect_value = NO_STANDARD_REF;
-    maps.insert(make_pair(CL_PROGRAM_BINARY_SIZES,
-                          (void *)(new Info_Result<size_t>((size_t)expect_value))));
-    sz = 4096; //big enough?
-    expect_source = NULL;
-    maps.insert(make_pair(CL_PROGRAM_BINARIES,
-                          (void *)(new Info_Result<char **>(&expect_source, &sz, 1))));
-
-    std::for_each(maps.begin(), maps.end(), [](pair<cl_program_info, void *> x) {
-        switch (x.first) {
-        case CL_PROGRAM_REFERENCE_COUNT:
-        case CL_PROGRAM_NUM_DEVICES:
-            CALL_PROGINFO_AND_RET(cl_uint);
-            break;
-        case CL_PROGRAM_CONTEXT:
-            CALL_PROGINFO_AND_RET(cl_context);
-            break;
-        case CL_PROGRAM_DEVICES:
-            CALL_PROGINFO_AND_RET(cl_device_id);
-            break;
-        case CL_PROGRAM_SOURCE:
-            CALL_PROGINFO_AND_RET(char *);
-            break;
-        case CL_PROGRAM_BINARY_SIZES:
-            CALL_PROGINFO_AND_RET(size_t);
-            break;
-        case CL_PROGRAM_BINARIES:
-            CALL_PROGINFO_AND_RET(char **);
-            break;
-        default:
-            break;
-        }
-    });
-}
-
-MAKE_UTEST_FROM_FUNCTION(get_program_info);
-
-- 
1.7.9.5



More information about the Beignet mailing list