SciSharp / NumSharp

High Performance Computation for N-D Tensors in .NET, similar API to NumPy.
https://github.com/SciSharp
Apache License 2.0
1.37k stars 192 forks source link

np.multiply is extremly slow #339

Closed Oceania2018 closed 5 years ago

Oceania2018 commented 5 years ago

Run TensorFlow.NET Logistic Regression:

image

Nucs commented 5 years ago

A. You can not evaluate execution speed with visual studios line execution counter. B. The library is not built to be used in a DEBUG configuration. It heavily relies on JIT optimization and aggressive inlining which occurs only when run in a RELEASE config or compiled with: image

Nevertheless, there is always place for more optimization

Oceania2018 commented 5 years ago

I use release mode and optimize code. It's better, but still much slower than before.

image

Oceania2018 commented 5 years ago

I've pushed debug code to https://github.com/SciSharp/TensorFlow.NET/tree/numsharp-unmanaged-storage.

Run Example project as: image

Please compare it with previous version. I really hope there is not performance regression.

Oceania2018 commented 5 years ago

It's better now. The first iteration needs JIT optimization. After that, it's more faster than before. But for the session.run, it's still about 1.5x slower.

image

Nucs commented 5 years ago

As np.multiply and all ops were optimized to as far as possible, I see the issue resolved. As for session.run, it is a mix of functions - I'll see what I can do.