static void init_cu2_devices(QSP_ARG_DECL Compute_Platform *cpp) { int n_devs,i; /* We don't get a proper error message if the cuda files in /dev * are not readable... So we check that first. */ check_file_access(QSP_ARG "/dev/nvidiactl"); cudaGetDeviceCount(&n_devs); if( n_devs == 0 ){ WARN("No CUDA devices found!?"); return; } if( verbose ){ sprintf(ERROR_STRING,"%d cuda devices found...",n_devs); advise(ERROR_STRING); } default_cuda_dev_name = getenv(DEFAULT_CUDA_ENV_VAR); /* may be null */ for(i=0;i<n_devs;i++){ char s[32]; sprintf(s,"/dev/nvidia%d",i); check_file_access(QSP_ARG s); init_cu2_device(QSP_ARG i, cpp); } if( default_cuda_dev_name == NULL ){ /* Not specified in environment */ // reserved var if set in environment? assign_var(QSP_ARG DEFAULT_CUDA_DEV_VAR,first_cuda_dev_name); default_cuda_dev_found=1; // not really necessary? } else if( ! default_cuda_dev_found ){ /* specified incorrectly */ sprintf(ERROR_STRING, "%s %s not found.\nUsing device %s.", DEFAULT_CUDA_DEV_VAR,default_cuda_dev_name, first_cuda_dev_name); WARN(ERROR_STRING); assign_var(QSP_ARG DEFAULT_CUDA_DEV_VAR,first_cuda_dev_name); default_cuda_dev_found=1; // not really necessary? } /* hopefully the vector library is already initialized - can we be sure? */ SET_PLATFORM_FUNCTIONS(cpp,cu2) SET_PF_FUNC_TBL(cpp,cu2_vfa_tbl); //SET_PLATFORM_DISPATCH_TBL(cpp,cu2_func_tbl); } // end init_cu2_devices
void atom(int &value) { int i; char temp[MAX_ID_LEN + 1]; switch (token_type) { case IDENTIFIER: i = internal_func(token); if (i != -1) { // Call "standard library" function. value = (*intern_func[i].p)(); } else if (find_func(token)) { // Call programmer-created function. call(); value = ret_value; } else { value = find_var(token); // get var's value strcpy(temp, token); // save variable name // Check for ++ or --. get_token(); if (*token == INC || *token == DEC) { if (*token == INC) assign_var(temp, find_var(temp) + 1); else assign_var(temp, find_var(temp) - 1); } else putback(); } get_token(); return; case NUMBER: // is numeric constant value = atoi(token); get_token(); return; case DELIMITER: // see if character constant if (*token == '\'') { value = *prog; prog++; if (*prog != '\'') throw InterpExc(QUOTE_EXPECTED); prog++; get_token(); return; } if (*token == ')') return; // process empty expression else throw InterpExc(SYNTAX); // otherwise, syntax error default: throw InterpExc(SYNTAX); // syntax error } }
static char *try_directory(QSP_ARG_DECL const char *dir,const char* progname) { FILE *fp; static char filename[MAXPATHLEN]; if( *dir ){ strcpy(filename,dir); strcat(filename,DIR_DELIM); } else strcpy(filename,""); strcat(filename,progname); strcat(filename,".scr"); fp=fopen(filename,"r"); if( fp!=NULL ) { redir(QSP_ARG fp, filename ); if( *dir ){ //sprintf(ERROR_STRING,"Setting %s to %s",STARTUP_DIRNAME,dir); //advise(ERROR_STRING); // We should only set the variable here if // it doesn't already exist - vars defined // in the environment are reserved! Variable *vp; vp = VAR_OF(STARTUP_DIRNAME); if( vp == NO_VARIABLE ){ assign_var(QSP_ARG STARTUP_DIRNAME,dir); } } return(filename); } else { return(NULL); } }
/* Process an assignment expression */ void eval_exp0(int *value) { char temp[ID_LEN]; /* holds name of var receiving the assignment */ register int temp_tok; if(token_type==IDENTIFIER) { if(is_var(token)) { /* if a var, see if assignment */ strcpy(temp, token); temp_tok = token_type; get_token(); if(*token=='=') { /* is an assignment */ get_token(); eval_exp0(value); /* get value to assign */ assign_var(temp, *value); /* assign the value */ return; } else { /* not an assignment */ putback(); /* restore original token */ strcpy(token, temp); token_type = temp_tok; } } } eval_exp1(value); }
static char *_try_directory(QSP_ARG_DECL const char *dir,const char* progname) { FILE *fp; static char filename[MAXPATHLEN]; if( *dir ){ strcpy(filename,dir); strcat(filename,DIR_DELIM); } else strcpy(filename,""); strcat(filename,progname); strcat(filename,".scr"); fp=fopen(filename,"r"); if( fp!=NULL ) { redir(fp, filename ); if( *dir ){ // We should only set the variable here if // it doesn't already exist - vars defined // in the environment are reserved! Variable *vp; vp = var_of(STARTUP_DIRNAME); if( vp == NULL ){ assign_var(STARTUP_DIRNAME,dir); } } return(filename); } else { return(NULL); } }
void eval_exp0(int &value) { char temp[MAX_ID_LEN + 1]; tok_types temp_tok; if (token_type == IDENTIFIER) { if (is_var(token)) { strcpy(temp, token); temp_tok = token_type; get_token(); if (*token == '=') { get_token(); eval_exp0(value); assign_var(temp, value); return; } else { putback(); strcpy(token, temp); token_type = temp_tok; } } } eval_exp1(value); }
static COMMAND_FUNC( do_tellprec ) { Data_Obj *dp; const char *s; dp = get_obj( QSP_ARG NAMEOF("data object") ); s = NAMEOF("variable name"); if( dp == NULL ) return; assign_var(s,OBJ_PREC_NAME(dp)); }
static COMMAND_FUNC( do_get_area ) { const char *s; s=NAMEOF("script variable for area name"); assert( curr_ap != NULL ); assign_var(s, AREA_NAME(curr_ap)); }
Data_Obj * grab_newest_firewire_frame( QSP_ARG_DECL PGR_Cam * pgcp ) { dc1394video_frame_t *framep, *prev_framep=NULL; //int i=0; int n_dequeued=0; if( ! ready_to_grab( QSP_ARG pgcp ) ) return NULL; // We might want to release all of the frames we have now, in case we // need to automatically release any that we grab in the meantime, // so that we release in order... // We get the newest by dequeueing in POLL mode, until we come up empty. // If we have at least one frame at that time, then that's the frame. // If we don't have any, then we WAIT. If at any time we have // more than 1, then we release the older. while( 1 ){ if ( dc1394_capture_dequeue( pgcp->pc_cam_p, DC1394_CAPTURE_POLICY_POLL, &framep ) != DC1394_SUCCESS) { fprintf( stderr, "Unable to capture a frame\n" ); return(NULL); } if( framep == NULL ){ // No frame to fetch? if( n_dequeued > 0 ){ // already have something? // The last one is the newest! sprintf(msg_str,"%d",prev_framep->id); assign_var("newest",msg_str); note_frame_usage(pgcp,prev_framep); return dobj_for_frame(QSP_ARG prev_framep); } else { // No frames yet... // We don't want to call the WAIT version here, because // we might have multiple cameras... return NULL; } } else { // We have a new frame if( prev_framep != NULL ){ // already have one? if( dc1394_capture_enqueue(pgcp->pc_cam_p,prev_framep) != DC1394_SUCCESS ){ WARN("error enqueueing frame"); } } else { // This counts the frame we dequeued. // We don't bother if we just enqueued // the previous one. pgcp->pc_n_avail--; } prev_framep = framep; n_dequeued++; } } // NOTREACHED }
// Is a unary +, -, ++, or --. void eval_exp4(int &value) { char op; char temp; op = '\0'; if (*token == '+' || *token == '-' || *token == INC || *token == DEC) { temp = *token; op = *token; get_token(); if (temp == INC) assign_var(token, find_var(token) + 1); if (temp == DEC) assign_var(token, find_var(token) - 1); } eval_exp5(value); if (op == '-') value = -(value); }
void assign_polh_var_data(char *varname, Data_Obj *dp, Polh_Output_Type type, int index ) { short *rpdp; Fmt_Pt fp1; Polh_Record_Format *prfp; char str[64]; char *s,*s2; int i; if( OBJ_COLS(dp) != 1 ){ sprintf(ERROR_STRING,"assign_polh_var_data: object %s has %d columns, should be 1", OBJ_NAME(dp),OBJ_COLS(dp)); warn(ERROR_STRING); return; } rpdp = (short *) OBJ_DATA_PTR(dp); prfp = &station_info[curr_station_idx].sd_multi_prf; format_polh_data(&fp1,rpdp,prfp); separator=""; /* no leading tab before the first record */ if( fmt_one(msg_str,&fp1,type) < 0 ) return; s=msg_str; i=index; while(i--){ while( *s!=0 && !isspace(*s) ) s++; /* skip data */ while( *s!=0 && isspace(*s) ) s++; /* skip spaces */ } #ifdef CAUTIOUS if( *s == 0 ){ sprintf(ERROR_STRING,"CAUTIOUS: assign_polh_var_data: not enough words for index %d", index); warn(ERROR_STRING); sprintf(ERROR_STRING,"formatted string: %s",msg_str); advise(ERROR_STRING); return; } #endif /* CAUTIOUS */ /* we have to do this check in case index is zero, so the check for leading spaces hasn't been * performed above. This is an issue with milliseconds, where a leading space may appear * in the string for values less than 100. */ while( *s!=0 && isspace(*s) ) s++; /* skip any leading spaces */ s2 = str; while( *s != 0 && !isspace(*s) ) *s2++ = *s++; *s2=0; /* BUG should check for overflow */ assign_var(varname,str); } /* end assign_polh_var_data */
static int read_next_record(QSP_ARG_DECL void * raw_pdp, int station ) { char data_string[6][32]; int i; int c, expect_c; fprintf(stderr,"read_next_record 0x%lx\n",(long)raw_pdp); /* read any leading spaces */ do { c=good_polh_char(); } while( isspace(c) ); while( c != '0' ){ sprintf(ERROR_STRING, "read 0x%x, expected '0' in first header position",c); warn(ERROR_STRING); c=good_polh_char(); } c=good_polh_char(); expect_c = '1' + curr_station_idx; while( c != expect_c ){ sprintf(ERROR_STRING, "read '%c' (0x%x), expected '%c' in second header position", c,c,expect_c); warn(ERROR_STRING); c=good_polh_char(); } c=good_polh_char(); if( c != 'D' && c != 'Y' ){ sprintf(ERROR_STRING, "read '%c' (0x%x), expected 'D' or 'Y' in third header position",c,c); //warn(ERROR_STRING); advise(ERROR_STRING); c=good_polh_char(); sprintf(ERROR_STRING, "read '%c' (0x%x) after unexpected character",c,c); //warn(ERROR_STRING); advise(ERROR_STRING); } /* BUG don't assume 6 data - use format? */ for(i=0;i<6;i++){ read_data_string(data_string[i]); // advise(data_string[i]); /* raw_pdp doesn't indicate the format? */ } // BUG how do we know that these are the data that were requested??? assign_var("polh_x_pos",data_string[0]); assign_var("polh_y_pos",data_string[1]); assign_var("polh_z_pos",data_string[2]); assign_var("polh_x_rot",data_string[3]); assign_var("polh_y_rot",data_string[4]); assign_var("polh_z_rot",data_string[5]); return(0); }
static COMMAND_FUNC( do_readpipe ) { Pipe *pp; const char *s; pp=pick_pipe(""); s=NAMEOF("variable for text storage"); if( pp == NULL ) { assign_var(s,"error_missing_pipe"); return; } readfr_pipe(QSP_ARG pp,s); }
/* Обработка выражения в присваивании */ void eval_exp0(int *value) { char temp[ID_LEN]; /* содержит имя переменной, которой присваивается значение */ register int temp_tok; if(token_type == IDENTIFIER) { if(is_var(token)) { /* если эта переменная, посмотреть, присваивается ли ей значение */ if(is_arr(token)) { sntx_err(SYNTAX); // todo: make message: redefinition of array is illegal } strcpy(temp, token); temp_tok = token_type; get_token(); if(*token == '=') { /* это присваивание */ get_token(); eval_exp0(value); /* вычислить присваемое значение */ assign_var(temp, *value); /* присвоить значение */ return; } else { /* не присваивание */ putback(); /* востановление лексемы */ strcpy(token, temp); token_type = temp_tok; } } else if(is_arr(token)) { strcpy(temp, token); temp_tok = token_type; get_token(); if(*token == '[') { get_token(); eval_exp0(value); // вычисление выражения в [] скобках int arr_index = *value; get_token(); // '=' or ';' if(*token == '=') { /* это присваивание */ get_token(); eval_exp0(value); /* вычислить присваемое значение */ assign_arr_element(temp, arr_index, *value); /* присвоить значение */ return; } else { /* не присваивание */ putback(); /* востановление лексемы */ strcpy(token, temp); token_type = temp_tok; } } else { sntx_err(ASSIGN_ARRAY_ILLEGAL); } } } eval_exp1(value); }
static COMMAND_FUNC( do_tell_dpy ) { Disp_Obj *dop; const char *s; s=NAMEOF("name of variable in which to deposit name of current display"); dop = curr_dop(); if( dop == NULL ){ WARN("do_tell_dpy: no current display!?"); return; } assign_var(s,DO_NAME(dop)); }
static COMMAND_FUNC(do_fetch_chunk) { Chunk_Data *cd_p; Data_Obj *dp; const char *s; char buf[64]; s = nameof("variable name"); cd_p = pick_chunk_data(""); dp = pick_obj("camera buffer"); if( cd_p == NULL || dp == NULL ) return; fetch_chunk_data(cd_p,dp); //display_chunk_data(cd_p); format_chunk_data(buf,cd_p); assign_var(s,buf); }
void read_input(int mode, char *batch_path) { char c; int current_length = (BUFFER_SIZE + 1); line = (char *) malloc(sizeof(char) * (BUFFER_SIZE + 1)); char *path = (char *) malloc(sizeof(char) * (BUFFER_SIZE + 1)); fflush(stderr); printf("\n[SHELL ] "); fflush(stdout); int run = 1, len = 0; if (mode == BATCH) { if (open(batch_path, O_RDONLY) > 0) { batch_file = fopen(batch_path, "r"); } else { fprintf(stderr, "cann't open or read the file\n"); return; } } while (c != EOF && run) { if (mode == INTERACTIVE) c = getchar(); else { c = fgetc(batch_file); if (feof(stdin)) { run = 0; break; } } switch (c) { case '\n': if (line[0] == '\0') { len = 0; free_args(); bzero(line, current_length); fflush(stderr); printf("\n[SHELL ] "); fflush(stdout); } else { if (mode == BATCH) { printf("%s\n", line); } if (len >= BUFFER_SIZE) { fprintf(stderr, "buffer limit excited\n"); bzero(line, current_length); len = 0; continue; } add_to_history(line); free_args(); fill_argv(line); if (is_comment(line) == 0) { if (strchr(line, '=') != NULL && strcmp(args[0], "echo") != 0) { assign_var(line); } else { // free_args(); // fill_argv(line); if (strcmp(args[0], "echo") != 0) { int i; for (i = 0; args[i] != NULL; i++) { append_home_dir(args[i]); fix_echo_line(args[i]); } } else { int i; for (i = 1; args[i] != NULL; i++) { fix_echo_line(args[i]); } } if (strcmp("exit", line) == 0) { run = 0; break; } else if (strcmp("history", args[0]) == 0) { execute_history(); } else if (strcmp("cd", args[0]) == 0) cd(); else { strcpy(path, args[0]); if (strchr(path, '/') != NULL) { int fd; if ((fd = open(path, O_RDONLY)) > 0) { close(fd); call_execve(path); } else { fprintf(stderr, "%s: No such file or directory\n", args[0]); } } else { if (!is_command(path)) { fprintf(stderr, "%s: command not found\n", args[0]); } else { call_execve(path); } } } } } free_args(); fflush(stderr); printf("\n[SHELL ] "); fflush(stdout); bzero(line, BUFFER_SIZE); len = 0; } bzero(line, BUFFER_SIZE); break; default: len++; if (len < BUFFER_SIZE) { strncat(line, &c, 1); } break; } } if (mode == BATCH) fclose(batch_file); }
int start_firewire_transmission(QSP_ARG_DECL PGR_Cam * pgcp, int _ring_buffer_size ) { int i; dc1394error_t err; Data_Obj *dp; //advise("start_firewire_transmission BEGIN"); /* older version had third flags arg... */ //advise("calling dc1394_capture_setup"); if( (err=dc1394_capture_setup(pgcp->pc_cam_p,_ring_buffer_size ,DC1394_CAPTURE_FLAGS_DEFAULT )) != DC1394_SUCCESS ) { WARN("dc1394_capture_setup failed!?"); describe_dc1394_error( QSP_ARG err ); if( err == DC1394_IOCTL_FAILURE ){ advise("Try decreasing the number of ring buffer frames requested?"); return -1; } fprintf( stderr,"unable to setup camera-\n" "check line %d of %s to make sure\n" "that the video mode and framerate are\n" "supported by your camera\n", __LINE__,__FILE__ ); /* fprintf( stderr, "video_mode = %d, framerate = %d\n" "Check dc1394_control.h for the meanings of these values\n", pgcp->pc_video_mode, pgcp->pc_framerate ); */ fprintf( stderr, "video_mode = %s (%d), framerate = %s (%d)\n", name_for_video_mode(pgcp->pc_video_mode), pgcp->pc_video_mode, name_for_framerate(pgcp->pc_framerate), pgcp->pc_framerate ); NERROR1("error starting capture"); return(-1); } pgcp->pc_ring_buffer_size = _ring_buffer_size; pgcp->pc_n_avail = _ring_buffer_size; pgcp->pc_flags |= PGR_CAM_IS_CAPTURING; #ifdef FOOBAR // we set this in the script already!? sprintf(msg_str,"%d",ring_buffer_size); /* tell the scripting language */ assign_var("ring_buffer_size",msg_str); #endif // FOOBAR // have the camera start sending us data //advise("calling dc1394_video_set_transmission"); if( (err=dc1394_video_set_transmission( pgcp->pc_cam_p, DC1394_ON )) != DC1394_SUCCESS ) { WARN("Unable to start camera iso transmission"); describe_dc1394_error( QSP_ARG err ); // do we need to undo capture_setup? dc1394_capture_stop( pgcp->pc_cam_p ); pgcp->pc_flags &= ~PGR_CAM_IS_CAPTURING; return(-1); } pgcp->pc_flags |= PGR_CAM_IS_TRANSMITTING; // Sleep untill the camera has a transmission dc1394switch_t status = DC1394_OFF; for ( i = 0; i <= 5; i++ ) { usleep(50000); //advise("calling dc1394_video_get_transmission"); if ( dc1394_video_get_transmission( pgcp->pc_cam_p, &status ) != DC1394_SUCCESS ) { fprintf( stderr, "Unable to get transmision status\n" ); return(-1); } if ( status != DC1394_OFF ) break; if( i == 5 ) { fprintf(stderr,"Camera doesn't seem to want to turn on!\n"); return(-1); } } //advise("start_firewire_transmission DONE"); // Now make sure that we have the frame objects... dp = dobj_of("_frame1"); if( dp == NULL ) init_buffer_objects(QSP_ARG pgcp); return(0); }
static void init_cu2_device(QSP_ARG_DECL int index, Compute_Platform *cpp) { struct cudaDeviceProp deviceProp; cudaError_t e; Platform_Device *pdp; char name[LLEN]; char dev_name[LLEN]; char area_name[LLEN]; const char *name_p; char *s; Data_Area *ap; float comp_cap; if( index >= MAX_CUDA_DEVICES ){ sprintf(ERROR_STRING,"Program is compiled for a maximum of %d CUDA devices, can't inititialize device %d.", MAX_CUDA_DEVICES,index); ERROR1(ERROR_STRING); } if( verbose ){ sprintf(ERROR_STRING,"init_cu2_device %d BEGIN",index); advise(ERROR_STRING); } if( (e=cudaGetDeviceProperties(&deviceProp, index)) != cudaSuccess ){ describe_cuda_driver_error2("init_cu2_device","cudaGetDeviceProperties",e); return; } if (deviceProp.major == 9999 && deviceProp.minor == 9999){ sprintf(ERROR_STRING,"There is no CUDA device with dev = %d!?.\n",index); WARN(ERROR_STRING); /* What should we do here??? */ return; } /* Put the compute capability into a script variable so that we can use it */ comp_cap = deviceProp.major * 10 + deviceProp.minor; if( comp_cap > CUDA_COMP_CAP ){ sprintf(ERROR_STRING,"init_cu2_device: CUDA device %s has compute capability %d.%d, but program was configured for %d.%d!?", deviceProp.name,deviceProp.major,deviceProp.minor, CUDA_COMP_CAP/10,CUDA_COMP_CAP%10); WARN(ERROR_STRING); } /* BUG if there are multiple devices, we need to make sure that this is set * correctly for the current context!? */ sprintf(ERROR_STRING,"%d.%d",deviceProp.major,deviceProp.minor); assign_var(QSP_ARG "cuda_comp_cap",ERROR_STRING); /* What does this do??? */ e = cudaSetDeviceFlags( cudaDeviceMapHost ); if( e != cudaSuccess ){ describe_cuda_driver_error2("init_cu2_device", "cudaSetDeviceFlags",e); } strcpy(name,deviceProp.name); /* change spaces to underscores */ s=name; while(*s){ if( *s==' ' ) *s='_'; s++; } /* We might have two of the same devices installed in a single system. * In this case, we can't use the device name twice, because there will * be a conflict. The first one gets the name, then we have to check and * make sure that the name is not in use already. If it is, then we append * a number to the string... */ name_p = available_pfdev_name(QSP_ARG name,dev_name,cpp,MAX_CUDA_DEVICES); // reuse name as scratch string pdp = new_pfdev(QSP_ARG name_p); #ifdef CAUTIOUS if( pdp == NO_PFDEV ){ sprintf(ERROR_STRING,"CAUTIOUS: init_cu2_device: Error creating cuda device struct for %s!?",name_p); WARN(ERROR_STRING); return; } #endif /* CAUTIOUS */ /* Remember this name in case the default is not found */ if( first_cuda_dev_name == NULL ) first_cuda_dev_name = PFDEV_NAME(pdp); /* Compare this name against the default name set in * the environment, if it exists... */ if( default_cuda_dev_name != NULL && ! default_cuda_dev_found ){ if( !strcmp(PFDEV_NAME(pdp),default_cuda_dev_name) ) default_cuda_dev_found=1; } SET_PFDEV_PLATFORM(pdp,cpp); SET_PFDEV_CUDA_INFO( pdp, getbuf(sizeof(Cuda_Dev_Info)) ); SET_PFDEV_CUDA_DEV_INDEX(pdp,index); SET_PFDEV_CUDA_DEV_PROP(pdp,deviceProp); SET_PFDEV_CUDA_RNGEN(pdp,NULL); if( comp_cap >= 20 ){ SET_PFDEV_MAX_DIMS(pdp,3); } else { SET_PFDEV_MAX_DIMS(pdp,2); } //set_cuda_device(pdp); // is this call just so we can call cudaMalloc? PF_FUNC_NAME(set_device)(QSP_ARG pdp); // is this call just so we can call cudaMalloc? // address set to NULL says use custom allocator - see dobj/makedobj.c // BUG?? with pdp we may not need the DA_ flag??? sprintf(area_name,"%s.%s",PLATFORM_NAME(cpp),name_p); ap = pf_area_init(QSP_ARG area_name,NULL,0, MAX_CUDA_GLOBAL_OBJECTS,DA_CUDA_GLOBAL,pdp); if( ap == NO_AREA ){ sprintf(ERROR_STRING, "init_cu2_device: error creating global data area %s",area_name); WARN(ERROR_STRING); } // g++ won't take this line!? SET_AREA_CUDA_DEV(ap,pdp); //set_device_for_area(ap,pdp); SET_PFDEV_AREA(pdp,PFDEV_GLOBAL_AREA_INDEX,ap); /* We used to declare a heap for constant memory here, * but there wasn't much of a point because: * Constant memory can't be allocated, rather it is declared * in the .cu code, and placed by the compiler as it sees fit. * To have objects use this, we would have to declare a heap and * manage it ourselves... * There's only 64k, so we should be sparing... * We'll try this later... */ /* Make up another area for the host memory * which is locked and mappable to the device. * We don't allocate a pool here, but do it as needed... */ //strcpy(area_name,name_p); //strcat(area_name,"_host"); sprintf(area_name,"%s.%s_host",PLATFORM_NAME(cpp),name_p); ap = pf_area_init(QSP_ARG area_name,(u_char *)NULL,0,MAX_CUDA_MAPPED_OBJECTS, DA_CUDA_HOST,pdp); if( ap == NO_AREA ){ sprintf(ERROR_STRING, "init_cu2_device: error creating host data area %s",area_name); ERROR1(ERROR_STRING); } SET_AREA_CUDA_DEV(ap, pdp); //cuda_data_area[index][CUDA_HOST_AREA_INDEX] = ap; SET_PFDEV_AREA(pdp,PFDEV_HOST_AREA_INDEX,ap); /* Make up another psuedo-area for the mapped host memory; * This is the same memory as above, but mapped to the device. * In the current implementation, we create objects in the host * area, and then automatically create an alias on the device side. * There is a BUG in that by having this psuedo area in the data * area name space, a user could select it as the data area and * then try to create an object. We will detect this in make_dobj, * and complain. */ //strcpy(area_name,name_p); //strcat(area_name,"_host_mapped"); sprintf(area_name,"%s.%s_host_mapped",PLATFORM_NAME(cpp),name_p); ap = pf_area_init(QSP_ARG area_name,(u_char *)NULL,0,MAX_CUDA_MAPPED_OBJECTS, DA_CUDA_HOST_MAPPED,pdp); if( ap == NO_AREA ){ sprintf(ERROR_STRING, "init_cu2_device: error creating host-mapped data area %s",area_name); ERROR1(ERROR_STRING); } SET_AREA_CUDA_DEV(ap,pdp); //cuda_data_area[index][CUDA_HOST_MAPPED_AREA_INDEX] = ap; SET_PFDEV_AREA(pdp,PFDEV_HOST_MAPPED_AREA_INDEX,ap); // We don't change the data area by default any more when initializing... /* Restore the normal area */ //set_data_area(PFDEV_AREA(pdp,PFDEV_GLOBAL_AREA_INDEX)); if( verbose ){ sprintf(ERROR_STRING,"init_cu2_device %d DONE",index); advise(ERROR_STRING); } }
int default_stim(QSP_ARG_DECL Trial_Class *tc_p,int val,Staircase *stc_p) { char stim_str[256], *s; int coin=0; // initialize to quiet compiler, but not necessary!? int rsp; //struct var *vp; Variable *vp; float *xv_p; if( is_fc ){ coin=(int)rn(1); sprintf(stim_str,"%d",coin); assign_var("coin",stim_str); } assert( CLASS_XVAL_OBJ(tc_p) != NULL ); xv_p = indexed_data( CLASS_XVAL_OBJ(tc_p), val ); sprintf(stim_str,"%f",*xv_p); /* clip trailing zeros if there is a decimal point */ s=stim_str; while( *s ){ if( *s == '.' ){ s=stim_str+strlen(stim_str)-1; while( *s == '0' ) { *s=0; s--; } /* * if ONLY 0's after the decimal pt., * remove the pt too! */ if( *s == '.' ){ *s=0; s--; } } s++; } assign_var("xval",stim_str); sprintf(stim_str,"%d",val); assign_var("val",stim_str); sprintf(stim_str,"%d",CLASS_INDEX(tc_p)); assign_var("class",stim_str); assert( tc_p != NULL ); //sprintf(msg_str,"Text \"%s\"",(char *)(tc_p->cl_data)); //PUSH_INPUT_FILE(msg_str); //interpret_text_fragment(QSP_ARG tc_p->cl_data); /* use chew_text??? */ chew_text(CLASS_CMD(tc_p), "(stimulus text)"); vp=var_of("response_string"); if( vp != NULL ) rsp = collect_response(VAR_VALUE(vp)); else { static int warned=0; if( !warned ){ warn("default_stim: script variable $response_string not defined"); warned=1; } rsp = collect_response("Enter response: "); } if( is_fc ){ /* stimulus routine may have changed value of coin */ vp=var_of("coin"); if( vp == NULL ) warn("variable \"coin\" not set!!!"); else { if( sscanf(VAR_VALUE(vp),"%d",&coin) != 1 ) warn("error scanning integer from variable \"coin\"\n"); } /* if( coin ){ if( rsp == YES ) rsp = NO; else if( rsp == NO ) rsp = YES; } */ assert( stc_p != NULL ); // analyzer complains coin is a garbage value??? BUG? if( coin ){ SET_STAIR_CRCT_RSP(stc_p,NO); } else { SET_STAIR_CRCT_RSP(stc_p,YES); } if( verbose ){ if( rsp == STAIR_CRCT_RSP(stc_p) ) advise("correct"); else advise("incorrect"); } } return(rsp); }