示例#1
0
/**
 * @internal
 *
 * @brief Tests creation, getting info from and destruction of
 * buffer wrapper objects.
 * */
static void create_info_destroy_test() {

    /* Test variables. */
    CCLContext * ctx = NULL;
    CCLBuffer * b = NULL;
    CCLErr * err = NULL;
    size_t buf_size = sizeof(cl_uint) * CCL_TEST_BUFFER_SIZE;

    /* Get the test context with the pre-defined device. */
    ctx = ccl_test_context_new(&err);
    g_assert_no_error(err);

    /* Create regular buffer. */
    b = ccl_buffer_new(ctx, CL_MEM_READ_WRITE, buf_size, NULL, &err);
    g_assert_no_error(err);

    /* Get some info and check if the return value is as expected. */
    cl_mem_object_type mot;
    mot = ccl_memobj_get_info_scalar(
        b, CL_MEM_TYPE, cl_mem_object_type, &err);
    g_assert_no_error(err);
    g_assert_cmphex(mot, ==, CL_MEM_OBJECT_BUFFER);

    cl_mem_flags flags;
    flags = ccl_memobj_get_info_scalar(
        b, CL_MEM_FLAGS, cl_mem_flags, &err);
    g_assert_no_error(err);
    g_assert_cmphex(flags, ==, CL_MEM_READ_WRITE);

    size_t mem_size;
    mem_size = ccl_memobj_get_info_scalar(b, CL_MEM_SIZE, size_t, &err);
    g_assert_no_error(err);
    g_assert_cmpuint(mem_size, ==, buf_size);

    void * host_ptr = NULL;
    host_ptr = ccl_memobj_get_info_scalar(
        b, CL_MEM_HOST_PTR, void*, &err);
    g_assert((err == NULL) || (err->code == CCL_ERROR_INFO_UNAVAILABLE_OCL));
    g_assert_cmphex(GPOINTER_TO_UINT(host_ptr), ==,
        GPOINTER_TO_UINT(NULL));
    g_clear_error(&err);

    cl_context context;
    context = ccl_memobj_get_info_scalar(
        b, CL_MEM_CONTEXT, cl_context, &err);
    g_assert_no_error(err);
    g_assert_cmphex(GPOINTER_TO_UINT(context), ==,
        GPOINTER_TO_UINT(ccl_context_unwrap(ctx)));

    /* Destroy stuff. */
    ccl_buffer_destroy(b);
    ccl_context_destroy(ctx);

    /* Confirm that memory allocated by wrappers has been properly
     * freed. */
    g_assert(ccl_wrapper_memcheck());
}
示例#2
0
/**
 * @internal
 *
 * @brief Tests map/unmap operations in buffer objects.
 * */
static void map_unmap_test() {

    /* Test variables. */
    CCLContext * ctx = NULL;
    CCLDevice * d = NULL;
    CCLBuffer * b = NULL;
    CCLQueue * q;
    cl_uint h_in[CCL_TEST_BUFFER_SIZE];
    cl_uint * h_out;
    size_t buf_size = sizeof(cl_uint) * CCL_TEST_BUFFER_SIZE;
    CCLErr * err = NULL;

    /* Create a host array, put some stuff in it. */
    for (guint i = 0; i < CCL_TEST_BUFFER_SIZE; ++i)
        h_in[i] = g_test_rand_int();

    /* Get the test context with the pre-defined device. */
    ctx = ccl_test_context_new(&err);
    g_assert_no_error(err);

    /* Get first device in context. */
    d = ccl_context_get_device(ctx, 0, &err);
    g_assert_no_error(err);

    /* Create a command queue. */
    q = ccl_queue_new(ctx, d, 0, &err);
    g_assert_no_error(err);

    /* Create regular buffer and write data from the host buffer. */
    b = ccl_buffer_new(
        ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, buf_size, h_in, &err);
    g_assert_no_error(err);

    /* Map buffer onto host memory. */
    h_out = ccl_buffer_enqueue_map(
        b, q, CL_TRUE, CL_MAP_READ, 0, buf_size, NULL, NULL, &err);
    g_assert_no_error(err);

    /* Check data is OK. */
    for (guint i = 0; i < CCL_TEST_BUFFER_SIZE; ++i)
        g_assert_cmpuint(h_in[i], ==, h_out[i]);

    /* Unmap buffer. */
    ccl_memobj_enqueue_unmap(
        (CCLMemObj *) b, q, h_out, NULL, &err);
    g_assert_no_error(err);

    /* Free stuff. */
    ccl_buffer_destroy(b);
    ccl_queue_destroy(q);
    ccl_context_destroy(ctx);

    /* Confirm that memory allocated by wrappers has been properly
     * freed. */
    g_assert(ccl_wrapper_memcheck());
}
示例#3
0
/**
 * Tests creation (using "full" constructor), getting info from and
 * destruction of sampler wrapper objects.
 * */
