int main(int argc, char *argv[]) { size_t size = 1000; if(argc >= 2){ size = boost::lexical_cast<size_t>(argv[1]); } std::cout << "size: " << size << std::endl; // setup context and queue for the default device boost::compute::device device = boost::compute::system::default_device(); boost::compute::context context(device); boost::compute::command_queue queue(context, device); // create vector of random numbers on the host std::vector<float> host_x(size); std::vector<float> host_y(size); std::generate(host_x.begin(), host_x.end(), rand_float); std::generate(host_y.begin(), host_y.end(), rand_float); // create vector on the device and copy the data boost::compute::vector<float> device_x(host_x.begin(), host_x.end(), context); boost::compute::vector<float> device_y(host_y.begin(), host_y.end(), context); boost::compute::detail::timer t; boost::compute::blas::axpy(static_cast<int>(size), 2.5f, &device_x[0], 1, &device_y[0], 1, queue); queue.finish(); std::cout << "time: " << t.elapsed() << " ms" << std::endl; // perform saxpy on host serial_saxpy(size, 2.5f, &host_x[0], &host_y[0]); // copy device_y to host_x boost::compute::copy(device_y.begin(), device_y.end(), host_x.begin(), queue); for(size_t i = 0; i < size; i++){ float host_value = host_y[i]; float device_value = host_x[i]; if(std::abs(device_value - host_value) > 1e-3){ std::cout << "ERROR: " << "value at " << i << " " << "device_value (" << device_value << ") " << "!= " << "host_value (" << host_value << ")" << std::endl; return -1; } } return 0; }
void g_set_rubbercursor(int win_id, int vp_id, float x, float y, int type) { int local_id, cursor_hidden=FALSE; int dx, dy, x1, y1, x2, y2; local_id = GET_LOCAL_ID(win_id); if (local_id < 0 || local_id >= G_MAXWINDOW) return; if ( !(CURTYPE(local_id) == G_CURSOR_CROSSHAIR || CURTYPE(local_id) == G_CURSOR_UPDOWN) && ! xwini[local_id].xlib_pixcopymode) return; if (!xwini[local_id].xx_hidden) { INTERNAL_hide_crosshair(local_id); cursor_hidden = TRUE; } dx = device_x(local_id, vp_id, x); dy = device_y(local_id, vp_id, y); exit_pixtemp(local_id, vp_id, dx, dy); switch (type) { case G_RUBBER_NONE: xwini[local_id].xx_draw_cursor_func = xx_default_cursor_func; INTERNAL_cursortype(local_id, save_old_cursortype); return; case G_RUBBER_CROSSHAIR: xwini[local_id].xx_draw_cursor_func = xx_default_cursor_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_DOUBLECROSS: rbx = dx; rby = dy; xwini[local_id].xx_draw_cursor_func = xx_doublecross_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_XHAIR: rbx = dx; xwini[local_id].xx_draw_cursor_func = xx_xline_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_YHAIR: rby = dy; xwini[local_id].xx_draw_cursor_func = xx_yline_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX: rbx = dx; rby = dy; xwini[local_id].xx_draw_cursor_func = xx_rubberbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_LINE: rbx = dx; rby = dy; xwini[local_id].xx_draw_cursor_func = xx_rubberline_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX_BL: rbx = dx; rby = dy; bltr = BL; xwini[local_id].xx_draw_cursor_func = xx_staticbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX_BR: rbx = dx; rby = dy; bltr = BR; xwini[local_id].xx_draw_cursor_func = xx_staticbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX_TL: rbx = dx; rby = dy; bltr = TL; xwini[local_id].xx_draw_cursor_func = xx_staticbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX_TR: rbx = dx; rby = dy; bltr = TR; xwini[local_id].xx_draw_cursor_func = xx_staticbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_PANNER: case G_RUBBER_PANNER_BORDER: if (vp_id != G_ERROR) { INTERNAL_calc_viewport_rect(win_id, vp_id, &x1,&y1,&x2,&y2); if (type == G_RUBBER_PANNER_BORDER) init_pixtemp(local_id, vp_id, dx, dy, x1+1, y1+1, x2-1, y2-1); else init_pixtemp(local_id, vp_id, dx, dy, x1, y1, x2, y2); xwini[local_id].xx_draw_cursor_func = copy_pixtemp; } else xwini[local_id].xx_draw_cursor_func = xx_dummy_func; INTERNAL_cursortype(local_id, G_CURSOR_HAND); break; } if (cursor_hidden && !(CURTYPE(local_id) == G_CURSOR_HAND || CURTYPE(local_id) == G_CURSOR_UPDOWN)) { INTERNAL_show_crosshair(local_id, xwini[local_id].xlib_marker_x, xwini[local_id].xlib_marker_y); } }
void g_set_rubbercursor(int win_id, int vp_id, float x, float y, int type) { int local_id, cursor_hidden = FALSE; int dx, dy, x1, y1, x2, y2; local_id = GET_LOCAL_ID(win_id); if (local_id < 0 || local_id >= G_MAXWINDOW) return; if (!(WI[local_id].cursortype == G_CURSOR_CROSSHAIR || WI[local_id].cursortype == G_CURSOR_UPDOWN) && ! WI[local_id].pixcopymode) return; if (!WI[local_id].cursorhidden) { mswin_hide_crosshair(local_id); cursor_hidden = TRUE; } dx = device_x(local_id, vp_id, x); dy = device_y(local_id, vp_id, y); exit_pixtemp(local_id, vp_id, dx, dy); switch (type) { case G_RUBBER_NONE: mswin_draw_cursor_func[local_id] = mswin_default_cursor_func; INTERNAL_cursortype(local_id, save_old_cursortype); return; case G_RUBBER_CROSSHAIR: mswin_draw_cursor_func[local_id] = mswin_default_cursor_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_DOUBLECROSS: WI[local_id].rbx = dx; WI[local_id].rby = dy; mswin_draw_cursor_func[local_id] = mswin_doublecross_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_XHAIR: WI[local_id].rbx = dx; mswin_draw_cursor_func[local_id] = mswin_xline_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_YHAIR: WI[local_id].rby = dy; mswin_draw_cursor_func[local_id] = mswin_yline_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX: WI[local_id].rbx = device_x(local_id, vp_id, x); WI[local_id].rby = device_y(local_id, vp_id, y); mswin_draw_cursor_func[local_id] = mswin_rubberbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_LINE: WI[local_id].rbx = device_x(local_id, vp_id, x); WI[local_id].rby = device_y(local_id, vp_id, y); mswin_draw_cursor_func[local_id] = mswin_rubberline_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX_BL: WI[local_id].rbx = device_x(local_id, vp_id, x); WI[local_id].rby = device_y(local_id, vp_id, y); WI[local_id].bltr = BL; mswin_draw_cursor_func[local_id] = mswin_staticbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX_BR: WI[local_id].rbx = device_x(local_id, vp_id, x); WI[local_id].rby = device_y(local_id, vp_id, y); WI[local_id].bltr = BR; mswin_draw_cursor_func[local_id] = mswin_staticbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX_TL: WI[local_id].rbx = device_x(local_id, vp_id, x); WI[local_id].rby = device_y(local_id, vp_id, y); WI[local_id].bltr = TL; mswin_draw_cursor_func[local_id] = mswin_staticbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_BOX_TR: WI[local_id].rbx = device_x(local_id, vp_id, x); WI[local_id].rby = device_y(local_id, vp_id, y); WI[local_id].bltr = TR; mswin_draw_cursor_func[local_id] = mswin_staticbox_func; INTERNAL_cursortype(local_id, G_CURSOR_CROSSHAIR); break; case G_RUBBER_PANNER: case G_RUBBER_PANNER_BORDER: if (vp_id != G_ERROR) { INTERNAL_calc_viewport_rect(win_id, vp_id, &x1, &y1, &x2, &y2); if (type == G_RUBBER_PANNER_BORDER) init_pixtemp(local_id, vp_id, dx, dy, x1 + 1, y1 + 1, x2 - 1, y2 - 1); else init_pixtemp(local_id, vp_id, dx, dy, x1, y1, x2, y2); mswin_draw_cursor_func[local_id] = copy_pixtemp; } else mswin_draw_cursor_func[local_id] = mswin_dummy_func; INTERNAL_cursortype(local_id, G_CURSOR_HAND); break; } if (cursor_hidden && WI[local_id].cursortype != G_CURSOR_HAND && WI[local_id].cursortype != G_CURSOR_UPDOWN) { mswin_show_crosshair(local_id, WI[local_id].cursorx, WI[local_id].cursory); } }