Ejemplo n.º 1
0
int errorL1Aux(int code, GError **err) {
	int status = errorL2Aux(code, "called by errorL1Aux", err);
	ccl_if_err_goto(*err, error_handler);
	goto finish;
error_handler:
	g_assert(*err != NULL);
	status = (*err)->code;
finish:
	return status;
}
Ejemplo n.º 2
0
/**
 * Test no errors.
 * */
static void errorNoneTest() {
	GError *err = NULL;

	int status = errorL2Aux(TEST_CCL_SUCCESS,
		"called by errorOneLevelTest", &err);
	ccl_if_err_goto(err, error_handler);
	CCL_UNUSED(status); /* Avoid compiler warnings. */

	goto cleanup;

error_handler:
	g_assert_not_reached();
	g_error_free(err);

cleanup:
	g_assert_no_error(err);
	return;
}
Ejemplo n.º 3
0
/**
 * Test two level error handling.
 * */
static void errorTwoLevelTest() {
	GError *err = NULL;

	int status = errorL1Aux(TEST_CCL_ERROR_2, &err);
	ccl_if_err_goto(err, error_handler);
	CCL_UNUSED(status); /* Avoid compiler warnings. */

	g_assert_not_reached();
	goto cleanup;

error_handler:
	g_assert_error(err, TEST_CCL_ERROR, TEST_CCL_ERROR_2);
	g_assert_cmpstr(err->message, ==,
		"Big error in level 2 function: called by errorL1Aux");
	g_error_free(err);

cleanup:
	return;
}
Ejemplo n.º 4
0
/**
 * Parse and verify command line arguments.
 *
 * @param[in] argc Number of command line arguments.
 * @param[in] argv Command line arguments.
 * @param[out] err Return location for a CCLErr, or `NULL` if error
 * reporting is to be ignored.
 * */
void ccl_devinfo_args_parse(int argc, char* argv[], CCLErr** err) {

	/* Make sure err is NULL or it is not set. */
	g_return_if_fail(err == NULL || *err == NULL);

	/* Command line options context. */
	GOptionContext* context = NULL;

	/* Create parsing context. */
	context = g_option_context_new(" - " CCL_DEVINFO_DESCRIPTION);

	/* Add acceptable command line options to context. */
	g_option_context_add_main_entries(context, entries, NULL);

	/* Use context to parse command line options. */
	g_option_context_parse(context, &argc, &argv, err);
	ccl_if_err_goto(*err, error_handler);

	/* If we get here, no need for error treatment, jump to cleanup. */
	g_assert(*err == NULL);
	goto cleanup;

error_handler:

	/* If we got here, everything is OK. */
	g_assert(*err != NULL);

cleanup:

	/* Free context. */
	if (context) g_option_context_free(context);

	/* Return. */
	return;

}
Ejemplo n.º 5
0
/**
 * Device info main program function.
 *
 * @param[in] argc Number of command line arguments.
 * @param[in] argv Vector of command line arguments.
 * @return ::CCL_SUCCESS if program returns with no error, or another
 * ::CCLErrorCode value otherwise.
 */
int main(int argc, char* argv[]) {

	/* Error object. */
	CCLErr* err = NULL;

	/* List of platform wrapper objects. */
	CCLPlatforms* platforms = NULL;

	/* List of device wrapper objects. */
	CCLDevSelDevices devices = NULL;

	/* Current platform and device. */
	CCLPlatform* p;
	CCLDevice* d;

	/* Number of devices in platform. */
	guint num_devs;

	/* Device information value object. */
	CCLWrapperInfo* info_value = NULL;

	/* Device name. */
	gchar* dev_name;

	/* Program return status. */
	gint status;

	/* Parse command line options. */
	ccl_devinfo_args_parse(argc, argv, &err);
	ccl_if_err_goto(err, error_handler);

	/* If version was requested, output version and exit. */
	if (version) {
		ccl_common_version_print("ccl_devinfo");
		exit(0);
	}

	/* Check if user requested a list of known information parameters. */
	if (opt_list) {

		/*Yes, user requested list, present it. */

		g_fprintf(CCL_DEVINFO_OUT, "\nKnown information parameters:\n\n");
		for (gint i = 0; i < ccl_devquery_info_map_size; i++) {
			if (opt_verb) {
				g_fprintf(CCL_DEVINFO_OUT,
					"\t%s\n\t\t%s.\n\n",
					ccl_devquery_info_map[i].param_name,
					ccl_devquery_info_map[i].description);
			} else {
				g_fprintf(CCL_DEVINFO_OUT,
					"\t%s\n",
					ccl_devquery_info_map[i].param_name);
			}
		}
		g_fprintf(CCL_DEVINFO_OUT, "\n");

	} else {

		/* User didn't request list, proceed as normal query. */

		/* Ignore platforms and focus only on number of devices in system? */
		if (no_platf) {

			/* Ignore platform, continue device-wise. */

			/* Get all devices in the system. */
			devices = ccl_devsel_devices_new(&err);
			ccl_if_err_goto(err, error_handler);

			/* Cycle through devices. */
			for (guint j = 0; j < devices->len; j++) {

				/* Get out if this device is not to be queried. */
				if ((opt_dev != G_MAXUINT) && (j != opt_dev))
					continue;

				/* Get current device. */
				d = (CCLDevice*) devices->pdata[j];

				/* Get device name. */
				info_value = ccl_device_get_info(d, CL_DEVICE_NAME, &err);
				ccl_if_err_goto(err, error_handler);

				dev_name = (gchar*) info_value->value;

				/* Show device information. */
				g_fprintf(CCL_DEVINFO_OUT,
					"\n    [ Device #%d: %s ]\n\n",
					j, dev_name);
				ccl_devinfo_show_device_info(d);

			}
			g_fprintf(CCL_DEVINFO_OUT, "\n");

		} else {

			/* Do not ignore platforms, continue platform-wise. */

			/* Get list of platform wrapper objects. */
			platforms = ccl_platforms_new(&err);
			ccl_if_err_goto(err, error_handler);

			/* Cycle through platforms. */
			for (guint i = 0; i < ccl_platforms_count(platforms); i++) {

				/* Get out if this platform is not to be queried. */
				if ((opt_platf != G_MAXUINT) && (i != opt_platf))
					continue;

				/* Get current platform. */
				p = ccl_platforms_get(platforms, i);

				/* Show platform information. */
				ccl_devinfo_show_platform_info(p, i);

				/* Get number of devices. */
				num_devs = ccl_platform_get_num_devices(p, &err);

				/* Is this a platform without devices? */
				if ((err) && (err->domain == CCL_OCL_ERROR) &&
						(err->code == CL_DEVICE_NOT_FOUND)) {

					/* Clear "device not found" error. */
					g_clear_error(&err);

					/* Inform about non-existing devices. */
					g_fprintf(CCL_DEVINFO_OUT,
						"\n    [ No devices found ]\n\n");

					/* Skip this platform. */
					continue;
				}
				ccl_if_err_goto(err, error_handler);

				/* Cycle through devices. */
				for (guint j = 0; j < num_devs; j++) {

					/* Get out if this device is not to be queried. */
					if ((opt_dev != G_MAXUINT) && (j != opt_dev))
						continue;

					/* Get current device. */
					d = ccl_platform_get_device(p, j, &err);
					ccl_if_err_goto(err, error_handler);

					/* Get device name. */
					info_value = ccl_device_get_info(d, CL_DEVICE_NAME, &err);
					ccl_if_err_goto(err, error_handler);

					dev_name = (gchar*) info_value->value;

					/* Show device information. */
					g_fprintf(CCL_DEVINFO_OUT,
						"\n    [ Device #%d: %s ]\n\n",
						j, dev_name);
					ccl_devinfo_show_device_info(d);

				}
				g_fprintf(CCL_DEVINFO_OUT, "\n");
			}
		}
	}

	/* If we got here, everything is OK. */
	g_assert(err == NULL);
	status = CCL_SUCCESS;
	goto cleanup;

error_handler:

	/* If we got here there was an error, verify that it is so. */
	g_assert(err != NULL);
	g_fprintf(stderr, "%s\n", err->message);
	status = (err->domain == CCL_ERROR) ? err->code : CCL_ERROR_OTHER;
	g_error_free(err);

cleanup:

	/* Free stuff! */
	if (platforms) ccl_platforms_destroy(platforms);
	if (devices) ccl_devsel_devices_destroy(devices);
	g_strfreev(opt_custom);

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

	/* Return status. */
	return status;

}
Ejemplo n.º 6
0
/**
 * Kernel info main function.
 *
 * @param[in] argc Number of command line arguments.
 * @param[in] argv Command line arguments.
 * @return ::CCL_SUCCESS if program returns with no error, or another
 * ::CCLErrorCode value otherwise.
 * */
