-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d218105
commit 1ef381e
Showing
2 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
import { alpenglow, OldBindingType, BlitShader, OldComputeShader, DeviceContext, wgsl_copy_storage_operation, wgsl_expensive_operation, wgsl_fake_combine_to_texture } from '../imports.js'; | ||
import { alpenglow, OldBindingType, BlitShader, OldComputeShader, DeviceContext, wgsl_copy_storage_operation, wgsl_expensive_operation, wgsl_fake_combine_to_texture, U32Order, BufferArraySlot, getArrayType, RadixSortModule, Routine, Procedure, u32 } from '../imports.js'; | ||
import Random from '../../../dot/js/Random.js'; | ||
import Utils from '../../../dot/js/Utils.js'; | ||
|
||
// eslint-disable-next-line bad-sim-text | ||
const random = new Random(); | ||
|
@@ -155,6 +156,100 @@ export default class PerformanceTesting { | |
buffersToDestroy.forEach( buffer => buffer.destroy() ); | ||
} )(); | ||
} | ||
|
||
public static async loopRadixSortTest( | ||
combineStrategy: boolean, | ||
separateComputePasses: boolean | ||
): Promise<void> { | ||
const countPerFrame = 100; | ||
|
||
const inputSize = 4000; | ||
// const inputSize = workgroupSize * workgroupSize * ( 6 ) - 27 * 301; | ||
// const inputSize = workgroupSize * workgroupSize * ( workgroupSize - 3 ) - 27 * 301; | ||
// eslint-disable-next-line bad-sim-text | ||
const uintNumbers = new Uint32Array( _.range( 0, inputSize ).map( () => Math.floor( Math.random() * 1000000 ) ) ); | ||
|
||
const device = ( await DeviceContext.getDevice() )!; | ||
const deviceContext = new DeviceContext( device ); | ||
|
||
const order = U32Order; | ||
const size = inputSize; | ||
const maximumSize = inputSize + 100; | ||
|
||
const inputSlot = new BufferArraySlot( getArrayType( order.type, maximumSize ) ); | ||
const outputSlot = new BufferArraySlot( getArrayType( order.type, maximumSize ) ); | ||
|
||
const radixSortModule = new RadixSortModule( { | ||
input: inputSlot, | ||
output: outputSlot, | ||
name: 'performance test', | ||
|
||
order: order, | ||
totalBits: 32, | ||
|
||
radixWorkgroupSize: 64, | ||
radixGrainSize: 4, | ||
scanWorkgroupSize: 64, | ||
scanGrainSize: 4, | ||
|
||
lengthExpression: u32( size ), | ||
|
||
bitsPerPass: 2, // TODO: try 8 once we are doing more | ||
bitsPerInnerPass: 2, | ||
earlyLoad: false, | ||
scanModuleOptions: { | ||
areScannedReductionsExclusive: false | ||
} | ||
} ); | ||
|
||
const routine = await Routine.create( | ||
deviceContext, | ||
radixSortModule, | ||
[ inputSlot, outputSlot ], | ||
combineStrategy ? Routine.COMBINE_ALL_LAYOUT_STRATEGY : Routine.INDIVIDUAL_LAYOUT_STRATEGY, | ||
async ( context, execute, input: number[] ) => { | ||
context.setTypedBufferValue( inputSlot, input ); | ||
|
||
for ( let i = 0; i < countPerFrame; i++ ) { | ||
execute( context, input.length ); | ||
} | ||
} | ||
); | ||
|
||
const procedure = new Procedure( routine ).bindRemainingBuffers(); | ||
|
||
let startTime: DOMHighResTimeStamp | null = null; | ||
let countElapsed = 0; | ||
const elapsedTimes: number[] = []; | ||
|
||
const step = async () => { | ||
requestAnimationFrame( step ); | ||
|
||
if ( startTime === null ) { | ||
startTime = performance.now(); | ||
} | ||
|
||
countElapsed++; | ||
|
||
if ( countElapsed % 500 === 0 ) { | ||
const now = performance.now(); | ||
const elapsed = now - startTime; | ||
startTime = now; | ||
elapsedTimes.push( elapsed ); | ||
console.log( Utils.toFixed( elapsed, 0 ), elapsedTimes.length > 1 ? Utils.toFixed( _.sum( elapsedTimes.slice( 1 ) ) / elapsedTimes.slice( 1 ).length, 0 ) : 0 ); | ||
} | ||
|
||
// TODO: maybe avoid the await on the first frame? | ||
|
||
// TODO: accept typed arrays and get things working more efficiently! | ||
await procedure.standaloneExecute( deviceContext, [ ...uintNumbers ], { | ||
procedureExecuteOptions: { | ||
separateComputePasses: separateComputePasses | ||
} | ||
} ); | ||
}; | ||
await step(); | ||
} | ||
} | ||
|
||
alpenglow.register( 'PerformanceTesting', PerformanceTesting ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters