I think this is a device error rather than an error in the function. Looking at other discussion on the same exception, they are mentioning that you need to move the lengths into the CPU (which is exactly what the error says).
link to the issue in github 90