static void create_full_info_destroy_test() {

	/* Test variables. */
	CCLContext* ctx = NULL;
	CCLSampler* s = NULL;
	const cl_sampler_properties sampler_properties[] = {
		CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
		CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_CLAMP_TO_EDGE,
		CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
		0};

	GError* err = NULL;

	/* Get the test context with the pre-defined device. */
	ctx = ccl_test_context_new(&err);
	g_assert_no_error(err);

	/* Create sampler using "full" constructor. */
	s = ccl_sampler_new_full(ctx, sampler_properties, &err);
	g_assert_no_error(err);

	/* Get some info and check if the return value is as expected. */
	cl_addressing_mode am;
	am = ccl_sampler_get_info_scalar(
		s, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode, &err);
	g_assert_no_error(err);
	g_assert_cmpuint(am, ==, CL_ADDRESS_CLAMP_TO_EDGE);

	cl_filter_mode fm;
	fm = ccl_sampler_get_info_scalar(
		s, CL_SAMPLER_FILTER_MODE, cl_filter_mode, &err);
	g_assert_no_error(err);
	g_assert_cmpuint(fm, ==, CL_FILTER_NEAREST);

	cl_bool nc;
	nc = ccl_sampler_get_info_scalar(
		s, CL_SAMPLER_NORMALIZED_COORDS, cl_bool, &err);
	g_assert_no_error(err);
	g_assert_cmpuint(nc, ==, CL_FALSE);

	cl_context context;
	context = ccl_sampler_get_info_scalar(
		s, CL_SAMPLER_CONTEXT, cl_context, &err);
	g_assert_no_error(err);
	g_assert_cmphex(GPOINTER_TO_UINT(context), ==,
		GPOINTER_TO_UINT(ccl_context_unwrap(ctx)));

	/* Destroy sampler. */
	ccl_sampler_destroy(s);
	ccl_context_destroy(ctx);

	/* Confirm that memory allocated by wrappers has been properly
	 * freed. */
	g_assert(ccl_wrapper_memcheck());

}
示例#4
0
/**
 * @internal
 *
 * @brief Tests buffer wrapping and unwrapping.
 * */
static void wrap_unwrap_test() {

    /* Test variables. */
    CCLContext * ctx = NULL;
    CCLBuffer * b = NULL;
    CCLBuffer * b_aux = NULL;
    cl_mem buffer = NULL;
    CCLErr * err = NULL;
    size_t buf_size = sizeof(cl_uint) * CCL_TEST_BUFFER_SIZE;
    cl_int status;

    /* Get the test context with the pre-defined device. */
    ctx = ccl_test_context_new(&err);
    g_assert_no_error(err);

    /* Create a buffer using OpenCL functions directly. */
    buffer = clCreateBuffer(
        ccl_context_unwrap(ctx), CL_MEM_READ_ONLY, buf_size, NULL, &status);
    g_assert_cmpint(status, ==, CL_SUCCESS);

    /* Wrap buffer. */
    b = ccl_buffer_new_wrap(buffer);

    /* If we now unwrap the wrapper, we must get the originally created
     * buffer. */
    g_assert(buffer == ccl_buffer_unwrap(b));

    /* If we again wrap the original buffer... */
    b_aux = ccl_buffer_new_wrap(buffer);

    /* ...we must get the same wrapper... */
    g_assert(b == b_aux);

    /* ... and the buffer wrapper ref count must be 2. */
    g_assert_cmpuint(2, ==, ccl_wrapper_ref_count((CCLWrapper *) b));

    /* Unref buffer, twice. */
    ccl_buffer_unref(b);

    /* Check that buffer ref count is 1. */
    g_assert_cmpuint(1, ==, ccl_wrapper_ref_count((CCLWrapper *) b));

    /* Destroy stuff. */
    ccl_buffer_destroy(b);
    ccl_context_destroy(ctx);

    /* Confirm that memory allocated by wrappers has been properly
     * freed. */
    g_assert(ccl_wrapper_memcheck());
}
示例#5
0
/**
 * @internal
 *
 * @brief Tests buffer wrapper class reference counting.
 * */
static void ref_unref_test() {

    /* Test variables. */
    CCLContext * ctx = NULL;
    CCLBuffer * b = NULL;
    CCLErr * err = NULL;
    size_t buf_size = sizeof(cl_uint) * CCL_TEST_BUFFER_SIZE;

    /* Get the test context with the pre-defined device. */
    ctx = ccl_test_context_new(&err);
    g_assert_no_error(err);

    /* Create regular buffer. */
    b = ccl_buffer_new(ctx, CL_MEM_READ_WRITE, buf_size, NULL, &err);
    g_assert_no_error(err);

    /* Increase buffer reference count. */
    ccl_memobj_ref(b);

    /* Check that buffer ref count is 2. */
    g_assert_cmpuint(2, ==, ccl_wrapper_ref_count((CCLWrapper *) b));

    /* Increase buffer reference count again, this time using helper
     * macro. */
    ccl_buffer_ref(b);

    /* Check that buffer ref count is 3. */
    g_assert_cmpuint(3, ==, ccl_wrapper_ref_count((CCLWrapper *) b));

    /* Unref buffer, twice. */
    ccl_buffer_unref(b);
    ccl_buffer_unref(b);

    /* Check that buffer ref count is 1. */
    g_assert_cmpuint(1, ==, ccl_wrapper_ref_count((CCLWrapper *) b));

    /* Destroy stuff. */
    ccl_buffer_unref(b);
    ccl_context_destroy(ctx);

    /* Confirm that memory allocated by wrappers has been properly
     * freed. */
    g_assert(ccl_wrapper_memcheck());
}
示例#6
0
/**
 * @internal
 *
 * @brief Test memory object destructor callbacks.
 * */
