gpufit / Gpufit

GPU-accelerated Levenberg-Marquardt curve fitting in CUDA
MIT License
313 stars 93 forks source link

Custom function fails to to fit in Python, only performing a single iteration. #102

Open kulius7 opened 2 years ago

kulius7 commented 2 years ago

Hello, I am struggling to define a custom fitting function for use in pyGpufit. I have already tried several variations, but never had a successful fit, so I would appreciate some help or tips. If this is the wrong place to present such a problem, please feel free to remove it or let me know. The function in question is a 2-dimensional parametric ellipse equation, defined as follows: 2d_ellipse_equation I followed the documentation when implementing the function. All necessary prerequisites (CUDA, Python, Visual Studio, etc.) are installed. The function was defined as ELLIPSE_2D with ModelID = 13 in the constants.h. The cuda device function, _ellipse2d.cuh containing all partial derivatives was written and thoroughly checked. I have attached it to this issue, please mind that I can't program in C/C++ and thus adapted the gauss2d.cuh device function file. The .cuh file was included in models.cuh, as well as the switch case was added. I used CMake GUI to configure the compiler, opened the solution file with Visual Studio 2022 and Re-built the project (I tried Debug and Release configs). No errors were encountered here. The GpuFit.dll file, as well as the modified gpufit.py files were then used to perform a test fit of this ellipse function. For the actual test fit I modified the gauss2d.py example file, which was included. I am fairly certain that the issue lies with the custom function, since simply changing the ModelID to another function (from 13 to e.g. 2) in Python with the custom-built library starts fitting, also noticeable in sustained load on the GPU (with a sufficient number of fits). Fitting using the custom function with ModelID = 13 however, will finish within a few seconds, no matter the specified number of fits and always returning the unchanged, initial parameters. I have included all altered files in a zip file, as well as the testing file in Python. gpufit_issue.zip Any help or insight would be greatly appreciated!

superchromix commented 2 years ago

Have you checked the return value of the call to gpufit(), and the output_states parameter?