Hello, everyone. I’m trying to solve a complex system using ModelingToolkit, which involves an array variable. One of the equations is quite heavy computationally and I was trying to pass this array as an argument, then build a GPU array (CUDA in this case, I don’t have more GPUs now), do the calculation and return the value back in the original format. The problem is that symbolic variables are of type Num and they are not isbitstype.
I then decided to try a small example and build a simple model with a CuArray with the idea of knowing if I can build everything directly:
using CUDA, ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
x0 = ones(2)
x0CU = CuArray(x0)
A = Float64[2 1; 1 2]
ACU = CuArray(A)
@mtkmodel Example begin
@variables begin
x(t)[1:2] = x0
end
@equations begin
D(x) ~ A * x
end
end
@mtkcompile example = Example()
@mtkmodel ExampleCU begin
@variables begin
x(t)[1:2] = x0CU
end
@equations begin
D(x) ~ derivative(x, ACU)
end
end
@mtkcompile exampleCU = ExampleCU()
The example model is compiled correctly on the CPU, but the exampleCU one for the GPU does not compile since it throws the scalar indexing error
ERROR: Scalar indexing is disallowed.
Note that something like
ACU * x0CU
outside of @mtkmodel works and returns a CuArray as a result.
Is there a way in ModelingToolkit for me to take a symbolic array, convert it to the desired numerical format for me to parallelize it and then return it back to MTK with the original type so the program can continue the evaluation? Or am I restricted to, at most, CPU parallelization?