static void destructor_callback_test() {

    /* Test variables. */
    CCLContext * ctx = NULL;
    CCLBuffer * b = NULL;
    CCLErr * err = NULL;
    GTimer * timer = NULL;
    cl_bool test_var = CL_FALSE;

    /* Get the test context with the pre-defined device. */
    ctx = ccl_test_context_new(&err);
    g_assert_no_error(err);

    /* Create a buffer. */
    b = ccl_buffer_new(
        ctx, CL_MEM_READ_WRITE, 128 * sizeof(cl_uint), NULL, &err);

    /* Add destructor callback. */
    ccl_memobj_set_destructor_callback(
        (CCLMemObj *) b, destructor_callback, &test_var, &err);
    g_assert_no_error(err);

    /* Destroy buffer. */
    ccl_buffer_destroy(b);

    /* Destroy context. */
    ccl_context_destroy(ctx);

    /* Confirm that memory allocated by wrappers has been properly
     * freed. */
    g_assert(ccl_wrapper_memcheck());

    /* Wait some more... */
    timer = g_timer_new();
    while (g_timer_elapsed(timer, NULL) < 2.0);
    g_timer_stop(timer);
    g_timer_destroy(timer);

    /* Confirm that test_var is CL_TRUE. */
    g_assert_cmpuint(test_var, ==, CL_TRUE);
}
示例#7
0
/**
 * Tests sampler wrapper class reference counting.
 * */
static void ref_unref_test() {

	/* Test variables. */
	CCLContext* ctx = NULL;
	CCLSampler* s = NULL;
	GError* err = NULL;

	/* Get the test context with the pre-defined device. */
	ctx = ccl_test_context_new(&err);
	g_assert_no_error(err);

	/* Create sampler. */
	s = ccl_sampler_new(ctx, CL_TRUE, CL_ADDRESS_CLAMP,
		CL_FILTER_NEAREST, &err);
	g_assert_no_error(err);

	/* Increase sampler reference count. */
	ccl_sampler_ref(s);

	/* Check that sampler ref count is 2. */
	g_assert_cmpuint(2, ==, ccl_wrapper_ref_count((CCLWrapper*) s));

	/* Unref sampler. */
	ccl_sampler_unref(s);

	/* Check that sampler ref count is 1. */
	g_assert_cmpuint(1, ==, ccl_wrapper_ref_count((CCLWrapper*) s));

	/* Destroy stuff. */
	ccl_sampler_unref(s);
	ccl_context_destroy(ctx);

	/* Confirm that memory allocated by wrappers has been properly
	 * freed. */
	g_assert(ccl_wrapper_memcheck());
}
示例#8
0
/**
 * @internal
 *
 * @brief Tests the ccl_buffer_new_from_region() function.
 * */
static void create_from_region_test() {

    /* Test variables. */
    CCLContext * ctx = NULL;
    CCLDevice * dev = NULL;
    CCLQueue * cq = NULL;
    CCLBuffer * buf = NULL;
    CCLBuffer * subbuf = NULL;
    CCLEvent * evt = NULL;
    CCLEventWaitList ewl = NULL;
    CCLErr * err = NULL;
    cl_ulong * hbuf;
    cl_ulong * hsubbuf;
    cl_uint min_align;
    size_t siz_buf;
    size_t siz_subbuf;

    /* Get the test context with the pre-defined device. */
    ctx = ccl_test_context_new(&err);
    g_assert_no_error(err);

    /* Get first device in context. */
    dev = ccl_context_get_device(ctx, 0, &err);
    g_assert_no_error(err);

    /* Get minimum alignment for sub-buffer in bits. */
    min_align = ccl_device_get_info_scalar(
        dev, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint, &err);
    g_assert_no_error(err);

    /* Determine buffer and sub-buffer sizes (divide by 64 because its
     * the number of bits in cl_ulong). */
    siz_subbuf = sizeof(cl_ulong) * min_align / 64;
    siz_buf = 4 * siz_subbuf;

    /* Allocate memory for host buffer and host sub-buffer. */
    hbuf = g_slice_alloc(siz_buf);
    hsubbuf = g_slice_alloc(siz_subbuf);

    /* Initialize initial host buffer. */
    for (cl_uint i = 0; i < siz_buf / sizeof(cl_ulong); ++i)
        hbuf[i] = g_test_rand_int();

    /* Create a command queue. */
    cq = ccl_queue_new(ctx, dev, 0, &err);
    g_assert_no_error(err);

    /* Create a regular buffer, put some data in it. */
    buf = ccl_buffer_new(
        ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, siz_buf, hbuf, &err);
    g_assert_no_error(err);

    /* Create sub-buffer from indexes 16 to 31 (16 positions) of
     * original buffer. */
    subbuf = ccl_buffer_new_from_region(
        buf, 0, siz_subbuf, siz_subbuf, &err);
    g_assert_no_error(err);

    /* Get data in sub-buffer to a new host buffer. */
    evt = ccl_buffer_enqueue_read(
        subbuf, cq, CL_FALSE, 0, siz_subbuf, hsubbuf, NULL, &err);
    g_assert_no_error(err);

    /* Wait for read to be complete. */
    ccl_event_wait(ccl_ewl(&ewl, evt, NULL), &err);
    g_assert_no_error(err);

    /* Check that expected values were successfully read. */
    for (cl_uint i = 0; i < siz_subbuf / sizeof(cl_ulong); ++i)
        g_assert_cmpuint(
            hsubbuf[i], ==, hbuf[i + siz_subbuf / sizeof(cl_ulong)]);

    /* Destroy stuff. */
    ccl_buffer_destroy(buf);
    ccl_buffer_destroy(subbuf);
    ccl_queue_destroy(cq);
    ccl_context_destroy(ctx);
    g_slice_free1(siz_buf, hbuf);
    g_slice_free1(siz_subbuf, hsubbuf);

    /* Confirm that memory allocated by wrappers has been properly
     * freed. */
    g_assert(ccl_wrapper_memcheck());
}
示例#9
0
/**
 * @internal
 *
 * @brief Tests rect buffer operations.
 * */
