void Scheduler::issueInstruction(InstRef &IR) { // Release buffered resources. const InstrDesc &Desc = IR.getInstruction()->getDesc(); releaseBuffers(Desc.Buffers); notifyReleasedBuffers(Desc.Buffers); // Issue IS to the underlying pipelines and notify listeners. SmallVector<std::pair<ResourceRef, double>, 4> Pipes; issueInstructionImpl(IR, Pipes); notifyInstructionIssued(IR, Pipes); if (IR.getInstruction()->isExecuted()) notifyInstructionExecuted(IR); }
NuPlayerVPPProcessor::~NuPlayerVPPProcessor() { quitThread(); if (mWorker != NULL) { delete mWorker; mWorker = NULL; } if (mThreadRunning == false) { releaseBuffers(); } mNuPlayerVPPProcessor = NULL; LOGI("===== VPPInputCount = %d =====", mInputCount); }
void UdrServerDataStream::actOnReceive(IpcConnection *conn) { const char *moduleName = "UdrServerDataStream::actOnReceive()"; IpcMessageObjType t; NABoolean somethingArrived = FALSE; // // A note about control flow in this method. It was originally // written under the assumption that only one message arrives at a // time. It would call getNextReceiveMsg() only once, then process // incoming objects, then return. It turns out this creates a memory // leak. Internally within the stream, the incoming message buffer // never moved from the "receive" list to the "in use" list and // never got cleaned up. Now this method calls getNextReceiveMsg() // until it returns FALSE. The result is that after the incoming // message has been processed, the next getNextReceiveMsg() call // will move the request buffer to the "in use" list where it later // gets cleaned up by a call to cleanupBuffers() or // releaseBuffers(). // while (getNextReceiveMsg(t)) { somethingArrived = TRUE; while (getNextObjType(t)) { switch (t) { case UDR_MSG_DATA_HEADER: { // Do nothing for now except extract the object from the stream UdrDataHeader *h = new (receiveMsgObj()) UdrDataHeader(this); } // case UDR_MSG_DATA_HEADER break; case UDR_MSG_CONTINUE_REQUEST: { // Extract the object from the stream and call SPInfo's work() UdrContinueMsg *m = new (receiveMsgObj()) UdrContinueMsg(this); if(spinfo_->getParamStyle() == COM_STYLE_TM) spinfo_->workTM(); else spinfo_->work(); } // case UDR_MSG_CONTINUE_REQUEST break; case UDR_MSG_DATA_REQUEST: { UdrDataBuffer *request = new (receiveMsgObj()) UdrDataBuffer(this); if (udrGlob_->verbose_ && udrGlob_->traceLevel_ >= TRACE_DETAILS && udrGlob_->showMain_) { ServerDebug( ""); ServerDebug("[UdrServ (%s)] Invoke Request has %ld tupps.", moduleName, request->getSqlBuffer()->getTotalTuppDescs()); ServerDebug("[UdrServ (%s)] Invoke Request SQL Buffer", moduleName); displaySqlBuffer(request->getSqlBuffer(), (Lng32) request->getSqlBufferLength()); } udrGlob_->numReqInvokeSP_++; // Let the SPInfo process the request spinfo_->setCurrentRequest(request); spinfo_->work(); } // case UDR_MSG_DATA_REQUEST break; case UDR_MSG_TMUDF_DATA_HEADER: { // Extract the object. UDR Handle and RS Handle are // interesting things in this message. UdrTmudfDataHeader *h = new (receiveMsgObj()) UdrTmudfDataHeader(this); UdrHandle udrHandle = h->getHandle(); NABoolean anyMore = getNextObjType(t); UDR_ASSERT(anyMore, "DATA_REQUEST must follow TMUDF DATA_HEADER"); UDR_ASSERT(t == UDR_MSG_DATA_REQUEST, "DATA_REQUEST must follow TMUDF DATA_HEADER"); UdrDataBuffer *request = new (receiveMsgObj()) UdrDataBuffer(this, FALSE); //Avoid unpack. // Let the SPInfo process the request spinfo_->setCurrentRequest(request); spinfo_->workTM(); } break; case UDR_MSG_RS_DATA_HEADER: { // Extract the object. UDR Handle and RS Handle are // interesting things in this message. UdrRSDataHeader *h = new (receiveMsgObj()) UdrRSDataHeader(this); UdrHandle udrHandle = h->getHandle(); RSHandle rsHandle = h->getRSHandle(); NABoolean anyMore = getNextObjType(t); UDR_ASSERT(anyMore, "DATA_REQUEST must follow RS_DATA_HEADER"); UDR_ASSERT(t == UDR_MSG_DATA_REQUEST, "DATA_REQUEST must follow RS_DATA_HEADER"); UdrDataBuffer *request = new (receiveMsgObj()) UdrDataBuffer(this); udrGlob_->numReqRSFetch_++; processAnRSFetchMessage(udrGlob_, *this, udrHandle, rsHandle, request); // We need the request buffer in a state where the stream // knows it can be freed. We call SqlBuffer::bufferFull() to // accomplish this even though the method name is a bit // misleading. SqlBuffer *sqlBuf = request->getSqlBuffer(); UDR_ASSERT(sqlBuf, "UDR request buffer is corrupt or contains no data"); sqlBuf->bufferFull(); } break; case UDR_MSG_RS_CONTINUE: { UdrRSContinueMsg *rsContinue = new (receiveMsgObj()) UdrRSContinueMsg(this); udrGlob_->numReqRSContinue_++; processAnRSContinueMessage(udrGlob_, *this, *rsContinue); } break; default: { UDR_ASSERT(FALSE, "Unknown message type arrived on UDR data stream"); } // default break; } // switch (t) } // while (getNextObjType(t)) } // while (getNextReceiveMsg(t)) // Make sure all reply buffers have been given to the connection. If // the only objects that arrived during this callback were continue // requests, then this action allows reply buffers associated with // those continue requests to propagate out of the stream and onto // the connection. // // If numOfInputBuffers() is > 0 then we do not need to do anything // at this point. This callback will be invoked again when the // incoming message is complete and ready to be processed. Lng32 numInputBuffers = numOfInputBuffers(); if (somethingArrived && numInputBuffers == 0 && spinfo_->getCurrentRequest() == NULL) { responseDone(); if (udrGlob_->verbose_ && udrGlob_->traceLevel_ >= TRACE_IPMS && udrGlob_->showMain_) { ServerDebug("[UdrServ (%s)] All messages marked as replied", moduleName); } // Cleanup any unpacked message buffers containing only objects // that are no longer in use, as determined by the virtual method // IpcMessageObj::msgObjIsFree() releaseBuffers(); // Do final garbage collection } } // UdrServerDataStream::actOnReceive()
~PyBufferWrapper(void) { releaseBuffers(); }
PyBufferWrapper(PyObject *const data, const uint32_t count, const bool writable) : m_count(count), m_length(UINT32_MAX) { memset(m_buffers, 0, sizeof(double*) * MAX_BUFFERS); memset(m_views, 0, sizeof(Py_buffer) * MAX_BUFFERS); if (!((data) && PyTuple_Check(data))) { PY_EXCEPTION("Input Python object does not appear to be a tuple!"); throw std::invalid_argument("Invalid buffer object!"); } if (!((count > 0) && (count <= MAX_BUFFERS) && (static_cast<uint32_t>(PyTuple_Size(data)) >= count))) { PY_EXCEPTION("Input tuple does not have the required minimum size!"); throw std::invalid_argument("Invalid buffer count!"); } PyObject *pyArrays[MAX_BUFFERS]; for (uint32_t c = 0; c < count; ++c) { if (!(pyArrays[c] = PyTuple_GetItem(data, static_cast<Py_ssize_t>(c)))) { PY_EXCEPTION("Failed to obtain the n-th element of the given input tuple!"); throw std::invalid_argument("PyTuple_GetItem() error!"); } if (PyObject_IsInstance(pyArrays[c], g_arrayClass) <= 0) { PY_EXCEPTION("The n-th element of the given tuple is not an array object!"); throw std::invalid_argument("PyObject_IsInstance() error!"); } } for (uint32_t c = 0; c < count; ++c) { if (!PyObject_CheckBuffer(pyArrays[c])) { PY_EXCEPTION("The provided array object does not support the 'buffer' protocol!"); releaseBuffers(); throw std::invalid_argument("PyObject_CheckBuffer() error!"); } if (PyObject_GetBuffer(pyArrays[c], &m_views[c], (writable ? PyBUF_WRITABLE : 0)) < 0) { PY_EXCEPTION("Failed to get the internal buffer from array object!"); releaseBuffers(); throw std::invalid_argument("PyObject_GetBuffer() error!"); } if (m_views[c].itemsize != sizeof(double)) { PY_EXCEPTION("The provided array has an invalid item size! Not 'double' array?"); releaseBuffers(); throw std::invalid_argument("Py_buffer.itemsize is invalid!"); } if ((m_length = std::min(m_length, static_cast<uint32_t>(m_views[c].len / m_views[c].itemsize))) < 1) { PY_EXCEPTION("The size of the provided buffers is way too small!"); releaseBuffers(); throw std::invalid_argument("Py_buffer.len is invalid!"); } if (!(m_buffers[c] = reinterpret_cast<double*>(m_views[c].buf))) { PY_EXCEPTION("Pointer to the arrays's buffer appears to be NULL!"); releaseBuffers(); throw std::invalid_argument("Py_buffer.buf is invalid!"); } } }
/** Run the OpenCL kernel */ short runOpenCL(struct benchmark *bench) { short j; #ifdef DEBUG printf("TEST OPENCL\n"); #endif /********************** Initializations **********************/ error=clGetPlatformIDs(1,&platform,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Error to get platform ID : %d\n",error); goto error; } error=clGetDeviceIDs(platform,CL_DEVICE_TYPE_GPU,1,&device,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Error to get device ID : %d\n",error); goto error; } if (error != CL_SUCCESS) { fprintf(stderr,"Can't get device info : %d\n",error); goto error; } context = clCreateContext(0,1,&device,NULL,NULL,&error); if (error != CL_SUCCESS) { fprintf(stderr,"Error to create context : %d\n",error); goto error; } size_t maxWorkItemDim; size_t maxWorkGroupSize; size_t workItemSize[10]; error = clGetDeviceInfo(device,CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,sizeof(size_t),&maxWorkItemDim,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't get max work item dimensions : %d\n",error); goto errorContext; } error = clGetDeviceInfo(device,CL_DEVICE_MAX_WORK_ITEM_SIZES,maxWorkItemDim*sizeof(size_t),workItemSize,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't get mwork item sizes : %d\n",error); goto errorContext; } error = clGetDeviceInfo(device,CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t),&maxWorkGroupSize,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't get max work item dimensions : %d\n",error); goto errorContext; } queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE ,&error); if (error != CL_SUCCESS) { fprintf(stderr,"Error to create command queue : %d\n",error); goto errorContext; } /********************** Memory allocations **********************/ long i; #ifdef DEBUG printf("Create buffers\n"); #endif double createBufTime; createBufTime = createBuffers(context,bench); /********************** OpenCL kernel **********************/ cl_program program; char *fileContent; FILE *f; struct stat fState; char path[256]; strcpy(path,"Kernels/"); strcat(path,bench->kernel); stat(path,&fState); f=fopen(path,"r"); fileContent=malloc(fState.st_size*sizeof(char)); fread(fileContent,sizeof(char),fState.st_size,f); fclose(f); program=clCreateProgramWithSource(context,1,(const char**)&fileContent,&fState.st_size,&error); free(fileContent); if (error != CL_SUCCESS) { fprintf(stderr,"Can't create program : %d\n",error); goto errorBuffer; } /*error=clBuildProgram(program,1,&device,"-cl-fast-relaxed-math",NULL,NULL);*/ error=clBuildProgram(program,1,&device,"",NULL,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't build program : %d\n",error); goto errorProgram; } cl_kernel kernel=clCreateKernel(program,"mainKernel",&error); if (error != CL_SUCCESS) { fprintf(stderr,"Can't create kernel : %d\n",error); goto errorProgram; } /********************** Launching the kernel **********************/ #ifdef DEBUG printf("Set args\n"); #endif setArgs(kernel,bench); cl_ulong lStart; cl_ulong lEnd; double fTimeInSeconds; double fFLOPS; #ifdef DEBUG printf("Compute\n"); printf("%d\n",bench->worksizeDim); for(i=0;i<bench->worksizeDim;i++) { printf(" GLOBAL -> %d\n",bench->global_ws[i]); printf(" LOCAL -> %d\n",bench->local_ws[i]); } #endif double writeBufTime; writeBufTime=writeInputs(queue,bench); double computeTime=getCurrentTime(); error=clEnqueueNDRangeKernel(queue, kernel,bench->worksizeDim, NULL,bench->global_ws, bench->local_ws,0,NULL,&event); if (error != CL_SUCCESS) { fprintf(stderr,"Can't enqueue kernel : %d\n",error); goto errorKernel; } clFinish(queue); computeTime= getCurrentTime() - computeTime; #ifdef DEBUG printf("Read results\n"); #endif double readBufTime; readBufTime=readResults(queue,bench); error = clGetEventProfilingInfo(event,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&lStart,NULL); error |= clGetEventProfilingInfo(event,CL_PROFILING_COMMAND_END ,sizeof(cl_ulong),&lEnd,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't get profiling info : %d\n",error); goto errorEvent; } fTimeInSeconds = ((double)(lEnd-lStart)) / 1000000000.0; /* Send timing */ write(newsockfd,"t\n",2*sizeof(char)); sprintf(result,"%f\n",createBufTime); write(newsockfd,result,strlen(result)); sprintf(result,"%f\n",writeBufTime); write(newsockfd,result,strlen(result)); sprintf(result,"%f\n",fTimeInSeconds); write(newsockfd,result,strlen(result)); sprintf(result,"%f\n",readBufTime); write(newsockfd,result,strlen(result)); /*sprintf(result,"%f\n",computeTime); write(newsockfd,result,strlen(result)); */ /* Send results */ sendResults(bench); errorEvent: clReleaseEvent(event); errorKernel: clReleaseKernel(kernel); /********************** Cleanup **********************/ errorProgram: clReleaseProgram(program); errorBuffer: clReleaseCommandQueue(queue); releaseBuffers(bench); errorContext: clReleaseContext(context); /** HORRIBLE error processing. It may create memory leaks. It will have to be improved. */ error: return (error != CL_SUCCESS); }
kit::Sphere::~Sphere() { releaseBuffers(); }