https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
mathematics
  • a

    alex cole

    11/25/2020, 5:54 PM
    kmath getting started and how to use examples. With kmath there seems to be very little documentation for getting started and transitioning from numpy to kmath. Is there any guide for this such as how to do a linspace function?
    a
    b
    • 3
    • 11
  • i

    Iaroslav Postovalov

    11/29/2020, 1:53 PM
    Hello, @breandan . We are experiencing problems with stable access to Princess library. Is it mandatory to use KotlinGrad
    SFun
    related interfaces? I suppose this library can either be published to more stable Maven repository or removed from KotlinGrad core module, then extracted to a separate module that does use Princess.
    b
    • 2
    • 2
  • a

    altavir

    11/30/2020, 8:49 AM
    @alex cole By the way, I just rememebered that I had an article about migration from Python notebook to Kotlin notebook: https://levelup.gitconnected.com/a-first-dive-into-kotlin-jupyter-eab43dca9472. The visualization and tooling became much better since then.
    a
    • 2
    • 5
  • i

    Iaroslav Postovalov

    12/08/2020, 8:41 AM
    Just sent a PR to KMath that replaces syntax of dynamic calls of algebraic operations from
    algebra.binaryOperation("+", 1, 1)
    to
    algebra.binaryOperation("+")(1, 1)
    . This feature also affects ASM code generation so generated classes store functional objects returned by
    *aryOperation("...")
    methods instead of storing algebraic structures.
    a
    • 2
    • 1
  • i

    Iaroslav Postovalov

    12/08/2020, 8:41 AM
    https://github.com/mipt-npm/kmath/pull/162/files
    👍 2
    a
    b
    • 3
    • 12
  • z

    zain

    12/11/2020, 5:04 AM
    Hi @altavir all the other issues are resolved while integrating the Plotly library. I had another question related to it I have tried to articulate it over here. https://stackoverflow.com/questions/65246043/how-to-plot-a-coordinate-graph-using-plotly-kt-for-y-1-x Please let me know once you are free.
    a
    • 2
    • 2
  • a

    alex cole

    12/28/2020, 2:37 AM
    I have been working on putting together a basic numerical methods library and was wondering what I could do to build an api primarily for this linear regression class. Also what is the best way to assert equals when the known values differ in significant figures from the actualValue. https://github.com/jalexcole/NumericalMethods/blob/master/src/main/kotlin/curveFitting/regression/LinearRegression.kt
    a
    • 2
    • 12
  • b

    breandan

    01/05/2021, 1:56 AM
    Did some experiments with type classes. It's a nice pattern for abstract algebra: https://github.com/breandan/kotlingrad/blob/master/core/src/main/kotlin/edu/umontreal/kotlingrad/typelevel/TypeClassing.kt
    ❤️ 1
    a
    • 2
    • 9
  • a

    alex cole

    01/14/2021, 12:05 AM
    Is there a preferred jdk, garbage collector, etc. that is best used for numerical loads?
    a
    i
    • 3
    • 14
  • a

    altavir

    01/22/2021, 5:35 AM
    message has been deleted
    • 1
    • 1
  • a

    Andrew

    01/23/2021, 4:36 PM
    I'm pretty dumb when it comes to software licenses. What are the implications of porting and heavily modifying something like BigInteger from the openJdk source to kotlin? Is that allowed? Do I just need to keep the license part, and does that apply to my entire project or just that class?
    a
    • 2
    • 8
  • a

    altavir

    01/24/2021, 7:37 AM
    By the way, here are the results of naive tests (no JMH, so be careful with conclusions) on GraalVM11:
    Boxing addition completed in 22157 millis
    Specialized addition completed in 1840 millis
    Nd4j specialized addition completed in 1309 millis
    Viktor addition completed in 1966 millis
    Parallel stream addition completed in 1457 millis
    Automatic field addition completed in 1773 millis
    Lazy addition completed in 14157 millis
    ND4J uses OpenBlas under the hood. And I think @Iaroslav Postovalov told me that is uses parallel execution. I wonder if there is a large overhead on top of BLAS. Because the results are very close.
    i
    • 2
    • 5
  • b

    breandan

    01/31/2021, 3:48 PM
    Interesting, it seems the term "field" used in algebra and physics are related. To check if a set of matrices is an algebraic field, it must be closed under (+, -, *), have additive identity, multiplicative identity and commutativity, and a multiplicative inverse. The term vector/matrix field used differential geometry and physics is a actually a vector/matrix space over a field, i.e. the product of a field and a vector/matrix space, whose elements are vectors/matrices. The type signatures are slightly different. Algebraic field: ×: 𝔽 × 𝔽 → 𝔽 +: 𝔽 × 𝔽 → 𝔽 Vector field: +: 𝔽ⁿ × 𝔽ⁿ → 𝔽ⁿ ⋅: 𝔽 × 𝔽ⁿ → 𝔽ⁿ cc: @altavir @dievsky
    a
    р
    a
    • 4
    • 33
  • a

    altavir

    02/03/2021, 4:05 PM
    Is the@Aleksei Dievskii the correct tag-name for Alexei, I think.
    👍 1
    a
    • 2
    • 1
  • b

    breandan

    02/06/2021, 8:27 PM
    Happy to see experimental support for sealed interfaces arriving in 1.5. Together with multiple inheritance and default methods, this opens up a path to implementing algebraic data types: https://blog.jetbrains.com/kotlin/2021/02/new-language-features-preview-in-kotlin-1-4-30/#sealed-interfaces AFAICT, this feature offers the same benefits of multiple receivers without needing to introduce a new syntax. Or is there some feature that KEEP-176 proposes which could not be implemented using the type class pattern on a sealed interface?
    i
    a
    • 3
    • 11
  • a

    altavir

    02/09/2021, 2:05 PM
    Somebody ever tried to solve the problem of the classes schedule optimization? I not it is not simple, but I know it could be solved. I asked different students to do the algorithm for that for years, but nobody managed to do that. And it requires more knowledge of descreete optimization, than I have.
    b
    l
    • 3
    • 4
  • a

    altavir

    02/17/2021, 1:51 PM
    message has been deleted
    :kotlin-intensifies: 3
    🐍 1
    a
    • 2
    • 4
  • a

    altavir

    02/21/2021, 2:44 PM
    Following the week of mathematical releases in Kotlin, I am happy to present KMath release 0.2.0: https://github.com/mipt-npm/kmath/releases/tag/v0.2.0. The release contains numerous new features and API fixes as well as new pacckage name (
    space.kscience
    ) and a completely new understanding of library aims. KMath does not want to follow numpy path and provide bindings for a single implementation of nd-arrays and numerics. Instead, we are working on a Kotlin-first API, that allows us to better tap into the kotlin lagnuage potential and allow to create the same or similar API to different existing libraries, so one could easily switch implementations withot a lot of changes in the code. Also we provide simple multiplatform implementations for people, who do not need super-optimized performance. Those basic implementations are thereby referenced as kmath-core to avoid confusion with library bindings like kmath-commons, kmath-ejml, kmath-viktor etc. The important feature of the new release is the new documenation and stability policy. Ecch module has a Maturity level shown in the documentation: • PROTOTYPE - both idea an the implementation may change. • EXPERIMENTAL - we have an idea how it should look like, but implementation could change in minor versions. • DEVELOPMENT - API compatibility between monitor versions is controlled via https://github.com/Kotlin/binary-compatibility-validator. • STABLE - no module has reached this stage yet, but we plan to enforce production-ready stability guarantees. New documentation plugin allows to maintain the list of module features. Here is the list of key feature modules: • kmath-core Core classes, algebra definitions, basic linear algebra, nd-structures, expressions etc. • kmath-commons Bindings for Commons-math library. • kmath-complex Complex numbers and quternions (separated from core in this release. • kmath-nd4j ND4J bindings for nd-structures implementation. • kmath-ejml EJML bindings for linear algebra implementatiion. • kmath-viktor JetBrains Research Viktor bindings for real-valued nd-structures. • kmath-histograms Univariate and multivariate histograms. • kmath-ast MST (mathematical syntax tree) definition, JIT expression compilation with ASM on JVM and JS interpreter on JS. Symbolic algebra. • kmath-kotlingrad Automatic differentiation via MST and kotlingrad library. The significant part of the release is done by @Iaroslav Postovalov. I would also like to thank a lot of people, including @breandan, @Peter Klimai, @elizarov , @Ролан, @Aleksei Dievskii, @roman.belov, @Pavel Gorgulov and numerous others (I can't remember them all, we need a list), for discussions and contributions. The project is supported by the JetBrains Research.
    🎉 12
    z
    e
    • 3
    • 10
  • a

    altavir

    03/08/2021, 9:24 AM
    @Aleksei Dievskii A question about algebras. Could you give an example of a
    Space
    which does not have a numeric scaling of its members? We have some problems bringing KMath inheritance model in check and keep it practical so I am thinkgin about different architectural approaches.
    a
    р
    • 3
    • 43
  • b

    breandan

    03/22/2021, 7:15 PM
    This Friday Mar. 26th at 12:00 EDT / 16:00 UTC we are hosting Erik Meijer at our reading group. He will discuss some mathematical topics, possibly related to Kotlin somehow. In case anyone here is available, please feel welcome to drop by and say hello! It would be great to have your feedback.
    Inside Every Calculus Is A Little Algebra Waiting To Get Out
    Because of deep learning, there has been a surge in interest in automatic differentiation, especially from the functional programming community. As a result there are many recent papers that look at AD from a Category Theory perspective. However, Category Theorists have already been looking at differentiation and calculus in general since the late 60’s in the context of Synthetic Differential Geometry, but it seems that this work is largely ignored by those interested in AD. In this talk, we will provide a gentle introduction to the ideas of SDG, by relating them to dual numbers, and show how it provides a simple and purely algebraic approach to (automatic) differentiation.
    https://mcgill.zoom.us/j/89551971819
    👀 1
    👍 1
    a
    р
    • 3
    • 5
  • a

    altavir

    03/25/2021, 5:01 PM
    An article on Viktor: https://blog.jetbrains.com/kotlin/2021/03/viktor-efficient-vectorized-computations-in-kotlin/
    👍 7
    👍🏼 2
    :tnx: 4
    z
    a
    • 3
    • 2
  • i

    Iaroslav Postovalov

    03/31/2021, 12:41 PM
    I've created Jupyter integration supporting the display of KMath's MST objects.
    👍 12
    i
    a
    • 3
    • 7
  • a

    altavir

    04/16/2021, 12:53 PM
    @Ролан You will probably like this one. A universal multiplatform Gauss-Legendre numerical integration, which could work on
    StructureND
    .
    🙌 1
    • 1
    • 2
  • z

    Zhelenskiy

    04/16/2021, 7:19 PM
    Current implementation of BigInteger implementation and power is slow so I provided it with corresponding tests: PR .
    👍 2
    a
    b
    • 3
    • 23
  • f

    Filipe Duarte

    04/17/2021, 1:25 AM
    Operator overload of Nd4j INDArray #kotlindl
    a
    • 2
    • 17
  • a

    altavir

    04/30/2021, 11:38 AM
    @Pavel Gorgulov @zaleslaw I would like to invite you to a public review of our (aniversary #300) PR by @Ролан and his interns: https://github.com/mipt-npm/kmath/pull/300. The PR introduces API and basic multiplatform implementation of tensor algebra. It is huge. Also I would like to start some kind of discusstion about what features do we want from tensors mathematics. Current implementation has one significant benifit, it works on top of generic KMath
    StructureND
    meaning it is compatible with any other library which have binings for KMath and one could pass those structures around between different implementations (like Viktor for example). @Ролан I also would like for your students to make a public seminar (in English) describing what have they done and sharing their experience.
    👌 1
    🤘 5
    :kotlin-intensifies: 6
    👍 2
    z
    р
    • 3
    • 2
  • i

    Iaroslav Postovalov

    05/02/2021, 7:03 PM
    We just merged Jupyter integration to the KMath
    dev
    branch.
    🙌 1
    р
    a
    i
    • 4
    • 10
  • i

    Iaroslav Postovalov

    05/02/2021, 7:21 PM
    👍 7
    • 1
    • 1
  • z

    Zhelenskiy

    05/06/2021, 4:45 PM
    One of the problems of many big int implementations is that they work extremely slow for not so big numbers.. I think it is a common case when number of really big numbers operations is slow so real numbers can be used with longs in most cases and overflows are rare. So, I created a demo to demonstrate it. I didn't compare with KMath's implementation but compared with java.lang.Math's one. Even when I give no helping info, it is about 4 times faster. When I used explicit
    LongBased
    type, it became 10 faster than generic one. The speed was the same with just manual long checking. This is because I used inline types. However, it is still a lot slower than just pure usage of
    Int
    s and `Long`s. But that may be achieved if the code is run under HotSpot and it decides to use intrinsic there. Here is the repo: https://github.com/zhelenskiy/BigInteger/tree/main.
    i
    a
    • 3
    • 78
  • р

    Ролан

    05/07/2021, 5:51 AM
    Thanks to Andrey Kislitsin, we have a example of a neural network on kotlin mutliplatform using kmath's tensors and including both forward and backward pass (so you can train it everywhere) https://github.com/mipt-npm/kmath/blob/feature/tensor-algebra/examples/src/main/kotlin/space/kscience/kmath/tensors/NeuralNetwork.kt
    🔥 1
    :party-parrot: 2
    🙌 2
    h
    a
    i
    • 4
    • 29
Powered by Linen
Title
р

Ролан

05/07/2021, 5:51 AM
Thanks to Andrey Kislitsin, we have a example of a neural network on kotlin mutliplatform using kmath's tensors and including both forward and backward pass (so you can train it everywhere) https://github.com/mipt-npm/kmath/blob/feature/tensor-algebra/examples/src/main/kotlin/space/kscience/kmath/tensors/NeuralNetwork.kt
🔥 1
:party-parrot: 2
🙌 2
h

Hampus Londögård

05/07/2021, 6:02 AM
Awesome! How big is the performance penalty in comparison to using Python (or well, Python DSL to Torch/TF one could call it as you don’t really write python 😅)? Are the tensors ever shuffled to the JVM or they stay native until you try to print?
р

Ролан

05/07/2021, 6:29 AM
no it's all KMP including tensors, no dependencies on anything and you can run it anywhere KMP works. In terms of performance, that wasn't our concern yet.
h

Hampus Londögård

05/07/2021, 6:31 AM
KMP = Kotlin Multiplatform? I ment more in the idea, do you shuffle the tensors into DoubleArrays or do you keep them as native (like pytorch and others usually do) so that the operations happens through the original C/C++-code?
р

Ролан

05/07/2021, 6:32 AM
Tensors are backed by
DoubleArray
indeed
there is nothing native
in that sense
yes for kotlin multiplatform, and that was the point of the exercise. Now perfomance wise we need to see, but I think we look more for functionality right now. You won't train mega networks in a browser after all.
h

Hampus Londögård

05/07/2021, 6:35 AM
Oh, I thought this was related to your previous pytorch contribution 😄 But this is really cool, seems simple enough to code that you could easily fit a framework on top which abstracts it into using lambda functions. Typed lambda functions + DL is something I’ve wanted for a while, Python simply doesn’t cut it. Really cool contribution! (unrelated) Do you happen to know if there’s any progress on supporting the new Vector-api on the JVM for kmath?
р

Ролан

05/07/2021, 6:43 AM
Thanks )), no the pytorch story is perpendicular to that. In fact, we wanted the user to be able to prototype simple things in a lightweight framework before getting monsters like pytorch, tf or dl4j. I am sorry for the vector-api, I haven't heard anything yet
👍 1
a

altavir

05/07/2021, 7:30 AM
Current work i the prelude to pytorch integration. We need to understand how to make better API for that. As for performance, it is not yet optimized but after optimization I expect the difference with native solution less than factor of 3. It is also possible to make easy parallelization and lazy computation optimization, so we can even win in some places.
As for vectors, do you mean https://openjdk.java.net/jeps/338? It is on the roadmap, but our current research show that there is already good automatic vectorization in latest JVMs, including GraalVM. Also there is Viktor project and we have bindings for it (not for tensors though).
h

Hampus Londögård

05/07/2021, 7:37 AM
That’s the one yeah. Agreed auto-vectorization is good. But when you know you want it from the get-go it could make sense to code for it, rather than hoping the JVM is smart or that the loop simply runs enough times and is tight 🙂 F64 is more precision than I would’ve preferred hehe.
I’ll most likely be migrating my project (londogard-nlp-toolkit) to kmath in the future, I really like the idea of swapping backends. For now I’ve simply used Ejml (which you wrap) because there’s no expensive native-interop when running single math operations. But once I introduce ML-models & DL I’ll have to use something else I think, at least for the DL-models.
a

altavir

05/07/2021, 7:39 AM
Indeed. The issue is here: https://github.com/mipt-npm/kmath/issues/249. It is marked as waiting for external contributions. so I hope some students will work on it soon. Meanwhile, as said, we get very good results with GraalVM automatic vectorization.
р

Ролан

05/07/2021, 8:26 AM
@altavir talking about performance is misleading here. Deep Learning is just made for GPU. (I am also advocating that beyond DL but that's another story). We are trying to offer some functionality in places where you cannot afford huge GPUs - and there are really a lot of such applications. But you have to forget about performance.
a

altavir

05/07/2021, 8:26 AM
Indeed, I was talking about CPU only. Doing GPU directly from JVM would be hard.
i

Iaroslav Postovalov

05/07/2021, 9:51 PM
It's simply impossible because Cuda like APIs can't be created natively for JVM, so the FFI overhead in different forms is unavoidable.
a

altavir

05/08/2021, 5:45 AM
It is possible for example with http://www.jcuda.org/. You can't create shared memory with the gpu anyway. But the work is tedious. They are experimenting with it right now in MultiK.
i

Iaroslav Postovalov

05/08/2021, 9:17 AM
It is FFI, too.
р

Ролан

05/08/2021, 8:29 PM
@altavir those are just java bindings to C wrappers of CUDA libraries, you still cannot integrate your own CUDA kernels like you would in python or C++. You would have to pass by JNI with all the pain.
a

altavir

05/08/2021, 9:18 PM
I've actually used opencl bindings and it does not require jni. As for object copy, you need to do that anyway to work with gpu.
Here is pretty recent article: https://blogs.oracle.com/javamagazine/programming-the-gpu-in-java
р

Ролан

05/09/2021, 6:06 AM
Of course with OpenCL you can send your shader programs from the JVM - they are just strings. In C++ you can use
boost_compute
namespace bc = boost::compute;
auto src_code = std::string_view{
"float circle_area_gpu(Circle c) { "
" float pi = 3.14f;
"
" return c.r * c.r * pi;
"
"}
"
};
auto circle_area_gpu = bc::make_function_from_source<float(Circle)> (
"circle_area_gpu", src_code.data()
);
But CUDA is very different: https://gist.github.com/grinisrit/280e4f14b17fe5ee37e2e254700d9fd0
a

altavir

05/09/2021, 6:16 AM
Yes and things like aparapi do the same for Java. I think there is some kind of idea to use Kotlin IR to produce kernels for CUDA/OpenCL, but it is not implemented yet.
р

Ролан

05/09/2021, 6:17 AM
Yes, I was looking at TornadoVM as well, it looks great
a

altavir

05/09/2021, 6:19 AM
I've never used it. At a time when I played with OpenCL, it has only first appeared. But basically it is the same idea as in your sample, we generate kernels from the Java bytecode dynamically. Kotlin IR would be even more avanced in this regard since it is higher level.
р

Ролан

05/09/2021, 6:20 AM
I don't know whether TornadoVM or Aparapi somehow integrade nvcc compilation on the fly like numba does in python, or maybe it's all OpenCL
a

altavir

05/09/2021, 6:20 AM
🤷‍♂️
View count: 5