static void rect_read_write_copy_test() {

    /* Test variables. */
    CCLContext * ctx = NULL;
    CCLDevice * d = NULL;
    CCLBuffer * b1 = NULL;
    CCLBuffer * b2 = NULL;
    CCLQueue * cq;
    cl_uchar h1[CCL_TEST_BUFFER_SIZE * CCL_TEST_BUFFER_SIZE];
    cl_uchar h2[CCL_TEST_BUFFER_SIZE * CCL_TEST_BUFFER_SIZE];
    size_t buf_size = sizeof(cl_uchar) * sizeof(cl_uchar)
        * CCL_TEST_BUFFER_SIZE * CCL_TEST_BUFFER_SIZE;
    CCLErr * err = NULL;
    const size_t origin[] = {0, 0, 0};
    const size_t region[] = {CCL_TEST_BUFFER_SIZE * sizeof(cl_uchar),
        CCL_TEST_BUFFER_SIZE * sizeof(cl_uchar), 1};

    /* Create a "2D" host array, put some stuff in it. */
    for (cl_uint i = 0; i < CCL_TEST_BUFFER_SIZE; ++i)
        for (cl_uint j = 0; j < CCL_TEST_BUFFER_SIZE; ++j)
            h1[i * CCL_TEST_BUFFER_SIZE + j] =
                (cl_uchar) (g_test_rand_int() % 0xFF);

    /* Get the test context with the pre-defined device. */
    ctx = ccl_test_context_new(&err);
    g_assert_no_error(err);

    /* Get first device in context. */
    d = ccl_context_get_device(ctx, 0, &err);
    g_assert_no_error(err);

    /* Create a command queue. */
    cq = ccl_queue_new(ctx, d, 0, &err);
    g_assert_no_error(err);

    /* Create device buffers. */
    b1 = ccl_buffer_new(ctx, CL_MEM_READ_WRITE, buf_size, NULL, &err);
    g_assert_no_error(err);
    b2 = ccl_buffer_new(ctx, CL_MEM_READ_WRITE, buf_size, NULL, &err);
    g_assert_no_error(err);

    /* Write "rect" data to first buffer in device. */
    ccl_buffer_enqueue_write_rect(
        b1, cq, CL_TRUE, origin, origin, region, 0, 0, 0, 0, h1, NULL, &err);
    g_assert_no_error(err);

    /* Copy "rect" data from first buffer to second buffer. */
    ccl_buffer_enqueue_copy_rect(
        b1, b2, cq, origin, origin, region, 0, 0, 0, 0, NULL, &err);
    g_assert_no_error(err);

    /* Read data "rect" back to host from the second buffer. */
    ccl_buffer_enqueue_read_rect(
        b2, cq, CL_TRUE, origin, origin, region, 0, 0, 0, 0, h2, NULL, &err);
    g_assert_no_error(err);

    /* Check data is OK doing a flat comparison. */
    for (cl_uint i = 0; i < CCL_TEST_BUFFER_SIZE * CCL_TEST_BUFFER_SIZE; ++i)
        g_assert_cmpuint(h1[i], ==, h2[i]);

    /* Free stuff. */
    ccl_buffer_destroy(b1);
    ccl_buffer_destroy(b2);
    ccl_queue_destroy(cq);
    ccl_context_destroy(ctx);

    /* Confirm that memory allocated by wrappers has been properly
     * freed. */
    g_assert(ccl_wrapper_memcheck());
}
示例#10
0
/**
 * @internal
 *
 * @brief Tests copy operations from one buffer to another.
 * */
