void Grid::openPredictionGrid(QString fname) { fstream file_ip((fname.toStdString()).c_str(), ios::in); if (!file_ip) { cerr << "Can't open input file " << endl; return; } int x_size = 0; int y_size = 0; int index = 0; int splitIndex = 0; QString qFname = ""; string intBufferStr = ""; string line = ""; string listFname = ""; string vecIndex = ""; cout << "doing file stuff" << endl; // get the stored size of the vector getline(file_ip,intBufferStr); istringstream intBuffer(intBufferStr); intBuffer >> x_size; getline(file_ip, intBufferStr); istringstream intBufferTwo(intBufferStr); intBufferTwo >> y_size; cout << "x_size = " << x_size << endl; cout << "y_size = " << y_size << endl; cout << "Before reset grid" << endl; resetGrid(); cout << "After reset grid" << endl; int i = 1; while(!file_ip.eof()) { getline(file_ip,line); cout << "Line is " << line << endl; splitIndex = line.find_first_of(','); vecIndex = line.substr(0,splitIndex); listFname = line.substr(splitIndex + 1); qFname = listFname.c_str(); istringstream buffer(vecIndex); buffer >> index; cout << "index = " << index << endl; cout << "filename = " << qFname << endl; addTrack(index % som_height, index / som_height, qFname); } }
void AudioDataOutput::processBuffer(GstPad*, GstBuffer* buffer, gpointer gThat) { // TODO emit endOfMedia AudioDataOutput *that = reinterpret_cast<AudioDataOutput*>(gThat); // determine the number of channels GstStructure* structure = gst_caps_get_structure (GST_BUFFER_CAPS(buffer), 0); gst_structure_get_int (structure, "channels", &that->m_channels); if (that->m_channels > 2 || that->m_channels < 0) { qWarning() << Q_FUNC_INFO << ": Number of channels not supported: " << that->m_channels; return; } gint16 *data = reinterpret_cast<gint16*>(GST_BUFFER_DATA(buffer)); guint size = GST_BUFFER_SIZE(buffer) / sizeof(gint16); that->m_pendingData.reserve(that->m_pendingData.size() + size); for (uint i=0; i<size; i++) { // 8 bit? interleaved? yay for lacking documentation! that->m_pendingData.append(data[i]); } while (that->m_pendingData.size() > that->m_dataSize * that->m_channels) { if (that->m_channels == 1) { QVector<qint16> intBuffer(that->m_dataSize); memcpy(intBuffer.data(), that->m_pendingData.constData(), that->m_dataSize * sizeof(qint16)); that->convertAndEmit(intBuffer, intBuffer); int newSize = that->m_pendingData.size() - that->m_dataSize; memmove(that->m_pendingData.data(), that->m_pendingData.constData() + that->m_dataSize, newSize * sizeof(qint16)); that->m_pendingData.resize(newSize); } else { QVector<qint16> left(that->m_dataSize), right(that->m_dataSize); for (int i=0; i<that->m_dataSize; i++) { left[i] = that->m_pendingData[i*2]; right[i] = that->m_pendingData[i*2+1]; } that->m_pendingData.resize(that->m_pendingData.size() - that->m_dataSize*2); that->convertAndEmit(left, right); } } }
inline void fillIntTest() { TEST_INIT; b3FillCL* fillCL = new b3FillCL(g_context,g_device,g_queue); int maxSize=1024*256; b3OpenCLArray<int> intBuffer(g_context,g_queue,maxSize); intBuffer.resize(maxSize); #define NUM_TESTS 7 int dx = maxSize/NUM_TESTS; for (int iter=0;iter<NUM_TESTS;iter++) { int size = b3Min( 11+dx*iter, maxSize ); int value = 2; int offset=0; fillCL->execute(intBuffer,value,size,offset); b3AlignedObjectArray<int> hostBuf2; hostBuf2.resize(size); fillCL->executeHost(hostBuf2,value,size,offset); b3AlignedObjectArray<int> hostBuf; intBuffer.copyToHost(hostBuf); for(int i=0; i<size; i++) { TEST_ASSERT( hostBuf[i] == hostBuf2[i] ); TEST_ASSERT( hostBuf[i] == hostBuf2[i] ); } } delete fillCL; TEST_REPORT( "fillIntTest" ); }
void octree::sort_dust(tree_structure &tree) { if(tree.n_dust == 0) return; devContext.startTiming(execStream->s()); //Start reduction to get the boundary's of the dust boundaryReduction.set_arg<int>(0, &tree.n_dust); boundaryReduction.set_arg<cl_mem>(1, tree.dust_pos.p()); boundaryReduction.set_arg<cl_mem>(2, devMemRMIN.p()); boundaryReduction.set_arg<cl_mem>(3, devMemRMAX.p()); boundaryReduction.setWork(tree.n, NTHREAD_BOUNDARY, NBLOCK_BOUNDARY); //256 threads and 120 blocks in total boundaryReduction.execute(execStream->s()); devMemRMIN.d2h(); //Need to be defined and initialized somewhere outside this function devMemRMAX.d2h(); //Need to be defined and initialized somewhere outside this function real4 r_min = make_real4(+1e10, +1e10, +1e10, +1e10); real4 r_max = make_real4(-1e10, -1e10, -1e10, -1e10); //Reduce the blocks, done on host since its //A faster and B we need the results anyway for (int i = 0; i < 120; i++) { r_min.x = std::min(r_min.x, devMemRMIN[i].x); r_min.y = std::min(r_min.y, devMemRMIN[i].y); r_min.z = std::min(r_min.z, devMemRMIN[i].z); r_max.x = std::max(r_max.x, devMemRMAX[i].x); r_max.y = std::max(r_max.y, devMemRMAX[i].y); r_max.z = std::max(r_max.z, devMemRMAX[i].z); } LOG("Found dust boundarys, number of particles %d : \n", tree.n_dust); LOG("min: %f\t%f\t%f\tmax: %f\t%f\t%f \n", r_min.x,r_min.y,r_min.z,r_max.x,r_max.y,r_max.z); //Compute the boundarys of the dust, needed to get the PH key real size = 1.001f*std::max(r_max.z - r_min.z, std::max(r_max.y - r_min.y, r_max.x - r_min.x)); float4 corner = make_real4(0.5f*(r_min.x + r_max.x) - 0.5f*size, 0.5f*(r_min.y + r_max.y) - 0.5f*size, 0.5f*(r_min.z + r_max.z) - 0.5f*size, size); float domain_fac = size/(1 << MAXLEVELS); corner.w = domain_fac; //Compute the keys my_dev::dev_mem<uint4> srcValues(devContext); //The generalBuffer1 has size uint*4*N*3 //this buffer gets part: 0-uint*4*N srcValues.cmalloc_copy(tree.generalBuffer1, tree.n_dust, 0); //Compute the keys directly into srcValues build_key_list.set_arg<cl_mem>(0, srcValues.p()); build_key_list.set_arg<cl_mem>(1, tree.dust_pos.p()); build_key_list.set_arg<int>(2, &tree.n_dust); build_key_list.set_arg<real4>(3, &corner); build_key_list.setWork(tree.n_dust, 128); //128 threads per block build_key_list.execute(execStream->s()); // If srcValues and buffer are different, then the original values // are preserved, if they are the same srcValues will be overwritten gpuSort(devContext, srcValues, tree.dust_key,srcValues, tree.n_dust, 32, 3, tree); //Sort the relevant properties.Note we can optimize this //further as done with the normal particles my_dev::dev_mem<real4> real4Buffer1(devContext); my_dev::dev_mem<real4> real4Buffer2(devContext); my_dev::dev_mem<real4> real4Buffer3(devContext); int memOffset1 = real4Buffer1.cmalloc_copy(tree.generalBuffer1,tree.n_dust, 0); memOffset1 = real4Buffer2.cmalloc_copy(tree.generalBuffer1,tree.n_dust, memOffset1); memOffset1 = real4Buffer3.cmalloc_copy(tree.generalBuffer1,tree.n_dust, memOffset1); dataReorderCombined.set_arg<int>(0, &tree.n_dust); dataReorderCombined.set_arg<cl_mem>(1, tree.dust_key.p()); dataReorderCombined.setWork(tree.n_dust, 512); //Position, velocity and acc0 dataReorderCombined.set_arg<cl_mem>(2, tree.dust_pos.p()); dataReorderCombined.set_arg<cl_mem>(3, real4Buffer1.p()); dataReorderCombined.set_arg<cl_mem>(4, tree.dust_vel.p()); dataReorderCombined.set_arg<cl_mem>(5, real4Buffer2.p()); dataReorderCombined.set_arg<cl_mem>(6, tree.dust_acc0.p()); dataReorderCombined.set_arg<cl_mem>(7, real4Buffer3.p()); dataReorderCombined.execute(execStream->s()); tree.dust_pos.copy(real4Buffer1, tree.n_dust); tree.dust_vel.copy(real4Buffer2, tree.n_dust); tree.dust_acc0.copy(real4Buffer3, tree.n_dust); my_dev::dev_mem<int> intBuffer(devContext); my_dev::dev_mem<float2> float2Buffer(devContext); my_dev::dev_mem<int> sortPermutation(devContext); memOffset1 = float2Buffer.cmalloc_copy (tree.generalBuffer1,tree.n_dust, 0); memOffset1 = sortPermutation.cmalloc_copy(tree.generalBuffer1,tree.n_dust, memOffset1); memOffset1 = intBuffer.cmalloc_copy (tree.generalBuffer1,tree.n_dust, memOffset1); dataReorderF2.set_arg<int>(0, &tree.n_dust); dataReorderF2.set_arg<cl_mem>(1, tree.dust_key.p()); dataReorderF2.set_arg<cl_mem>(2, float2Buffer.p()); //Place holder, dust has no time dataReorderF2.set_arg<cl_mem>(3, float2Buffer.p()); //Reuse as destination1 dataReorderF2.set_arg<cl_mem>(4, tree.dust_ids.p()); dataReorderF2.set_arg<cl_mem>(5, sortPermutation.p()); //Reuse as destination2 dataReorderF2.setWork(tree.n_dust, 512); dataReorderF2.execute(execStream->s()); tree.dust_ids.copy(sortPermutation, sortPermutation.get_size()); devContext.stopTiming("DustSortReorder", -1, execStream->s()); }