-
Notifications
You must be signed in to change notification settings - Fork 43
Convert multik-api, multik-jvm, multik-default to use multiplaform. Add native and js targets for multik-jvm #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ugin multik-jvm now also compiles for native. convert use of service loader to use standard reflection (probably wasn't necessary) Reflection for discovering Engines on native doesn't work so add an initEnginesProvider function that only has an implementation for native updating //apply("$rootDir/gradle/publish.gradle") still needs to be done
This reverts commit bf1b95c.
#14 okio's new filesystem api would make allow this for multiplatform also |
hey is there an ETA for this? |
I pulled the v0.0.2 in. And I added JS as a target. Someone might want to double check my conversions from Java.lang.System.arraycopy() to using using kotlin's kotlin.collections.copyInto are correct. (the multiplication of array indexes times 2 is confusing) |
So I was able to get JS passing all but one test (excluding JvmLinAlgTest tests) after I reified a bunch of functions to determine NDArray data types on JS. I also simplified/fixed loading engines on js and other targets. Most tests are passing on all targets. (haven't had time to compare if the tests that are failing are also failing on the v0.0.2 branch. But, it would be nice if you guys consider reviewing this pull request as it's hard to keep merging work into since the source set folders are reorganized with the multiplatform plugin ( src/kotlin/main -> src/kotlin/commonMain) |
@devcrocod Loading the engines happens slightly differently per target: JVM After some debugging
So essentially, the companion object's init function automatically loads the available engines on JVM and sets the default. Native and JS Reflection is not fully available on non-JVM targets. As far as I am aware of, there isn't a way to automatically locate and instantiate the available engines on those other targets. Without this ability So, I created a workaround for non-jvm targets with a global
So, for non-jvm targets simply supply the global [1] Disclaimer: For native builds the companion object behavior appears to be different than jvm and js. After debugging |
@devcrocod so this is the js issue I worked around with the reified functions:
In js outputs:
where as jvm and native output as expected:
Created an issue: https://youtrack.jetbrains.com/issue/KT-50455 |
calling toCommonNDArray() causes it to lose datatype info on JS. workaround this by: create two implementations of toCommonNDArray one which uses reified and one which requires a datatype ndarrayCommon has a new optional dtype param to force datatype revert most reified.
So I managed to revert almost all the The main problem was that calling in JS builds So I made a workaround by creating two implementations of |
Hi @occultus73 |
My boss/client said he wanted the capability to deploy the baysian context bandit library (basically a generic machine learning model) I built on multiplatform with a colleague to JavaScript environments. What exactly he had in mind I'm not sure, but he did express interest in the file io capabilities that come with node.js; as this allows the bandit to save and resume its learning progress in matrix files (I built custom binary file i/o because we didn't have .npy API then). |
@luca992 Using As for Engines and EnginesProvider. It seems to me that for the moment you can leave what you have done. |
Interesting. I thought I tried a similar approach but noticed the init function of the objects weren't always called on all platforms. Looks like they get around that by assigning the object to some global variable. I could try and test that approach again |
At your discretion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luca992
I looked at other modules and new changes.
Globally, I have no new questions.
I think to do this: you will make all the small edits that remain, after that, I merge your changes. Everything related to publishing, dokka, initializing engines, and js, I will issue it as an issue, if you want, you can take them to work. This will make it easier to pour in the changes and it will be more convenient for me to participate. What do you think?
multik-default/src/main/kotlin/org/jetbrains/kotlinx/multik/default/DefaultMath.kt
Outdated
Show resolved
Hide resolved
Sounds good to me. 👍 I'm still confused about layout of memory in complex arrays. But if you think what I did was wrong, addressing it as an issue works for me |
Also, I think I am going to remove the ThreadLocal annotations and just enable the new native memory model. It seems to me that fully adopting the new memory model is what most devs are doing these days. For reference: https://twitter.com/kpgalligan/status/1474101883686068227?s=20 Dealing with the difficult to resolve concurrent memory issues in the old memory model is annoying to say the least |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luca992
I'm merging your changes.
As I said, I created issues for a number of problems, including complex arrays. With complex arrays, nothing complicated, I can fix it myself. The principle of complex arrays is simple, the real and imaginary parts are sequentially stored there, that is, for each step it is x2.
There was a problem while running the tests. When calling the clean
task, I got an exception: java.lang.NullPointerException: destinationDir must not be null
. I found the corresponding issue in ktor, it will be necessary to upgrade to 1.6.20 where it was corrected.
Otherwise, the library passed the tests, everything is fine.
Okay great! Now that it's merged I could take a look at porting multik-native when I get a chance if you guys don't beat me to it. |
To port multik-native, you first need to figure out how to build OpenBLAS and bundle it all. |
Yeah, it looks simple enough to build a shared lib for each target. I'd probably just create a new "libs" folder in the root that contains the shared libs and the headers. Then link it up with kotlin cinterop |
Convert use of service loader to use standard reflection (probably wasn't necessary?)
Reflection for discovering Engines on native doesn't work so add an initEnginesProvider function that only has an implementation for native
updating //apply("$rootDir/gradle/publish.gradle") still needs to be done
There might be some fat jar issues. That probably should be looked into