Exemplo n.º 1
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;

}
Exemplo n.º 2
0
/**
 * Tests devquery module helper functions.
 * */
static void helpers_test() {

	CCLPlatforms* platfs = NULL;
	CCLPlatform* p = NULL;
	CCLDevice* d = NULL;
	GError* err = NULL;
	guint num_devs;
	guint num_platfs;
	CCLWrapperInfo* info;
	gchar param_value_str[CCL_TEST_DEVQUERY_MAXINFOLEN];

	/* Get platforms. */
	platfs = ccl_platforms_new(&err);
	if (err == NULL) {

		/* Number of platforms. */
		num_platfs = ccl_platforms_count(platfs);
		g_debug("* Found %d OpenCL platforms", num_platfs);

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

			/* Get current platform. */
			p = ccl_platforms_get(platfs, i);
			g_debug(">> Platform %d:", i);

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

			/* Only test for device information if device count was
			 * successfully obtained. */
			if (err != NULL) {
				g_test_message("Error obtaining number of devices for platform %d (%s).",
					i, err->message);
				g_clear_error(&err);
			} else {

				g_debug("==== # Devs  : %d", num_devs);

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

					/* Get current device. */
					d = ccl_platform_get_device(p, j, &err);
					g_assert_no_error(err);
					g_debug("====== Device #%d", j);

					for (gint k = 0; k < ccl_devquery_info_map_size; k++) {
						info = ccl_device_get_info(d, ccl_devquery_info_map[k].device_info, &err);
						if (err == NULL) {
							g_debug("\t%s : %s",
								ccl_devquery_info_map[k].param_name,
								ccl_devquery_info_map[k].format(
									info, param_value_str,
									CCL_TEST_DEVQUERY_MAXINFOLEN,
									ccl_devquery_info_map[k].units));
						} else {
							g_clear_error(&err);
							g_debug("\t%s : %s",
								ccl_devquery_info_map[k].param_name, "N/A");

						}
					}

				}
			}
		}

		/* Destroy list of platforms. */
		ccl_platforms_destroy(platfs);

	} else {

		/* Unable to get any OpenCL platforms, test can't pass. */
		g_test_message("Test failed due to following error: %s",
			err->message);
		g_test_fail();
	}

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

}