// executes functions based on choice void doChoice(string choice, Stopwatch &stopwatch) { if (choice == "toggle") { if (stopwatch.isRunning()) { stopwatch.toggle(); cout << "Stopwatch stopped at " << stopwatch.split() << " seconds." << endl; } else { cout << "Stopwatch started." << endl; stopwatch.toggle(); } } else if (choice == "split") { cout << "Elapsed time is " << stopwatch.split() << " seconds." << endl; } else if (choice == "reset") { stopwatch.reset(); cout << "Stopwatch reset." << endl; } else if (choice == "status") { if (stopwatch.isRunning()) { cout << "Stopwatch is running." << endl; cout << "Elapsed time is " << stopwatch.split() << " seconds." << endl; } else { cout << "Stopwatch is not running." << endl; cout << "Elapsed time is " << stopwatch.split() << " seconds." << endl; } } // catch invalid input else { throw 1; } }
void AdlPrimitivesDemo::test( Buffer<int2>& buf, int size, Stopwatch& sw ) { Kernel* kernel = KernelManager::query( m_deviceData, "..\\..\\AdlDemos\\TestBed\\Demos\\AdlPrimitivesDemoKernel", "FillInt4Kernel" ); Buffer<int4> constBuffer( m_deviceData, 1, BufferBase::BUFFER_CONST ); int numGroups = (size+128*4-1)/(128*4); Buffer<u32> workBuffer0( m_deviceData, numGroups*(16) ); Buffer<u32> workBuffer1( m_deviceData, numGroups*(16) ); Buffer<int2> sortBuffer( m_deviceData, size ); { int2* host = new int2[size]; for(int i=0; i<size; i++) { host[i] = make_int2( getRandom(0, 0xf), i ); } sortBuffer.write( host, size ); DeviceUtils::waitForCompletion( m_deviceData ); delete [] host; } int4 constData; { constData.x = size; constData.y = 0; constData.z = numGroups; constData.w = 0; } sw.start(); int nThreads = size/4; { BufferInfo bInfo[] = { BufferInfo( &buf ), BufferInfo( &workBuffer0 ), BufferInfo( &workBuffer1 ) }; Launcher launcher( m_deviceData, kernel ); launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(Launcher::BufferInfo) ); launcher.setConst( constBuffer, constData ); launcher.launch1D( nThreads, 128 ); } sw.split(); { constData.w = 1; int nThreads = size/4; BufferInfo bInfo[] = { BufferInfo( &buf ), BufferInfo( &workBuffer0 ), BufferInfo( &workBuffer1 ) }; Launcher launcher( m_deviceData, kernel ); launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(Launcher::BufferInfo) ); launcher.setConst( constBuffer, constData ); launcher.launch1D( nThreads, 128 ); } sw.split(); { constData.w = 2; int nThreads = size/4; BufferInfo bInfo[] = { BufferInfo( &sortBuffer ), BufferInfo( &workBuffer0 ), BufferInfo( &workBuffer1 ) }; Launcher launcher( m_deviceData, kernel ); launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(Launcher::BufferInfo) ); launcher.setConst( constBuffer, constData ); launcher.launch1D( nThreads, 128 ); } sw.stop(); { int2* host = new int2[size]; buf.read( host, size ); DeviceUtils::waitForCompletion( m_deviceData ); for(int i=0; i<128*4-1; i++) { ADLASSERT( host[i].x <= host[i+1].x ); } delete [] host; } { float t[3]; sw.getMs(t, 3); // (byte * nElems) sprintf_s(m_txtBuffer[m_nTxtLines++], LINE_CAPACITY, "LoadStore: %3.2fGB/s (%3.2fns)", (4*8*2)*nThreads/t[0]/1000/1000, t[0]*1000.f); sprintf_s(m_txtBuffer[m_nTxtLines++], LINE_CAPACITY, "GenHistog: %3.2fGB/s (%3.2fns)", (4*(8*2+2))*nThreads/t[1]/1000/1000, t[1]*1000.f); sprintf_s(m_txtBuffer[m_nTxtLines++], LINE_CAPACITY, "FullSort: %3.2fGB/s (%3.2fns)", (4*(8*2+2))*nThreads/t[2]/1000/1000, t[2]*1000.f); } }