at::globalContext().setBenchmarkCuDNN(flag) should work in C++.
However, benchmark is off by default so I guess that’s not the root cause of the non-deterministic results.
You could try to use at::globalContext().deterministicCuDNN() or at::globalContext().setDeterministic() in the nightly binaries and refer to this document 3 for more information.