static void copy_test() {

    /* Test variables. */
    CCLContext * ctx = NULL;
    CCLDevice * d = NULL;
    CCLBuffer * b1 = NULL;
    CCLBuffer * b2 = NULL;
    CCLQueue * q;
    cl_long h1[CCL_TEST_BUFFER_SIZE];
    cl_long h2[CCL_TEST_BUFFER_SIZE];
    size_t buf_size = sizeof(cl_long) * CCL_TEST_BUFFER_SIZE;
    CCLErr * err = NULL;

    /* Create a host array, put some stuff in it. */
    for (guint i = 0; i < CCL_TEST_BUFFER_SIZE; ++i)
        h1[i] = g_test_rand_int();

    /* Get the test context with the pre-defined device. */
    ctx = ccl_test_context_new(&err);
    g_assert_no_error(err);

    /* Get first device in context. */
    d = ccl_context_get_device(ctx, 0, &err);
    g_assert_no_error(err);

    /* Create a command queue. */
    q = ccl_queue_new(ctx, d, 0, &err);
    g_assert_no_error(err);

    /* Create regular buffer and write data from the host buffer. */
    b1 = ccl_buffer_new(
        ctx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, buf_size, h1, &err);
    g_assert_no_error(err);

    /* Create another buffer, double the size. */
    b2 = ccl_buffer_new(ctx, CL_MEM_READ_WRITE, 2 * buf_size, NULL, &err);
    g_assert_no_error(err);

    /* Copy data from first buffer to second buffer, using an offset on
     * the second buffer. */
    ccl_buffer_enqueue_copy(
        b1, b2, q, 0, buf_size / 2, buf_size, NULL, &err);
    g_assert_no_error(err);

    /* Read data back to host from the second buffer. */
    ccl_buffer_enqueue_read(
        b2, q, CL_TRUE, buf_size / 2, buf_size, h2, NULL, &err);
    g_assert_no_error(err);

    /* Check data is OK. */
    for (guint i = 0; i < CCL_TEST_BUFFER_SIZE; ++i)
        g_assert_cmpuint(h1[i], ==, h2[i]);

    /* Free stuff. */
    ccl_buffer_destroy(b1);
    ccl_buffer_destroy(b2);
    ccl_queue_destroy(q);
    ccl_context_destroy(ctx);

    /* Confirm that memory allocated by wrappers has been properly
     * freed. */
    g_assert(ccl_wrapper_memcheck());
}
示例#11
0
/**
 * Tests creation, getting info from and destruction of
 * profiler objects, and their relationship with context, device and
 * queue wrapper objects.
 * */
static void create_add_destroy_test() {

	/* Test variables. */
	CCLErr* err = NULL;
	CCLBuffer* buf1 = NULL;
	CCLBuffer* buf2 = NULL;
	CCLProf* prof = NULL;
	CCLContext* ctx = NULL;
	CCLDevice* d = NULL;
	CCLQueue* cq1 = NULL;
	CCLQueue* cq2 = NULL;
	CCLEvent* evt = NULL;
	CCLEventWaitList ewl = NULL;
	size_t buf_size = 8 * sizeof(cl_short);
	cl_short hbuf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
	cl_ulong duration, eff_duration;
	double time_elapsed;

	/* Create a new profile object. */
	prof = ccl_prof_new();

	/* Get a context and a device. */
	ctx = ccl_test_context_new(&err);
	g_assert_no_error(err);

	d = ccl_context_get_device(ctx, 0, &err);
	g_assert_no_error(err);

	/* Create two command queue wrappers. */
	cq1 = ccl_queue_new(ctx, d, CL_QUEUE_PROFILING_ENABLE, &err);
	g_assert_no_error(err);

	cq2 = ccl_queue_new(ctx, d, CL_QUEUE_PROFILING_ENABLE, &err);
	g_assert_no_error(err);

	/* Create device buffers. */
	buf1 = ccl_buffer_new(ctx, CL_MEM_READ_ONLY, buf_size, NULL, &err);
	g_assert_no_error(err);
	buf2 = ccl_buffer_new(ctx, CL_MEM_READ_WRITE, buf_size, NULL, &err);
	g_assert_no_error(err);

	/* Start profile object timer. */
	ccl_prof_start(prof);

	/* Transfer data to buffer. */
	evt = ccl_buffer_enqueue_write(
		buf1, cq1, CL_FALSE, 0, buf_size, hbuf, NULL, &err);
	g_assert_no_error(err);

	/* Transfer data from one buffer to another. */
	evt = ccl_buffer_enqueue_copy(buf1, buf2, cq2, 0, 0, buf_size,
		ccl_ewl(&ewl, evt, NULL), &err);
	g_assert_no_error(err);

	/* Wait for copy. */
	ccl_event_wait(ccl_ewl(&ewl, evt, NULL), &err);
	g_assert_no_error(err);

	/* Stop profile object timer. */
	ccl_prof_stop(prof);

	/* Add both queues to profile object. */
	ccl_prof_add_queue(prof, "A Queue", cq1);
	ccl_prof_add_queue(prof, "Another Queue", cq2);

	/* Process queues. */
	ccl_prof_calc(prof, &err);
	g_assert_no_error(err);

	/* Request some profiling information. */
	time_elapsed = ccl_prof_time_elapsed(prof);
	duration = ccl_prof_get_duration(prof);
	eff_duration = ccl_prof_get_eff_duration(prof);

	g_debug("Profiling time elapsed: %lf", time_elapsed);
	g_debug("Profiling duration: %d", (cl_int) duration);
	g_debug("Profiling eff. duration: %d", (cl_int) eff_duration);

	/* Destroy buffers. */
	ccl_buffer_destroy(buf1);
	ccl_buffer_destroy(buf2);

	/* Unref cq1, which should not be destroyed because it is held
	 * by the profile object. */
	ccl_queue_destroy(cq1);

	/* Destroy the profile object, which will also destroy cq1. cq2
	 * will me merely unrefed and must still be explicitly destroyed. */
	ccl_prof_destroy(prof);

	/* Destroy cq2. */
	ccl_queue_destroy(cq2);

	/* Destroy the context. */
	ccl_context_destroy(ctx);

	/* Confirm that memory allocated by wrappers has been properly
	 * freed. */
	g_assert(ccl_wrapper_memcheck());

}
示例#12
0
/**
 * Tests creation, getting info from and destruction of
 * kernel wrapper objects.
 * */
static void create_info_destroy_test() {

	/* Test variables. */
	CCLContext* ctx = NULL;
	cl_context context = NULL;
	CCLProgram* prg = NULL;
	cl_program program = NULL;
	CCLKernel* krnl = NULL;
	cl_kernel kernel = NULL;
	CCLDevice* d = NULL;
	CCLQueue* cq = NULL;
	size_t gws;
	size_t lws;
	cl_uint host_buf[CCL_TEST_KERNEL_BUF_SIZE];
	cl_uint host_buf_aux[CCL_TEST_KERNEL_BUF_SIZE];
	CCLBuffer* buf;
	GError* err = NULL;
	CCLEvent* evt = NULL;
	CCLEventWaitList ewl = NULL;
	const char* krnl_name;
	void* args[] = { NULL, NULL };
	cl_bool release_krnl;
	cl_int ocl_status;

	/* Create a context with devices from first available platform. */
	ctx = ccl_test_context_new(&err);
	g_assert_no_error(err);

	/* Create a new program from source and build it. */
	prg = ccl_program_new_from_source(
		ctx, CCL_TEST_KERNEL_CONTENT, &err);
	g_assert_no_error(err);

	ccl_program_build(prg, NULL, &err);
	g_assert_no_error(err);

	/* Create a command queue. */
	cq = ccl_queue_new(ctx, d, CL_QUEUE_PROFILING_ENABLE, &err);
	g_assert_no_error(err);

	/* Test three ways to create a kernel wrapper. */
	for (cl_uint i = 0; i < 3; ++i) {

		/* Create kernel wrapper. */
		switch (i) {
			case 0:
				/* Instantiate kernel directly. */
				krnl = ccl_kernel_new(prg, CCL_TEST_KERNEL_NAME, &err);
				g_assert_no_error(err);
				release_krnl = CL_TRUE;
				break;
			case 1:
				/* Using the program utility function. No need to free
				 * kernel in this case, because it will be freed when
				 * program is destroyed. */
				krnl = ccl_program_get_kernel(
					prg, CCL_TEST_KERNEL_NAME, &err);
				g_assert_no_error(err);
				release_krnl = CL_FALSE;
				break;
			case 2:
				/* Using the "wrap" constructor. */
				kernel = clCreateKernel(ccl_program_unwrap(prg),
					CCL_TEST_KERNEL_NAME, &ocl_status);
				g_assert_cmpint(ocl_status, ==, CL_SUCCESS);
				krnl = ccl_kernel_new_wrap(kernel);
				g_assert_cmphex(GPOINTER_TO_UINT(kernel), ==,
					GPOINTER_TO_UINT(ccl_kernel_unwrap(krnl)));
				release_krnl = CL_TRUE;
				break;
		}

		/* Get some kernel info, compare it with expected info. */

		/* Get kernel function name from kernel info, compare it with the
		 * expected value. */
		krnl_name = ccl_kernel_get_info_array(
			krnl, CL_KERNEL_FUNCTION_NAME, char*, &err);
		g_assert_no_error(err);
		g_assert_cmpstr(krnl_name, ==, CCL_TEST_KERNEL_NAME);

		/* Check if the kernel context is the same as the initial context
		 * and the program context. */
		context = ccl_kernel_get_info_scalar(
			krnl, CL_KERNEL_CONTEXT, cl_context, &err);
		g_assert_no_error(err);
		g_assert(context == ccl_context_unwrap(ctx));

		program = ccl_kernel_get_info_scalar(
			krnl, CL_KERNEL_PROGRAM, cl_program, &err);
		g_assert_no_error(err);
		g_assert(program == ccl_program_unwrap(prg));

#ifndef OPENCL_STUB

		cl_uint ocl_ver;

		/* Get OpenCL version of kernel's underlying platform. */
		ocl_ver = ccl_kernel_get_opencl_version(krnl, &err);
		g_assert_no_error(err);

		(void)ocl_ver;

#ifdef CL_VERSION_1_1

		size_t kwgz;
		size_t* kcwgs;
		CCLDevice* dev = NULL;

		/* If platform supports kernel work group queries, get kernel
		 * work group information and compare it with expected info. */
		if (ocl_ver >= 110) {

			dev = ccl_context_get_device(ctx, 0, &err);
			g_assert_no_error(err);

			kwgz = ccl_kernel_get_workgroup_info_scalar(
				krnl, dev, CL_KERNEL_WORK_GROUP_SIZE, size_t, &err);
			g_assert_no_error(err);
			(void)kwgz;

			kcwgs = ccl_kernel_get_workgroup_info_array(krnl, dev,
				CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size_t*, &err);
			g_assert_no_error(err);
			(void)kcwgs;

		}

#endif /* ifdef CL_VERSION_1_1 */

#ifdef CL_VERSION_1_2

		cl_kernel_arg_address_qualifier kaaq;
		char* kernel_arg_type_name;
		char* kernel_arg_name;

		/* If platform supports kernel argument queries, get kernel argument
		 * information and compare it with expected info. */
		if (ocl_ver >= 120) {

			kaaq = ccl_kernel_get_arg_info_scalar(krnl, 0,
					CL_KERNEL_ARG_ADDRESS_QUALIFIER,
					cl_kernel_arg_address_qualifier, &err);
			g_assert((err == NULL) || (err->code == CCL_ERROR_INFO_UNAVAILABLE_OCL));
			if (err == NULL) {
				g_assert_cmphex(kaaq, ==, CL_KERNEL_ARG_ADDRESS_GLOBAL);
			} else {
示例#13
0
/**
 * Tests creation (using "simple" constructor), getting info from and
 * destruction of sampler wrapper objects.
 * */
static void create_info_destroy_test() {

	/* Test variables. */
	CCLContext* ctx = NULL;
	CCLSampler* s = NULL;
	cl_sampler sampler = NULL;
	GError* err = NULL;
	cl_int ocl_status;
	const cl_sampler_properties sampler_properties[] = {
		CL_SAMPLER_NORMALIZED_COORDS, CL_TRUE,
		CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
		CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
		0};

	/* Get the test context with the pre-defined device. */
	ctx = ccl_test_context_new(&err);
	g_assert_no_error(err);

	/* Test three ways to create a sampler. */
	for (cl_uint i = 0; i < 3; ++i) {

		/* Create sampler wrapper. */
		switch (i) {
			case 0:
				/* Create sampler using "simple" constructor. */
				s = ccl_sampler_new(ctx, CL_TRUE, CL_ADDRESS_NONE,
					CL_FILTER_NEAREST, &err);
				g_assert_no_error(err);
				break;
			case 1:
				/* Using the "full" constructor. */
				s = ccl_sampler_new_full(ctx, sampler_properties, &err);
				g_assert_no_error(err);
				break;
			case 2:
				/* Using the "wrap" constructor. */
				CCL_BEGIN_IGNORE_DEPRECATIONS
				sampler = clCreateSampler(ccl_context_unwrap(ctx),
					CL_TRUE, CL_ADDRESS_NONE, CL_FILTER_NEAREST,
					&ocl_status);
				g_assert_cmpint(ocl_status, ==, CL_SUCCESS);
				CCL_END_IGNORE_DEPRECATIONS
				s = ccl_sampler_new_wrap(sampler);
				g_assert_cmphex(GPOINTER_TO_UINT(sampler), ==,
					GPOINTER_TO_UINT(ccl_sampler_unwrap(s)));
				break;
		}

		/* Get some info and check if the return value is as expected. */
		cl_addressing_mode am;
		am = ccl_sampler_get_info_scalar(
			s, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode, &err);
		g_assert_no_error(err);
		g_assert_cmpuint(am, ==, CL_ADDRESS_NONE);

		cl_filter_mode fm;
		fm = ccl_sampler_get_info_scalar(
			s, CL_SAMPLER_FILTER_MODE, cl_filter_mode, &err);
		g_assert_no_error(err);
		g_assert_cmpuint(fm, ==, CL_FILTER_NEAREST);

		cl_bool nc;
		nc = ccl_sampler_get_info_scalar(
			s, CL_SAMPLER_NORMALIZED_COORDS, cl_bool, &err);
		g_assert_no_error(err);
		g_assert_cmpuint(nc, ==, CL_TRUE);

		cl_context context;
		context = ccl_sampler_get_info_scalar(
			s, CL_SAMPLER_CONTEXT, cl_context, &err);
		g_assert_no_error(err);
		g_assert_cmphex(GPOINTER_TO_UINT(context), ==,
			GPOINTER_TO_UINT(ccl_context_unwrap(ctx)));

		/* Destroy sampler. */
		ccl_sampler_destroy(s);
	}

	/* Destroy context. */
	ccl_context_destroy(ctx);

	/* Confirm that memory allocated by wrappers has been properly
	 * freed. */
	g_assert(ccl_wrapper_memcheck());

}
示例#14
0
/**
 * Tests creation, getting info from and destruction of
 * program wrapper objects.
 * */
static void create_info_destroy_test() {

	/* Test variables. */
	CCLContext* ctx = NULL;
	CCLProgram* prg = NULL;
	CCLProgram* prg2 = NULL;
	CCLKernel* krnl = NULL;
	CCLWrapperInfo* info = NULL;
	CCLDevice* d = NULL;
	CCLQueue* cq = NULL;
	size_t gws;
	size_t lws;
	cl_uint a_h[CCL_TEST_PROGRAM_BUF_SIZE];
	cl_uint b_h[CCL_TEST_PROGRAM_BUF_SIZE];
	cl_uint c_h[CCL_TEST_PROGRAM_BUF_SIZE];
	cl_uint d_h ;
	CCLBuffer* a_w;
	CCLBuffer* b_w;
	CCLBuffer* c_w;
	CCLEvent* evt_w1;
	CCLEvent* evt_w2;
	CCLEvent* evt_kr;
	CCLEvent* evt_r1;
	CCLEventWaitList ewl = NULL;
	GError* err = NULL;
	gchar* tmp_dir_name;
	gchar* tmp_file_prefix;

	/* Get a temp. dir. */
	tmp_dir_name = g_dir_make_tmp("test_program_XXXXXX", &err);
	g_assert_no_error(err);

	/* Get a temp file prefix. */
	tmp_file_prefix = g_strdup_printf("%s%c%s",
		tmp_dir_name, G_DIR_SEPARATOR, CCL_TEST_PROGRAM_SUM_FILENAME);

	/* Create a temporary kernel file. */
	g_file_set_contents(
		tmp_file_prefix, CCL_TEST_PROGRAM_SUM_CONTENT, -1, &err);
	g_assert_no_error(err);

	/* Create a context with devices from first available platform. */
	ctx = ccl_test_context_new(&err);
	g_assert_no_error(err);

	/* Create a new program from kernel file. */
	prg = ccl_program_new_from_source_file(
		ctx, tmp_file_prefix, &err);
	g_assert_no_error(err);

	ccl_program_destroy(prg);

	const char* file_pref = (const char*) tmp_file_prefix;
	prg = ccl_program_new_from_source_files(ctx, 1, &file_pref, &err);
	g_assert_no_error(err);

	g_free(tmp_file_prefix);

	/* Get some program info, compare it with expected info. */
	info = ccl_program_get_info(prg, CL_PROGRAM_CONTEXT, &err);
	g_assert_no_error(err);
	g_assert(*((cl_context*) info->value) == ccl_context_unwrap(ctx));

	/* Get number of devices from program info, check that this is the
	 * same value as the number of devices in context. */
	info = ccl_program_get_info(prg, CL_PROGRAM_NUM_DEVICES, &err);
	g_assert_no_error(err);
	g_assert_cmpuint(*((cl_uint*) info->value),
		==, ccl_context_get_num_devices(ctx, &err));
	g_assert_no_error(err);

	/* Get program source from program info, check that it is the
	 * same as the passed source. */
	info = ccl_program_get_info(prg, CL_PROGRAM_SOURCE, &err);
	g_assert_no_error(err);
	g_assert_cmpstr((char*) info->value,
		==, CCL_TEST_PROGRAM_SUM_CONTENT);

	/* Get first device in context (and in program). */
	d = ccl_context_get_device(ctx, 0, &err);
	g_assert_no_error(err);

	/* Check that no build was performed yet. */
	info = ccl_program_get_build_info(
		prg, d, CL_PROGRAM_BUILD_STATUS, &err);
	g_assert_no_error(err);
	g_assert_cmpint(*((cl_build_status*) info->value), ==, CL_BUILD_NONE);

	/* **** BUILD PROGRAM **** */
	ccl_program_build(prg, NULL, &err);
	g_assert_no_error(err);

	/* Get some program build info, compare it with expected values. */
	info = ccl_program_get_build_info(
		prg, d, CL_PROGRAM_BUILD_STATUS, &err);
	g_assert_no_error(err);
	g_assert((*((cl_build_status*) info->value) == CL_BUILD_SUCCESS)
		|| (*((cl_build_status*) info->value) == CL_BUILD_IN_PROGRESS));

	/* Get the build log, check that no error occurs. */
	info = ccl_program_get_build_info(prg, d, CL_PROGRAM_BUILD_LOG, &err);
	g_assert_no_error(err);

	/* Get kernel wrapper object. */
	krnl = ccl_program_get_kernel(
		prg, CCL_TEST_PROGRAM_SUM, &err);
	g_assert_no_error(err);

	/* Get some kernel info, compare it with expected info. */

	/* Get kernel function name from kernel info, compare it with the
	 * expected value. */
	info = ccl_kernel_get_info(krnl, CL_KERNEL_FUNCTION_NAME, &err);
	g_assert_no_error(err);
	g_assert_cmpstr(
		(gchar*) info->value, ==, CCL_TEST_PROGRAM_SUM);

	/* Check if the kernel context is the same as the initial context
	 * and the program context. */
	info = ccl_kernel_get_info(krnl, CL_KERNEL_CONTEXT, &err);
	g_assert_no_error(err);
	g_assert(*((cl_context*) info->value) == ccl_context_unwrap(ctx));

	info = ccl_kernel_get_info(krnl, CL_KERNEL_PROGRAM, &err);
	g_assert_no_error(err);
	g_assert(*((cl_program*) info->value) == ccl_program_unwrap(prg));

#ifndef OPENCL_STUB
#ifdef CL_VERSION_1_2

	cl_kernel_arg_address_qualifier kaaq;
	char* kernel_arg_type_name;
	char* kernel_arg_name;
	cl_uint ocl_ver;

	/* Get OpenCL version of program's underlying platform. */
	ocl_ver = ccl_program_get_opencl_version(prg, &err);
	g_assert_no_error(err);

	/* If platform supports kernel argument queries, get kernel argument
	 * information and compare it with expected info. */
	if (ocl_ver >= 120) {

		/* First kernel argument. */
		kaaq = ccl_kernel_get_arg_info_scalar(krnl, 0,
				CL_KERNEL_ARG_ADDRESS_QUALIFIER,
				cl_kernel_arg_address_qualifier, &err);
		g_assert((err == NULL) || (err->code == CCL_ERROR_INFO_UNAVAILABLE_OCL));
		if (err == NULL) {
			g_assert_cmphex(kaaq, ==, CL_KERNEL_ARG_ADDRESS_GLOBAL);
		} else {