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\ }";
/* Get the first device that matches the given device type and string. */ cl_device_id get_device(cl_platform_id platform, cl_device_type device_type, const char *device_string) { cl_device_id *devices = NULL; cl_device_id device; char *name; int i; int len; int num; num = get_devices(platform, device_type, &devices); if (num < 1) return NULL; device = NULL; name = NULL; len = 0; for (i = 0; i < num; i++) { get_device_info(devices[i], CL_DEVICE_NAME, &name, &len); if (strstr(name, device_string)) { device = devices[i]; break; } } if (name != NULL) free(name); if (devices != NULL) free(devices); return device; }
/* * Print usage information, then terminate the program. */ void usage() { char *devices[MAXDEV + 1]; int ndev; printf("%s\n\n", copyright); printf("Usage:\n"); printf(" sdwriter [-v] [-d device] sdcard.img\n"); printf("\nArgs:\n"); printf(" sdcard.img Binary file with SD card image\n"); printf(" -v Verify only\n"); printf(" -d device Use specified disk device\n"); printf(" -D Debug mode\n"); printf(" -h, --help Print this help message\n"); printf(" -V, --version Print version\n"); printf("\n"); get_devices(devices, MAXDEV); if (! devices[0]) { printf("No target disk devices available.\n"); } else { printf("Available disk devices:\n\n"); for (ndev=0; devices[ndev]; ndev++) { printf(" %s\n", devices[ndev]); } } printf("\n"); exit(0); }
static int get_num_devices(DevicesPtr devices=get_devices()) { int num = 0; for(ibv_device **iter=devices.get(); *iter; ++iter) { ++num; } return num; }
/// Returns the build log. std::string build_log() const { device device = get_devices()[0]; size_t size = 0; cl_int ret = clGetProgramBuildInfo(m_program, device.id(), CL_PROGRAM_BUILD_LOG, 0, 0, &size); if(ret != CL_SUCCESS){ BOOST_THROW_EXCEPTION(runtime_exception(ret)); } std::string value(size - 1, 0); ret = clGetProgramBuildInfo(m_program, device.id(), CL_PROGRAM_BUILD_LOG, size, &value[0], 0); if(ret != CL_SUCCESS){ BOOST_THROW_EXCEPTION(runtime_exception(ret)); } return value; }
void Browser::Run(const char *pRessourcePath) { Init(pRessourcePath); // Disable auto render on format SetAutoRender(0); #ifdef WIN32 strcpy(currentPath, "c:/"); #else // strcpy(currentPath, "uda0:/"); handle = -1; char * s = NULL; int next_device_n = 0; next_device_n = get_devices(next_device_n, s); strcpy(currentPath, s); ScanDir(); #endif while (1) { RenderApp(); Update(); } }
static void ztex_disable(struct thr_info *thr) { struct cgpu_info *cgpu; applog(LOG_ERR, "%s: Disabling!", thr->cgpu->device_ztex->repr); cgpu = get_devices(thr->cgpu->device_id); cgpu->deven = DEV_DISABLED; ztex_shutdown(thr); }
/// Returns the device for the context. If the context contains multiple /// devices, the first is returned. device get_device() const { std::vector<device> devices = get_devices(); if(devices.empty()) { return device(); } return devices.front(); }
/* * Since we're getting potentially sensitive data (MAC addresses for all devices on the system), * hash all the MAC addresses to provide basic anonymity and security. */ char *internal_get_host_id(void) { size_t i; unsigned char raw_md5[16]; char *printable_md5; struct device *devices; void *ctx; devices = get_devices(); if (!(devices)) return NULL; printable_md5 = calloc(1, 37); if (!(printable_md5)) { free(devices); return NULL; } ctx = cl_hash_init("md5"); if (!(ctx)) { for (i=0; devices[i].name != NULL; i++) free(devices[i].name); free(devices); free(printable_md5); return NULL; } for (i=0; devices[i].name != NULL; i++) cl_update_hash(ctx, devices[i].mac, sizeof(devices[i].mac)); cl_finish_hash(ctx, raw_md5); for (i=0; devices[i].name != NULL; i++) free(devices[i].name); free(devices); for (i=0; i < sizeof(raw_md5); i++) { size_t len = strlen(printable_md5); switch (len) { case 8: case 13: case 18: case 23: printable_md5[len++] = '-'; break; } sprintf(printable_md5+len, "%02x", raw_md5[i]); } return printable_md5; }
void recv_set(struct packet_t *packet) { uint8_t device_src,device_dst; application_t* app; uart_putstr_P(PSTR("recv_set()\r\n")); while (get_devices(packet,&device_src,&device_dst)) { app=app_get(device_dst); if (app == NULL) continue; if (app->set == NULL) continue; app->set(packet); } }
/* * The command-line arguments to ucblinks are: * * -r specify a root relative to which ./devices and ./dev * are used to create links. * * -e the awk-based ucblinks had a default rule-base and * allowed alternate rule-bases with -e. If the user * specifies a rule-base we run the awk-based ucblinks * and pass all the args to it. * * -d undocumented debug option (like the awk-based version); * print what would be created, fixed, or is already correct. */ int main(int argc, char **argv) { int c; int err = 0; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); progname = argv[0]; /* save program name for error messages */ while ((c = getopt(argc, argv, "r:e:d")) != EOF) { switch (c) { case 'r': rootdir = optarg; break; case 'e': exec_script(argv); /* exec_script doesn't return */ break; case 'd': debug = 1; break; case '?': default: err = 1; break; } } if (err || (optind != argc)) { (void) fprintf(stderr, gettext("usage: %s [ -r rootdir ] " "[ -e rulebase ]\n"), progname); exit(1); } get_major_nums(); set_depth(); get_devices(); get_dev_links(); call_device_rules(); return (0); }
/* * Ask for a name of the target device. */ const char *ask_device() { #define MAXDEV 9 char *devices[MAXDEV + 1]; char reply[100]; int ndev; get_devices(devices, MAXDEV); if (! devices[0]) { printf("No removable USB disks avalable.\n"); quit(0); } for (;;) { printf("\n"); for (ndev=0; devices[ndev]; ndev++) { printf(" %c. %s\n", '1'+ndev, devices[ndev]); } printf(" q. Cancel\n"); printf("\nSelect disk device "); if (ndev > 1) printf("(1-%c, q): ", '0'+ndev); else printf("(1, q): "); fflush(stdout); if (! fgets(reply, sizeof(reply), stdin)) { quit(0); } if (*reply == 'q' || *reply == 'Q') { printf("Cancelled.\n"); quit(0); } if (*reply >= '1' && *reply < '1'+ndev) { char *devname = devices[*reply - '1']; char *p = strchr(devname, ' '); if (p) *p = 0; printf("\n"); return devname; } printf("\nEnter 1"); if (ndev > 1) printf("...%c", '0'+ndev); printf(" to select a device,\n"); printf("or `Q' to cancel the operation.\n"); } }
init_sys() { if (!init_system()) return(0); make_current_drawer(); strcpy(init_drawer, drawer); /* OPENDUMP(); */ get_devices(); see_cmap(); find_colors(); return(1); }
void recv_get(struct packet_t *packet) { uint8_t device_src,device_dst; uint8_t len; application_t* app; struct packet_t *send_packet = get_tx_packet(); while (get_devices(packet,&device_src,&device_dst)) { app=app_get(device_dst); set_devices(send_packet,device_dst,device_src); len=app->get(send_packet); // if (len > 0) { // data.remaining_len-=len; // } } send(packet->network->src,VALUE,send_packet); }
void Browser::Run(const char *pRessourcePath) { Init(pRessourcePath); // Disable auto render on format SetAutoRender(0); #ifdef WIN32 strcpy(currentPath, "c:/"); #else handle = 0; char path[2048]; handle = get_devices(handle, path); strcpy(currentPath, path); ScanDir(); #endif while (1) { RenderApp(); Update(); } }
static void na_application_activate (GApplication *application) { NAApplication *self = NA_APPLICATION (application); //G_APPLICATION_CLASS (na_application_parent_class)->startup (application); get_devices (self); introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (introspection_data != NULL); g_application_hold (application); guint owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, NETWORK_ANALYZER_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, on_name_acquired, on_name_lost, self, NULL); g_assert (owner_id > 0); }
void Browser::Update() { #ifdef WIN32 W32Update(); #endif Hw::SystemPoll(); get_controller_data(&ctrl, 0); { int up = 0; int down = 0; // button pressed if(ctrl.up && !old_ctrl.up){ up++; lChange[0]=mftb(); } else if (ctrl.down && !old_ctrl.down){ down++; lChange[1]=mftb(); } // button released if(!ctrl.up){ lChange[0]=0; } if(!ctrl.down){ lChange[1]=0; } uint64_t now = mftb(); if(lChange[0]>0) if(tb_diff_msec(now,lChange[0])>250){ static int uh=0; uh=!uh; if (uh) up++; } if(lChange[1]>0) if(tb_diff_msec(now,lChange[1])>250){ static int dh=0; dh=!dh; if (dh) down++; } //if (get_controller_data(&ctrl, 0)) { if (up) { switch (panelSelected) { case PANEL_FILE_LIST: entrySelected--; break; case PANEL_ACTION: actionSelected--; break; } } if (down) { switch (panelSelected) { case PANEL_FILE_LIST: entrySelected++; break; case PANEL_ACTION: actionSelected++; break; } } if (ctrl.b && !old_ctrl.b) { switch (panelSelected) { case PANEL_FILE_LIST: append_dir_to_path(currentPath, ".."); ScanDir(); break; } } if (ctrl.back && !old_ctrl.back) { #ifdef LIBXENON switch (panelSelected) { case PANEL_FILE_LIST: char path[2048]; handle = get_devices(handle, path); strcpy(currentPath, path); ScanDir(); break; } #endif } if ( (ctrl.start && !old_ctrl.start) || (ctrl.a && !old_ctrl.a) ) { switch (panelSelected) { case PANEL_FILE_LIST: { if (vEntry.size() == 0) break; FileEntry currentEntry = vEntry.at(entrySelected); if (currentEntry.type == 1) { append_dir_to_path(currentPath, (char*) currentEntry.name.c_str()); ScanDir(); } else { sprintf(currentFile, "%s/%s", currentPath, currentEntry.name.c_str()); if (ActionLaunchFile != NULL) ActionLaunchFile(currentFile); } break; } case PANEL_ACTION: { if (nbAction == 0) break; // Exec action ... //FileEntry currentEntry = vEntry.at(entrySelected); lpBrowserActionEntry currentAction = vAction[actionSelected]; if (currentAction != NULL && currentAction->action != NULL) { currentAction->param = (void*) currentPath; //currentAction->param = currentAction->action(currentAction); } break; } } } if (ctrl.left && !old_ctrl.left) { //if(panelSelected!=PANEL_PROGRESS) panelSelected--; } if (ctrl.right && !old_ctrl.right) { //if(panelSelected!=PANEL_PROGRESS) panelSelected++; } // clamp ... CLAMP(entrySelected, 0, vEntry.size() - 1); CLAMP(actionSelected, 0, nbAction - 1); CLAMP(panelSelected, 0, 1); // Save the old value old_ctrl = ctrl; // Erase for the big loop memset(&ctrl, 0, sizeof (struct controller_data_s)); } }
int start_simulation(void) { cl_device_id *dev; cl_uint devc; cl_context context; cl_command_queue *cmd_queue; cl_mem src, dst, wdth, hght, *offy; cl_int err; cl_kernel kern; cl_program prog; cl_platform_id pform; size_t rows, columns, runs, print_each = 0, offsetx, offsety, *y, swapoffy; int gui_enabled, platform, device; unsigned int *buff0; unsigned int i; struct dispatcher_context *c; int random; char fname[1024]; cl_uint cqc; #if 1 do { printf("Width: "); scanf(SZTF, &columns); if (columns % 32) { printf("Width must be a multiple of 32\n"); continue; } if (columns == 0) { printf("Width must be > 0\n"); continue; } break; } while (true); do { printf("Height: "); scanf(SZTF, &rows); if (rows == 0) { printf("Width must be > 0\n"); continue; } break; } while (true); printf("Runs: "); scanf(SZTF, &runs); printf("Random? "); scanf("%d", &random); if (!random) { printf("File name: "); scanf("%s", fname); printf("Offset X: "); scanf(SZTF, &offsetx); printf("Offset Y: "); scanf(SZTF, &offsety); } printf("GUI? "); scanf("%d", &gui_enabled); if (!gui_enabled) { printf("Print after run: "); scanf(SZTF, &print_each); } printf("Platform index: "); scanf("%d", &platform); printf("Device index (-1 for all): "); scanf("%d", &device); do { printf("Swap offset: "); scanf(SZTF, &swapoffy); if (swapoffy == 0) swapoffy = rows; if (rows % swapoffy != 0) { printf("Swap offset must be a factor of the row count\n"); continue; } break; } while (true); #else columns = 512; rows = 512; runs = 1000; gui_enabled = 1; print_each = 0; random = 1; offsetx = 0; offsety = 0; platform = 0; device = 0; swapoffy = rows; #endif err = get_devices(&dev, &devc, &pform, platform, device); if (err) return err; err = initialize_context_cmd_queue(dev, devc, pform, &context, &cmd_queue, &cqc); if (err) return err; err = load_kernel(context, dev, devc, &prog, &kern); if (err) return err; buff0 = (unsigned int*)malloc(rows * (columns / 8)); if (!buff0) return -1; if (random) { srand((unsigned int)time(NULL)); for (i = 0; i < (rows * (columns / 8)) / 4; i++) { buff0[i] = rand() | (rand() << 16); } } else { memset(buff0, 0, rows * (columns / 8)); if (!load_file_to_buffer(buff0, fname, offsetx, offsety, columns, rows)) return -1; } err = compute_buffer_sizes(context, cmd_queue, cqc, kern, columns, rows, swapoffy, &y); if (err) return err; err = create_buffers(context, swapoffy * (columns / 8), columns, swapoffy, &src, &dst, &wdth, &hght, &offy, y, buff0, devc); if (err) return err; if (gui_enabled) { if (!initialize_window()) return -1; } c = (struct dispatcher_context *)malloc(sizeof(*c)); if (!c) return -1; c->cmd_queue = cmd_queue; c->cqc = cqc; c->kern = kern; c->columns = columns; c->rows = rows; c->print_each = print_each; c->runs = runs; c->gui_enabled = gui_enabled; c->buff0 = buff0; c->src = src; c->dst = dst; c->wdth = wdth; c->hght = hght; c->offy = offy; c->y = y; c->swapoffy = swapoffy; c->context = context; c->win_height = rows; return start_dispatcher(c); }
/// Returns the build log. std::string build_log() const { return get_build_info<std::string>(CL_PROGRAM_BUILD_LOG, get_devices().front()); }