Optix Prime - Not running on passed in stream.

Optix prime is not running on the stream I have been passing it via a CUDA interface I have set up. This interface sets up a mapping of threads to streams which automatically generates streams on request. ( Say: Thread 0 requests Stream 1 on the current device. ) That request will create a stream which will persist for the lifetime of the thread.

OptiX when passing this stream similar to the below:

NOTE: This is a handtyped relavent sample of my codebase and is not meant to be compilable. It is simply showing how I am using the library. The model and triangles are generated in code not provided here.

When using OptiX in the way I am using it, the library is creating a new stream and running all queries on that while not using the one I passed to it.

__host__ void CUDARayTracer::rayTrace( const Transducer & tx,
                                       const Transducer & rx,
                                       const float frequency )
{
    // Sets the current device to an internal list of available devices which point to actual cuda device ids. ( This excludes devices attached to a screen for example or under compute < 3.0 )
    // We have other functions that simply cycle through the list of available devices.
    // TODO: Change to cycle gpus assigned to OptiX context
    CudaSetDevice(0);
    // Gets the first stream for current device, thread::id pair.
    cudaStream_t stream = CudaGetStream(0);
    
    DeviceArray<Hit> d_hits( m_numRaysX*m_numRaysY );
    // Generates rays radiating from the source towards a receiver 
    DeviceArray<geometry::CUDARay3D> d_rays( generateRays( tx.getInertialPosition(),
                                             rx.getInertialPosition(),
                                             tx.getInertialDownUnitVector(),
                                             stream ) );

    optix::prime::Query query( initializeRayTraceQuery( d_hits, d_rays ) );

    executeQueryAsync( query, stream );

    finishQueryAsync( query );

    // ... Use hits and ray buffers past this point...
}

__host__ optix::prime::Query CUDARayTracer::initializeRayTraceQuery( DeviceArray<Hit> & d_hits,
                                                      DeviceArray<geometry::CUDARay3D> & d_rays ) const
{
    optix::prime::Context context( GetOptixPrimeContext() );

    // Model and triangles are generated in other functions not provided here...
    optix::prime::Query = m_model->createQuery( RTP_QUERY_TYPE_CLOSEST );
    
    optix::prime::BufferDesc raysDesc = context->createBufferDesc( RTP_BUFFER_FORMAT_RAY_ORIGIN_TMIN_DIRECTION_TMAX,
RTP_BUFFER_TYPE_CUDA_LINEAR,
reinterpret_cast< void * >( d_rays.data() ) );

    optix::prime::BufferDesc hitsDesc = context->createBufferDesc( RTP_BUFFER_FORMAT_HIT_T_TRIID_U_V,
RTP_BUFFER_TYPE_CUDA_LINEAR,
reinterpret_cast< void * >( d_hits.data() ) );
    
    raysDesc->setRange( 0, d_rays.getSizeElements() );
    hitsDesc->setRange( 0, d_hits.getSizeElements() );
    query->setHits( hitsDesc );
    query->setRays( raysDesc );

    return query;
}

__host__ void CUDARayTracer::executeQueryAsync( optix::prime::Query query,
                                                 cudaStream_t stream ) const
{
    query->setCudaStream(stream);
    query->execute( RTP_QUERY_HINT_ASYNC );
}

__host__ void CUDARayTracer::finishQueryAsync( optix::prime::Query query ) const
{
    query->finish();
}