#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <cf4ocl2.h>
#define ERROR_MSG_AND_EXIT(msg) \
do { fprintf(stderr, "\n%s\n", msg); exit(EXIT_FAILURE); } while(0)
#define HANDLE_ERROR(err) \
if (err != NULL) { ERROR_MSG_AND_EXIT(err->message); }
#define USAGE \
"Usage: device_filter 1|2\n\n1 - " \
"Create context with filtered devices\n" \
"2 - List filtered devices\n"
int main(
int argc,
char* argv[]) {
cl_uint num_devs;
char* dev_name;
int op;
if (argc < 2)
ERROR_MSG_AND_EXIT(USAGE);
else
op = atoi(argv[1]);
if (op == 1) {
HANDLE_ERROR(err);
HANDLE_ERROR(err);
printf("Context was successfully created with %d device(s)!\n",
num_devs);
} else if (op == 2) {
HANDLE_ERROR(err);
if (devices->len > 0) {
printf("%d devices were accepted by the filters:\n", devices->len);
for (unsigned int i = 0; i < devices->len; ++i) {
devices->pdata[i], CL_DEVICE_NAME, char*, &err);
HANDLE_ERROR(err);
printf("\t%d - %s\n", i + 1, dev_name);
}
} else {
ERROR_MSG_AND_EXIT("No devices were accepted by the filters.");
}
} else {
ERROR_MSG_AND_EXIT(USAGE);
}
return EXIT_SUCCESS;
}