TensorRT 6: dynamic shapes in thread

I want to create context in every thread.
for every thread,I create cuda context by pycuda.driver.Device.make_context and use the same engine to create trt context:

self.context = self.engine.create_execution_context()

it’s works fine for fixed shapes(the second line is not used).
but for dynamic shapes,
when I execute the code second time in the second thread,the first line of code causes a warning:

[TensorRT] WARNING: Could not set default profile 0 for execution context. Profile index must be set explicitly.

and the second line of the code causes a error:

IndexError: Profile index 0 is out of bounds.

Ubuntu 18.04
CUDA 10.1
TensorRT ga


Multiple execution contexts may exist for one ICudaEngine instance, allowing the same engine to be used for the execution of multiple batches simultaneously.

If the engine supports dynamic shapes, each execution context in concurrent use must use a separate optimization profile.

Please refer to below link for more details: