Пример #1
0
/**
 * Show basic device information.
 *
 * @param[in] d Device wrapper object.
 * */
void ccl_devinfo_show_device_info_basic(CCLDevice* d) {

	/* A row of the device info_map. */
	const CCLDevQueryMap* info_row;

	/* Parameter value and size. */
	CCLWrapperInfo* param_value;

	/* Parameter value string. */
	gchar param_value_str[CCL_DEVINFO_MAXINFOLEN];

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

	/* Cycle through the pre-defined basic information array. */
	for (guint i = 0; basic_info[i] != NULL; i++) {

		/* Get next row. */
		info_row = ccl_devquery_prefix(basic_info[i], NULL);

		/* Check that its a valid parameter, otherwise we have a
		 * programming error, so it is better to abort. */
		g_assert(info_row != NULL);

		/* Get parameter value for current info_map row. */
		param_value = ccl_device_get_info(d, info_row->device_info, &err);

		/* Check for errors. */
		if (err == NULL) {

			/* If no error, show current parameter value... */
			ccl_devinfo_output_device_info(
				info_row->param_name,
				info_row->format(
					param_value, param_value_str,
					CCL_DEVINFO_MAXINFOLEN,
					info_row->units),
				info_row->description);

		} else {

			/* ...otherwise clear error... */
			g_clear_error(&err);
			if (opt_nfound) {
				/* ...and show that parameter is not available, if user
				 * requested so. */
				ccl_devinfo_output_device_info(
					info_row->param_name,
					CCL_DEVINFO_NA,
					info_row->description);
			}
		}

	}

}
Пример #2
0
/**
 * Show all available device information.
 *
 * @param[in] d Device wrapper object.
 * */
void ccl_devinfo_show_device_info_all(CCLDevice* d) {

	/* Parameter value and size. */
	CCLWrapperInfo* param_value;

	/* Parameter value string. */
	gchar param_value_str[CCL_DEVINFO_MAXINFOLEN];

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

	/* Cycle through all supported device information names. */
	for (gint k = 0; k < ccl_devquery_info_map_size; k++) {

		/* Get the device information value and size. */
		param_value = ccl_device_get_info(
			d, ccl_devquery_info_map[k].device_info, &err);

		/* Check for errors. */
		if (err == NULL) {

			/* If no error, show current parameter value... */
			ccl_devinfo_output_device_info(
				ccl_devquery_info_map[k].param_name,
				ccl_devquery_info_map[k].format(
					param_value, param_value_str,
					CCL_DEVINFO_MAXINFOLEN,
					ccl_devquery_info_map[k].units),
				ccl_devquery_info_map[k].description);

		} else {

			/* ...otherwise clear error... */
			g_clear_error(&err);
			if (opt_nfound) {
				/* ...and show that parameter is not available, if user
				 * requested so. */
				ccl_devinfo_output_device_info(
					ccl_devquery_info_map[k].param_name,
					CCL_DEVINFO_NA,
					ccl_devquery_info_map[k].description);
			}
		}
	}

}
Пример #3
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;

}
Пример #4
0
/**
 * Show user specified device information.
 *
 * @param[in] d Device wrapper object.
 * */
void ccl_devinfo_show_device_info_custom(CCLDevice* d) {

	/* A row of the device info_map. */
	const CCLDevQueryMap* info_row;

	/* Parameter value and size. */
	CCLWrapperInfo* param_value;

	/* Parameter value string. */
	gchar param_value_str[CCL_DEVINFO_MAXINFOLEN];

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

	/* Custom parameter name in proper format. */
	gchar* custom_param_name;

	/* Index of next row of the device info_map. */
	gint idx;

	/* Cycle through all user specified parameter substrings. */
	for (guint i = 0; opt_custom[i] != NULL; i++) {

		/* Set index of next row to zero. */
		idx = 0;

		/* Put info name in proper format. */
		custom_param_name = ccl_devquery_get_prefix_final(opt_custom[i]);

		/* Get next row (the first one). */
		info_row = ccl_devquery_match(custom_param_name, &idx);

		/* Keep getting rows until we reach the end of the device
		 * info_map. */
		while (info_row != NULL) {

			/* Get parameter value for current info_map row. */
			param_value = ccl_device_get_info(d, info_row->device_info, &err);

			/* Check for errors. */
			if (err == NULL) {

				/* If no error, show current parameter value... */
				ccl_devinfo_output_device_info(
					info_row->param_name,
					info_row->format(
						param_value, param_value_str,
						CCL_DEVINFO_MAXINFOLEN,
						info_row->units),
					info_row->description);

			} else {

				/* ...otherwise clear error... */
				g_clear_error(&err);
				if (opt_nfound) {
					/* ...and show that parameter is not available, if user
					* requested so. */
					ccl_devinfo_output_device_info(
						info_row->param_name,
						CCL_DEVINFO_NA,
						info_row->description);
				}
			}

			/* Get next row. */
			info_row = ccl_devquery_match(custom_param_name, &idx);

		}

		/* Free the proper format custom parameter name. */
		g_free(custom_param_name);

	}

}
Пример #5
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());

}