int main(int argc, char *argv[]) {

	/* ***************** */
	/* Program variables */
	/* ***************** */

	/* Function and program return status. */
	int status;
	/* Error management. */
	GError *err = NULL;
	/* Context wrapper. */
	CCLContext* ctx = NULL;
	/* Program wrapper. */
	CCLProgram* prg = NULL;
	/* Kernel wrapper. */
	CCLKernel* krnl = NULL;
	/* Device wrapper. */
	CCLDevice* dev = NULL;
	/* Device filters. */
	CCLDevSelFilters filters = NULL;
	/* Default device index. */
	cl_int dev_idx = -1;
	/* OpenCL version. */
	double ocl_ver;
	/* Kernel workgroup info variables. */
	size_t k_wg_size;
	size_t k_pref_wg_size_mult;
	size_t* k_compile_wg_size;
	cl_ulong k_loc_mem_size;
	cl_ulong k_priv_mem_size;

	/* ************************** */
	/* Parse command line options */
	/* ************************** */

	/* If version was requested, output version and exit. */
	if ((argc == 2) && (g_strcmp0("--version", argv[1]) == 0)) {
		ccl_common_version_print("ccl_kerninfo");
		exit(0);
	}

	ccl_if_err_create_goto(err, CCL_ERROR, (argc < 3) || (argc > 4),
		CCL_ERROR_ARGS, error_handler,
		"Usage: %s <program_file> <kernel_name> [device_index]\n",
		argv[0]);
	if (argc == 4) dev_idx = atoi(argv[3]);

	/* ********************************************* */
	/* Initialize OpenCL variables and build program */
	/* ********************************************* */

	/* Select a context/device. */
	ccl_devsel_add_dep_filter(
		&filters, ccl_devsel_dep_menu,
		(dev_idx == -1) ? NULL : (void*) &dev_idx);
	ctx = ccl_context_new_from_filters(&filters, &err);
	ccl_if_err_goto(err, error_handler);

	/* Get program which contains kernel. */
	prg = ccl_program_new_from_source_file(ctx, argv[1], &err);
	ccl_if_err_goto(err, error_handler);

	/* Build program. */
	ccl_program_build(prg, NULL, &err);
	ccl_if_err_goto(err, error_handler);

	/* Get kernel */
	krnl = ccl_program_get_kernel(prg, argv[2], &err);
	ccl_if_err_goto(err, error_handler);

	/* Get the device. */
	dev = ccl_context_get_device(ctx, 0, &err);
	ccl_if_err_goto(err, error_handler);

	/* Check platform  OpenCL version. */
	ocl_ver = ccl_kernel_get_opencl_version(krnl, &err);
	ccl_if_err_goto(err, error_handler);

	/* *************************** */
	/*  Get and print kernel info  */
	/* *************************** */

	g_printf("\n   ======================== Static Kernel Information =======================\n\n");

	k_wg_size = ccl_kernel_get_workgroup_info_scalar(
		krnl, dev, CL_KERNEL_WORK_GROUP_SIZE, size_t, &err);
	ccl_if_err_goto(err, error_handler);
	g_printf("     Maximum workgroup size                  : %lu\n",
		(unsigned long) k_wg_size);

	/* Only show info about CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE
	 * if OpenCL version of the underlying platform is >= 1.1. */
	if (ocl_ver >= 110) {
		k_pref_wg_size_mult = ccl_kernel_get_workgroup_info_scalar(krnl,
			dev, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_t, &err);
		ccl_if_err_goto(err, error_handler);
		g_printf("     Preferred multiple of workgroup size    : %lu\n",
			(unsigned long) k_pref_wg_size_mult);
	}

	k_compile_wg_size = ccl_kernel_get_workgroup_info_array(krnl, dev,
		CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size_t*, &err);
	ccl_if_err_goto(err, error_handler);
	g_printf("     WG size in __attribute__ qualifier      : (%lu, %lu, %lu)\n",
		(unsigned long) k_compile_wg_size[0],
		(unsigned long) k_compile_wg_size[1],
		(unsigned long) k_compile_wg_size[2]);

	k_loc_mem_size = ccl_kernel_get_workgroup_info_scalar(krnl, dev,
		CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong, &err);
	ccl_if_err_goto(err, error_handler);
	g_printf("     Local memory used by kernel             : %lu bytes\n",
		(unsigned long) k_loc_mem_size);

	k_priv_mem_size = ccl_kernel_get_workgroup_info_scalar(krnl, dev,
		CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong, &err);
	ccl_if_err_goto(err, error_handler);
	g_printf("     Min. private mem. used by each workitem : %lu bytes\n",
		(unsigned long) k_priv_mem_size);

	g_printf("\n");

	/* ************** */
	/* Error handling */
	/* ************** */

	/* If we get here, no need for error checking, jump to cleanup. */
	g_assert(err == NULL);
	status = CCL_SUCCESS;
	goto cleanup;

error_handler:
	/* If we got here there was an error, verify that it is so. */
	g_assert(err != NULL);
	g_fprintf(stderr, "%s\n", err->message);
	status = (err->domain == CCL_ERROR) ? err->code : CCL_ERROR_OTHER;
	g_error_free(err);

cleanup:

	/* *********** */
	/* Free stuff! */
	/* *********** */

	if (prg != NULL) ccl_program_destroy(prg);
	if (ctx != NULL) ccl_context_destroy(ctx);

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

	/* Return status. */
	return status;

}