void cu2_init_platform(SINGLE_QSP_ARG_DECL) { static int inited=0; if( inited ){ //WARN("Redundant call to cu2_init_platform!?"); advise("Redundant call to cu2_init_platform!?"); return; } inited=1; #ifdef HAVE_CUDA Compute_Platform *cpp; cpp = creat_platform(QSP_ARG "CUDA", PLATFORM_CUDA ); //init_platform(QSP_ARG cpp, PLATFORM_CUDA); #ifdef CAUTIOUS if( cpp == NULL ) ERROR1("CAUTIOUS: cu2_init_platform: Couldn't create Cuda2 platform!?"); #endif // CAUTIOUS push_pfdev_context(QSP_ARG PF_CONTEXT(cpp) ); init_cu2_devices(QSP_ARG cpp); if( pop_pfdev_context(SINGLE_QSP_ARG) == NO_ITEM_CONTEXT ) ERROR1("cu2_init_platform: Failed to pop platform device context!?"); check_vfa_tbl(QSP_ARG cu2_vfa_tbl, N_VEC_FUNCS); #else // ! HAVE_CUDA WARN("Sorry, no CUDA support in this build."); #endif // ! HAVE_CUDA } // cu2_init_platform
void vl2_init_platform(SINGLE_QSP_ARG_DECL) { Compute_Platform *cpp; static int inited=0; if( inited ){ /* As long as we have not completely replaced the * previous veclib, we can call this from vl2 or veclib... */ return; } cpp = creat_platform(QSP_ARG "CPU", PLATFORM_CPU ); SET_PLATFORM_FUNCTIONS(cpp,vl2) SET_PF_FUNC_TBL(cpp,vl2_vfa_tbl); push_pfdev_context(QSP_ARG PF_CONTEXT(cpp) ); init_vl2_pfdevs(QSP_ARG cpp); if( pop_pfdev_context(SINGLE_QSP_ARG) == NO_ITEM_CONTEXT ) ERROR1("init_ocl_platform: Failed to pop platform device context!?"); check_vl2_vfa_tbl(SINGLE_QSP_ARG); inited=1; }
static void init_ocl_platform(QSP_ARG_DECL cl_platform_id platform_id) { Compute_Platform *cpp; cl_int status; //char param_data[MAX_PARAM_SIZE]; char *platform_str; size_t ret_size; GET_PLATFORM_STRING(CL_PLATFORM_NAME) cpp = creat_platform(QSP_ARG platform_str, PLATFORM_OPENCL); givbuf(platform_str); GET_PLATFORM_STRING(CL_PLATFORM_PROFILE) SET_OCLPF_PROFILE(cpp,platform_str); GET_PLATFORM_STRING(CL_PLATFORM_VERSION) SET_OCLPF_VERSION(cpp,platform_str); GET_PLATFORM_STRING(CL_PLATFORM_VENDOR) SET_OCLPF_VENDOR(cpp,platform_str); GET_PLATFORM_STRING(CL_PLATFORM_EXTENSIONS) SET_OCLPF_EXTENSIONS(cpp,platform_str); SET_OCLPF_ID(cpp,platform_id); SET_PLATFORM_FUNCTIONS(cpp,ocl) SET_PF_FUNC_TBL(cpp,ocl_vfa_tbl); // BUG need to set vfa_tbl here too! //icp = create_item_context(QSP_ARG pfdev_itp, PLATFORM_NAME(cpp) ); //push_item_context(QSP_ARG pfdev_itp, icp ); push_pfdev_context(QSP_ARG PF_CONTEXT(cpp) ); init_ocl_devices(QSP_ARG cpp); if( pop_pfdev_context(SINGLE_QSP_ARG) == NULL ) error1("init_ocl_platform: Failed to pop platform device context!?"); }
static COMMAND_FUNC( do_new_gl_buffer ) { const char *s; Data_Obj *dp; Platform_Device *pdp; Compute_Platform *cdp; dimension_t d,w,h; #ifdef HAVE_OPENGL Dimension_Set ds; int t; #endif // HAVE_OPENGL s = NAMEOF("name for GL buffer object"); cdp = pick_platform("platform"); if( cdp != NULL ) push_pfdev_context(QSP_ARG PF_CONTEXT(cdp) ); pdp = pick_pfdev("device"); if( cdp != NULL ) pop_pfdev_context(SINGLE_QSP_ARG); w = (int)HOW_MANY("width"); h = (int)HOW_MANY("height"); d = (int)HOW_MANY("depth"); /* what should the depth be??? default to 1 for now... */ if( pdp == NULL ) return; /* Make sure this name isn't already in use... */ dp = dobj_of(s); if( dp != NULL ){ sprintf(ERROR_STRING,"Data object name '%s' is already in use, can't use for GL buffer object.",s); warn(ERROR_STRING); return; } #ifdef HAVE_OPENGL // BUG need to be able to set the cuda device. // Note, however, that we don't need GL buffers on the Tesla... //set_data_area(cuda_data_area[0][0]); set_data_area( PFDEV_AREA(pdp,PFDEV_GLOBAL_AREA_INDEX) ); ds.ds_dimension[0]=d; ds.ds_dimension[1]=w; ds.ds_dimension[2]=h; ds.ds_dimension[3]=1; ds.ds_dimension[4]=1; dp = _make_dp(QSP_ARG s,&ds,PREC_FOR_CODE(PREC_UBY)); if( dp == NULL ){ sprintf(ERROR_STRING, "Error creating data_obj header for %s",s); error1(ERROR_STRING); } SET_OBJ_FLAG_BITS(dp, DT_NO_DATA); /* can't free this data */ SET_OBJ_FLAG_BITS(dp, DT_GL_BUF); /* indicate obj is a GL buffer */ SET_OBJ_DATA_PTR(dp, NULL); //fprintf(stderr,"do_new_gl_buffer: allocating gl_info for %s\n",OBJ_NAME(dp)); SET_OBJ_GL_INFO(dp, (GL_Info *) getbuf( sizeof(GL_Info) ) ); //fprintf(stderr,"do_new_gl_buffer: DONE allocating gl_info for %s\n",OBJ_NAME(dp)); glew_check(SINGLE_QSP_ARG); /* without this, we get a segmentation * violation on glGenBuffers??? */ // We need an extra field in which to store the GL identifier... // AND another extra field in which to store the associated texid. // Why is this ifdef here? These don't seem to depend // on libglew??? // Answer: We need libglew to bring in openGL extensions like glBindBuffer... //advise("calling glGenBuffers"); //fprintf(stderr,"OBJ_GL_INFO(%s) = 0x%lx\n",OBJ_NAME(dp),(long)OBJ_GL_INFO(dp)); //fprintf(stderr,"OBJ_BUF_ID_P(%s) = 0x%lx\n",OBJ_NAME(dp),(long)OBJ_BUF_ID_P(dp)); // BUG glGenBuffers seems to require v1.5??? glGenBuffers(1, OBJ_BUF_ID_P(dp) ); // first arg is # buffers to generate? //sprintf(ERROR_STRING,"glGenBuffers gave us buf_id = %d",OBJ_BUF_ID(dp)); //advise(ERROR_STRING); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OBJ_BUF_ID(dp) ); // glBufferData will allocate the memory for the buffer, // but won't copy unless the pointer is non-null // How do we get the gpu memory space address? // That must be with map glBufferData(GL_PIXEL_UNPACK_BUFFER, OBJ_COMPS(dp) * OBJ_COLS(dp) * OBJ_ROWS(dp), NULL, GL_STREAM_DRAW); /* buffer arg set to 0 unbinds any previously bound buffers... * and restores client memory usage. */ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); //#endif // HAVE_LIBGLEW glGenTextures(1, OBJ_TEX_ID_P(dp) ); // makes a texture name fprintf(stderr,"new_gl_buffer: new texture name is 0x%x\n",OBJ_TEX_ID(dp)); glBindTexture(GL_TEXTURE_2D, OBJ_TEX_ID(dp) ); t = gl_pixel_type(dp); glTexImage2D( GL_TEXTURE_2D, 0, // level-of-detail - is this the same as miplevel??? OBJ_COMPS(dp), // internal format, can also be symbolic constant such as // GL_RGBA etc OBJ_COLS(dp), // width - must be 2^n+2 (border) for some n??? OBJ_ROWS(dp), // height - must be 2^m+2 (border) for some m??? 0, // border - must be 0 or 1 t, // format of pixel data GL_UNSIGNED_BYTE, // type of pixel data NULL // pixel data - null pointer means // allocate but do not copy? // - offset into PIXEL_UNPACK_BUFFER?? ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Why was this here? It would seem to un-bind the target??? glBindTexture(GL_TEXTURE_2D, 0); //glFinish(); // necessary or not? //advise("calling platform-specific buffer registration function"); if( (*PF_REGBUF_FN(PFDEV_PLATFORM(pdp)))( QSP_ARG dp ) < 0 ){ WARN("do_new_gl_buffer: Error in platform-specific buffer registration!?"); // BUG? - should clean up here! } // Leave the buffer mapped by default //cutilSafeCall(cudaGLMapBufferObject( &OBJ_DATA_PTR(dp), OBJ_BUF_ID(dp) )); //advise("calling platform-specific buffer mapping function"); if( (*PF_MAPBUF_FN(PFDEV_PLATFORM(pdp)))( QSP_ARG dp ) < 0 ){ WARN("do_new_gl_buffer: Error in platform-specific buffer mapping!?"); // BUG? - should clean up here! } SET_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED); // propagate change to children and parents propagate_flag(dp,DT_BUF_MAPPED); #else // ! HAVE_OPENGL NO_OGL_MSG #endif // ! HAVE_OPENGL } /* end do_new_gl_buffer */