optixDeviceCreateContext Error code 7051

The OptiX 7 API doesn’t know about multiple GPUs. You need to make sure the proper CUDA context is selected per device before doing any OptiX operation as m001 explained.

For OptiX 7 examples using multiple GPUs, have a look into the SDK examples optixMultiGPU and optixNVlink.

For more advanced OptiX 7 examples explicitly showing multi-GPU workload distribution with different buffer allocation methods, CUDA peer-to-peer data sharing via NVLINK or PCI-E bus, and different OpenGL interop methods detecting which active GPU runs the OpenGL implementation, have a look here and read the repository’s README.md carefully:
https://forums.developer.nvidia.com/t/optix-advanced-samples-on-github/48410/4