Exemplo n.º 1
0
bool
piglit_cl_write_whole_buffer(cl_command_queue command_queue, cl_mem buffer,
                             const void *ptr)
{
	bool success;
	size_t* buffer_size;

	buffer_size = piglit_cl_get_mem_object_info(buffer, CL_MEM_SIZE);
	success = piglit_cl_write_buffer(command_queue, buffer, 0, *buffer_size,
	                                 ptr);
	free(buffer_size);

	return success;
}
Exemplo n.º 2
0
enum piglit_result
piglit_cl_test(const int argc,
               const char** argv,
               const struct piglit_cl_custom_test_config* config,
               const struct piglit_cl_custom_test_env* env)
{
	enum piglit_result result = PIGLIT_PASS;

	size_t global_size = 1;
	size_t local_size = 1;
	cl_int data = 0;

	piglit_cl_context context = NULL;
	cl_mem buffer = NULL;
	cl_program program = NULL;
	cl_kernel kernel = NULL;

	/* Create objects up to the kernel */
	context = piglit_cl_create_context(env->platform_id, &env->device_id, 1);
	buffer = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE,
	                                 sizeof(cl_int));
	program = piglit_cl_build_program_with_source(context, 1, &source, "");
	kernel = piglit_cl_create_kernel(program, "test");

	/* Set kernel arguments and run the kernel */
	piglit_cl_write_buffer(context->command_queues[0], buffer, 0,
	                       sizeof(cl_int), &data);
	piglit_cl_set_kernel_buffer_arg(kernel, 0, &buffer);
	piglit_cl_execute_ND_range_kernel(context->command_queues[0], kernel, 1,
	                                  NULL, &global_size, &local_size);

	/* Read the buffer and check the result */
	piglit_cl_read_buffer(context->command_queues[0], buffer, 0,
	                      sizeof(cl_int), &data);
	if(data != -1) {
		fprintf(stderr,
		        "Failed to properly execute the kernel.\n");
		result = PIGLIT_FAIL;
	}

	/* Release resources */
	clReleaseKernel(kernel);
	clReleaseProgram(program);
	clReleaseMemObject(buffer);
	piglit_cl_release_context(context);

	return result;
}
Exemplo n.º 3
0
static enum piglit_result
buffer_test(piglit_cl_context *ctx,
            cl_program *prg,
            cl_mem_flags in_flags,
            cl_mem_flags out_flags,
            float data)
{
    float in_data[BUFFER_SIZE];
    float out_data[BUFFER_SIZE];
    float *result = out_data;

    cl_mem in_buffer = NULL, out_buffer = NULL;
    cl_kernel kernel = NULL;

    piglit_cl_context context = *ctx;

    cl_int errNo;
    unsigned i;
    size_t global = BUFFER_SIZE;
    size_t local = 1;
    enum piglit_result ret = PIGLIT_PASS;
    const char kernel_name[] = "test";

    printf("> Running kernel test: in-0x%x-out-0x%x\n",
    (unsigned)in_flags, (unsigned)out_flags);
    for (i = 0; i < BUFFER_SIZE; ++i) {
        in_data[i] = data;
        out_data[i] = 0.0f;
    }
    printf("Using kernel %s\n", kernel_name);

    printf("Creating buffers...\n");
    /* Create input buffer */
    if ((in_flags & CL_MEM_USE_HOST_PTR) ||
    (in_flags & CL_MEM_COPY_HOST_PTR)) {
        /* Use host side memory */
        in_buffer = clCreateBuffer(context->cl_ctx, in_flags,
        sizeof(in_data), in_data, &errNo);
    } else {
        /* Use device memory and copy */
        in_buffer = clCreateBuffer(context->cl_ctx, in_flags,
        sizeof(in_data), NULL, &errNo);
        if (errNo == CL_SUCCESS && !piglit_cl_write_buffer(
            context->command_queues[0], in_buffer, 0,
            sizeof(in_data), in_data)) {
            ret = PIGLIT_FAIL;
            goto cleanup;
        }
    }

    if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
        fprintf(stderr,
        "Could not create in buffer with flags %x: %s\n",
        (unsigned)in_flags, piglit_cl_get_error_name(errNo));
        ret = PIGLIT_FAIL;
        goto cleanup;
    }

    /* Create destination buffer */
    if ((out_flags & CL_MEM_USE_HOST_PTR) ||
    (out_flags & CL_MEM_COPY_HOST_PTR)) {
        out_buffer = clCreateBuffer(context->cl_ctx, out_flags,
        sizeof(out_data), out_data, &errNo);
    } else {
        out_buffer = clCreateBuffer(context->cl_ctx, out_flags,
        sizeof(out_data), NULL, &errNo);
    }
    if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
        fprintf(stderr,
        "Could not create out buffer with flags %x: %s\n",
        (unsigned)out_flags, piglit_cl_get_error_name(errNo));
        ret = PIGLIT_FAIL;
        goto cleanup;
    }
    kernel = piglit_cl_create_kernel(*prg, kernel_name);

    printf("Setting kernel arguments...\n");
    if (!piglit_cl_set_kernel_arg(kernel, 0, sizeof(cl_mem), &out_buffer)) {
        ret = PIGLIT_FAIL;
        goto cleanup;
    }
    if (!piglit_cl_set_kernel_arg(kernel, 1, sizeof(cl_mem), &in_buffer)) {
        ret = PIGLIT_FAIL;
        goto cleanup;
    }

    printf("Running the kernel...\n");
    if (!piglit_cl_enqueue_ND_range_kernel(context->command_queues[0],
    kernel, 1, &global, &local)) {
        ret = PIGLIT_FAIL;
        goto cleanup;
    }

    clFlush(context->command_queues[0]);

    printf("Retrieving results...\n");
    if ((out_flags & CL_MEM_USE_HOST_PTR) ||
    (out_flags & CL_MEM_ALLOC_HOST_PTR)) {
        /* buffer uses host side memory, map it here,
                 * map is also a synchronization point */
        result = clEnqueueMapBuffer(context->command_queues[0],
        out_buffer, true, CL_MAP_READ, 0, sizeof(out_data), 0,
        NULL, NULL, &errNo);
        if (!piglit_cl_check_error(errNo, CL_SUCCESS)) {
            fprintf(stderr,
            "Could not map out buffer with flags %x: %s\n",
            (unsigned)out_flags,
            piglit_cl_get_error_name(errNo));
            ret = PIGLIT_FAIL;
            goto cleanup;
        }
    } else {
        /* Copy back from device */
        if (!piglit_cl_read_buffer(context->command_queues[0],
        out_buffer, 0, sizeof(out_data),
        out_data)) {
            ret = PIGLIT_FAIL;
            goto cleanup;
        }
    }

    for (i = 0; i < BUFFER_SIZE; ++i) {
        if (!piglit_cl_probe_floating(result[i], in_data[i], 0)) {
            printf("Error at float[%u]\n", i);
            ret = PIGLIT_FAIL;
            goto cleanup;
        }
    }

    /* cleanup */
cleanup:
    clReleaseMemObject(in_buffer);
    clReleaseMemObject(out_buffer);
    clReleaseKernel(kernel);
    piglit_report_subtest_result(ret, "in-0x%x-out-0x%x",
                                 (unsigned)in_flags, (unsigned)out_flags);
    return ret;

};