void cl_initilize() { cl_int errcode; cl_platform_id platform[10]; get_platforms(platform); cl_device_id devices[10]; int platform_index = 0; get_devices(platform[platform_index], devices); int device_index = 0; show_device_info(devices[device_index]); context = clCreateContext(NULL, 1, &devices[device_index], NULL, NULL, &errcode); checkError(clCreateContext); queue = clCreateCommandQueue (context, devices[device_index], CL_QUEUE_PROFILING_ENABLE, &errcode); // третий параметр - свойства checkError(clCreateCommandQueue); char* source = "\n\ __kernel void sum(__global const uchar *src, __global uchar *trg, int m, int n)\n\ {\n\ int i = get_global_id(0);\n\ int j = get_global_id(1);\n\ int SIdx = (i*n + (n-1 - j)) ;\n\ int DIdx = (j*m + i) ;\n\ if (i > m) return;\ if (j > n) return;\ for (int c = 0; c < 3; c++)\n\ trg[DIdx*3+c] = src[SIdx*3+c];\n\ }";
static void read_info_complete(uint8_t status, uint16_t length, const void *param, void *user_data) { const struct mgmt_rp_read_info *rp = param; if (status != MGMT_STATUS_SUCCESS) { DBG("Failed to read device information: %s (0x%02x)", mgmt_errstr(status), status); resp_mgmt(err_PROTO_ERR); return; } if (length < sizeof(*rp)) { DBG("Wrong size of read info response"); resp_mgmt(err_PROTO_ERR); return; } /* Save a copy of the device info response */ dev_info = *rp; show_device_info(); resp_mgmt_with_data(dev_info.current_settings); }
void show_all_active_devices(void) { int i; if (dev_list.dev_total == 0) return; dm_log(NULL, "================="); for (i = 0; i < MAX_DEVICE_NO; i++) if (dev_list.dev[i].active) show_device_info(dev_list.dev[i].idev); dm_log(NULL, "================="); }
int main() { const cl_uint n_max = 16; cl_uint i, j, n_platforms, n_devices; cl_platform_id platforms[n_max]; cl_device_id devices[n_max]; clCheckError(clGetPlatformIDs(0, NULL, &n_platforms), "getting number of available platforms"); // seems strange: here first argument may be not 0, but not in clGetDeviceIDs clCheckError(clGetPlatformIDs(n_platforms, platforms, NULL), "getting available platforms' IDs"); for (i=0; i<n_platforms; i++) { printf("\n============= Platform #%u =============\n", i+1); if (!clSoftCheckError(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &n_devices), "getting number of available devices")) // here the third argument must be 0 { if (!clSoftCheckError(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, n_devices, devices, NULL), "getting available devices' IDs")) for (j=0; j<n_devices; j++) { printf("\n============== Device #%u ==============\n", j+1); show_device_info(devices[j]); } } } return 0; }
int main(int argc, char *argv[]) { const struct astribank_type *abtype; struct my_usb_device mydev; const char *devpath = NULL; const char *binfile = NULL; const char *inhexfile = NULL; const char *outhexfile = NULL; struct hexdata *hexdata = NULL; int opt_reset = 0; int opt_info = 0; int opt_read_eeprom = 0; int opt_output_width = 0; int output_is_set = 0; #ifdef XORCOM_INTERNAL int opt_write_eeprom = 0; char *vendor = NULL; char *source = NULL; char *product = NULL; char *release = NULL; char *label = NULL; const char options[] = "rib:D:ghH:I:vw:C:V:P:R:S:"; #else const char options[] = "rib:D:ghH:I:vw:"; #endif int ret = 0; progname = argv[0]; assert(sizeof(struct fpga_packet_header) <= PACKET_SIZE); assert(sizeof(struct myeeprom) == EEPROM_SIZE); while (1) { int c; c = getopt (argc, argv, options); if (c == -1) break; switch (c) { case 'D': devpath = optarg; if(output_is_set++) { ERR("Cannot set -D. Another output option is already selected\n"); return 1; } break; case 'r': opt_reset = 1; break; case 'i': opt_info = 1; break; case 'b': binfile = optarg; if(output_is_set++) { ERR("Cannot set -b. Another output option is already selected\n"); return 1; } break; case 'g': opt_read_eeprom = 1; break; case 'H': outhexfile = optarg; if(output_is_set++) { ERR("Cannot set -H. Another output option is already selected\n"); return 1; } break; case 'I': inhexfile = optarg; break; #ifdef XORCOM_INTERNAL case 'V': vendor = optarg; break; case 'C': source = optarg; break; case 'P': product = optarg; break; case 'R': release = optarg; break; case 'S': label = optarg; { const char GOOD_CHARS[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "-_."; int len = strlen(label); int goodlen = strspn(label, GOOD_CHARS); if(len > LABEL_SIZE) { ERR("Label too long (%d > %d)\n", len, LABEL_SIZE); usage(); } if(goodlen != len) { ERR("Bad character in label number (pos=%d)\n", goodlen); usage(); } } break; #endif case 'w': opt_output_width = strtoul(optarg, NULL, 0); break; case 'v': verbose++; break; case 'h': default: ERR("Unknown option '%c'\n", c); usage(); } } if (optind != argc) { usage(); } if(inhexfile) { #ifdef XORCOM_INTERNAL if(vendor || product || release || label || source ) { ERR("The -I option is exclusive of -[VPRSC]\n"); return 1; } #endif parse_hexfile_set_reporting(parse_report_func); hexdata = parse_hexfile(inhexfile, MAX_HEX_LINES); if(!hexdata) { ERR("Bailing out\n"); exit(1); } if(opt_info) { printf("%s: Version=%s Checksum=%d\n", inhexfile, hexdata->version_info, bsd_checksum(hexdata)); } if(binfile) { dump_binary(hexdata, binfile); return 0; } if(outhexfile) { if(opt_output_width) dump_hexfile2(hexdata, outhexfile, opt_output_width); else dump_hexfile(hexdata, outhexfile); return 0; } } #ifdef XORCOM_INTERNAL else if(vendor || product || release || label || source ) { if(outhexfile) { FILE *fp; if(strcmp(outhexfile, "-") == 0) fp = stdout; else if((fp = fopen(outhexfile, "w")) == NULL) { perror(outhexfile); return 1; } memset(&mydev.eeprom, 0, sizeof(struct myeeprom)); eeprom_fill(&mydev.eeprom, vendor, product, release, label, source); gen_hexline((uint8_t *)&mydev.eeprom, 0, sizeof(mydev.eeprom), fp); gen_hexline(NULL, 0, 0, fp); /* EOF */ return 0; } } #endif if(!devpath) { ERR("Missing device path\n"); usage(); } DBG("Startup %s\n", devpath); if((abtype = my_usb_device_identify(devpath, &mydev)) == NULL) { ERR("Bad device. Does not match our types.\n"); usage(); } INFO("FIRMWARE: %s (type=%d)\n", abtype->name, abtype->type_code); if(!my_usb_device_init(devpath, &mydev, abtype)) { ERR("Failed to initialize USB device '%s'\n", devpath); ret = -ENODEV; goto dev_err; } ret = eeprom_get(&mydev); if(ret < 0) { ERR("Failed reading eeprom\n"); goto dev_err; } #ifdef XORCOM_INTERNAL if(vendor || product || release || label || source ) { eeprom_fill(&mydev.eeprom, vendor, product, release, label, source); opt_write_eeprom = 1; opt_read_eeprom = 1; } #endif if(opt_read_eeprom) { show_device_info(&mydev); } if(hexdata) { if (!mydev.is_usb2) INFO("Warning: working on a low end USB1 backend\n"); if(!fpga_load(&mydev, hexdata)) { ERR("FPGA loading failed\n"); ret = -ENODEV; goto dev_err; } ret = renumerate_device(&mydev, PT_RENUMERATE); if(ret < 0) { ERR("Renumeration failed: errno=%d\n", ret); goto dev_err; } } #ifdef XORCOM_INTERNAL else if(opt_write_eeprom) { if(abtype->type_code == USB_FIRMWARE_II) { ERR("No EEPROM burning command in %s. Use fxload for that\n", abtype->name); goto dev_err; } ret = eeprom_set(&mydev, &mydev.eeprom); if(ret < 0) { ERR("Failed writing eeprom: %s\n", strerror(-ret)); goto dev_err; } printf("------- RESULTS -------\n"); show_device_info(&mydev); } #endif if(opt_reset) { DBG("Reseting to default\n"); ret = renumerate_device(&mydev, PT_RESET); if(ret < 0) { ERR("Renumeration to default failed: errno=%d\n", ret); goto dev_err; } } DBG("Exiting\n"); dev_err: my_usb_device_cleanup(&mydev); return ret; }