René's URL Explorer Experiment


Title: Arrayfire -> glium interaction possible? · arrayfire/arrayfire-rust · Discussion #278 · GitHub

Open Graph Title: Arrayfire -> glium interaction possible? · arrayfire/arrayfire-rust · Discussion #278

X Title: Arrayfire -> glium interaction possible? · arrayfire/arrayfire-rust · Discussion #278

Description: Arrayfire -> glium interaction possible?

Open Graph Description: Hi, I'm trying to get arrayfire and glium to cooperate; Is that currently possible with both libraries as they are? or is there some lower level work that needs to be done? Basically trying to figu...

X Description: Hi, I'm trying to get arrayfire and glium to cooperate; Is that currently possible with both libraries as they are? or is there some lower level work that needs to be done? Basically trying to ...

Opengraph URL: https://github.com/arrayfire/arrayfire-rust/discussions/278

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"Arrayfire -> glium interaction possible?","text":"

Hi, I'm trying to get arrayfire and glium to cooperate; Is that currently possible with both libraries as they are? or is there some lower level work that needs to be done?

\n

Basically trying to figure out how to do this:

\n
let arr: Array<f32>\nglium::VertexBuffer::new_raw(display as &Facade, arr.device_ptr() ,bindings, arr.elements() * std::mem::size_of::<f32>()).unwrap()\n//or\nglium::buffer::Buffer::new<f32>(display as &Facade, arr.device_ptr(), BufferType::TextureBuffer, glium::buffer::BufferMode::Default)
\n

while keeping everything on the gpu and avoiding expensive gpu->cpu->gpu operations.

\n

Is this even possible? And if so, what steps need to be taken?
\nThanks!

","upvoteCount":2,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

@nodeSpace Yes, I believe it is completely possible to do that. However, it would require some additional helper code apart from using the libraries glium and arrayfire. arrayfire/forge essentially handles the same workflow(avoids via CPU data transfers) which is ArrayFire's graphics(OpenGL based) functionality provider.

\n

Let's say you are using CUDA backend of ArrayFire. Have a look at the functions from forge helper header: createGLBuffer, copyToGLBuffer, releaseGLBuffer for an idea on C++ code does it. You would need similar functions in rust that are written with glium as target. I think the following steps should essentially let you handle the OpenGL interop successfully.

\n
    \n
  1. Create a shared resource handle cudaGraphicsResource in rust using vertex buffer resource id returned by glium. Note that this vertex buffer's size in bytes should match the array you want to display. Matching data type is also important - Essentially what createGLBuffer does in forge project
  2. \n
  3. Copy data from CUDA device pointer to shared resource created in step (1). Note that this is also a device buffer sitting on GPU. So, you are essentially only doing a device-to-device memcopy which is many times faster than host-to-device/device-to-host copy. - Essentially what copyToGLBuffer does in forge project.
  4. \n
  5. Release the shared resource handle during program exit or when you are done using it.
  6. \n
\n

This workflow would need CUDA rust API. You can take a look at arrayfire's CUDA/OpenCL interop crates to see what we use in those projects. Any crate exposes CUDA API will do the job of creating/copying/releasing the shared CUDA-OpenGL resource.

\n\n

The entire process remains the same if you use OpenCL backend with OpenCL APIs replacing their respective CUDA APIs.

\n

Updated

\n

My mistake, I didn't mention one additional detail regarding OpenCL, you would need to some additional modifications to your code.

\n

Firstly, use ArrayFire's OpenCL interop crate - https://github.com/arrayfire/arrayfire-rust/tree/master/opencl-interop

\n

You need to use some crate that enables you use OpenCL API in rust, you can use the OpenCL crate that af-opencl-interop crate uses for easy integration.

\n

The following are the additional steps:

\n
    \n
  1. create an OpenCL context using OpenGL context handle
  2. \n
  3. Now add the device on which context from step (1) is created and the context itself to ArrayFire device manager - Please look at the documentation of af_opencl_interop for relevant functions.
  4. \n
  5. Set device to this newly added device in ArrayFire and use that for computations.
  6. \n
\n

With the above setup done before any devices are used by OpenCL in ArrayFire. You should be able to share the OpenCL-OpenGL context. There are some examples in af-opencl-interop crate, please have a look - they might help with figuring out the opencl context creation etc.

","upvoteCount":2,"url":"https://github.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-348321"}}}

route-pattern/_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format)
route-controllervoltron_discussions_fragments
route-actiondiscussion_layout
fetch-noncev2:3f934123-352c-8152-3024-4220340db5d7
current-catalog-service-hash9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be
request-idBC5A:27C189:5E17:74DF:696E637E
html-safe-nonce3052330059fd065ef675bb740575b72c72f060bfa500f6bac7904c92c5e06dbe
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzVBOjI3QzE4OTo1RTE3Ojc0REY6Njk2RTYzN0UiLCJ2aXNpdG9yX2lkIjoiODY0MjY3NzU2NTI1NzgzNTM5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac06ec54b7c8f18d5f10b16087269716b1553988550c08e2cfaf88870a2c4c0892
hovercard-subject-tagdiscussion:2815976
github-keyboard-shortcutsrepository,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/discussions_fragments/discussion_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/arrayfire/arrayfire-rust/278/discussion_layout
twitter:imagehttps://opengraph.githubassets.com/2aa007abb8e5468289da672056b071f0728ed0c57982e151face5b2021e17fc5/arrayfire/arrayfire-rust/discussions/278
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2aa007abb8e5468289da672056b071f0728ed0c57982e151face5b2021e17fc5/arrayfire/arrayfire-rust/discussions/278
og:image:altHi, I'm trying to get arrayfire and glium to cooperate; Is that currently possible with both libraries as they are? or is there some lower level work that needs to be done? Basically trying to figu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None99a4a74f92e7618f6e15b4dbb9f4470c8d31701a90d89c21ff31970528b7f0c3
turbo-cache-controlno-preview
go-importgithub.com/arrayfire/arrayfire-rust git https://github.com/arrayfire/arrayfire-rust.git
octolytics-dimension-user_id5395442
octolytics-dimension-user_loginarrayfire
octolytics-dimension-repository_id35817370
octolytics-dimension-repository_nwoarrayfire/arrayfire-rust
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id35817370
octolytics-dimension-repository_network_root_nwoarrayfire/arrayfire-rust
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseef0d97829e997c64864f25a29b00067f5dc3a4c4
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Farrayfire%2Farrayfire-rust%2Fdiscussions%2F278
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Farrayfire%2Farrayfire-rust%2Fdiscussions%2F278
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fdiscussions_fragments%2Fdiscussion_layout&source=header-repo&source_repo=arrayfire%2Farrayfire-rust
Reloadhttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
Reloadhttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
Reloadhttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
arrayfire https://patch-diff.githubusercontent.com/arrayfire
arrayfire-rusthttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Farrayfire%2Farrayfire-rust
Fork 58 https://patch-diff.githubusercontent.com/login?return_to=%2Farrayfire%2Farrayfire-rust
Star 827 https://patch-diff.githubusercontent.com/login?return_to=%2Farrayfire%2Farrayfire-rust
Code https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust
Issues 22 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/issues
Pull requests 2 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/pulls
Discussions https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions
Actions https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/actions
Projects 1 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/projects
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/security
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
Insights https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/pulse
Code https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust
Issues https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/issues
Pull requests https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/pulls
Discussions https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions
Actions https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/actions
Projects https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/projects
Security https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/security
Insights https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/pulse
Answered https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-348321
9prady9https://patch-diff.githubusercontent.com/9prady9
nodeSpace https://patch-diff.githubusercontent.com/nodeSpace
Q&Ahttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/categories/q-a
Arrayfire -> glium interaction possible? https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#top
nodeSpace https://patch-diff.githubusercontent.com/nodeSpace
Answered https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-348321
9prady9https://patch-diff.githubusercontent.com/9prady9
Return to tophttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#top
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
nodeSpace https://patch-diff.githubusercontent.com/nodeSpace
Feb 5, 2021 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussion-2815976
Give feedback.https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
9prady9 https://patch-diff.githubusercontent.com/9prady9
Feb 8, 2021 https://github.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-348321
@nodeSpacehttps://github.com/nodeSpace
arrayfire/forgehttps://github.com/arrayfire/forge
createGLBufferhttps://github.com/arrayfire/forge/blob/master/include/fg/compute_copy.h#L140
copyToGLBufferhttps://github.com/arrayfire/forge/blob/master/include/fg/compute_copy.h#L165
releaseGLBufferhttps://github.com/arrayfire/forge/blob/master/include/fg/compute_copy.h#L158
View full answer https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-348321
Oldest https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278?sort=old
Newest https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278?sort=new
Top https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278?sort=top
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
9prady9 https://patch-diff.githubusercontent.com/9prady9
Feb 8, 2021 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-348321
@nodeSpacehttps://github.com/nodeSpace
arrayfire/forgehttps://github.com/arrayfire/forge
createGLBufferhttps://github.com/arrayfire/forge/blob/master/include/fg/compute_copy.h#L140
copyToGLBufferhttps://github.com/arrayfire/forge/blob/master/include/fg/compute_copy.h#L165
releaseGLBufferhttps://github.com/arrayfire/forge/blob/master/include/fg/compute_copy.h#L158
ArrayFire-CUDA Interop Cratehttps://crates.io/crates/af-cuda-interop
ArrayFire-OpenCL Interop Cratehttps://crates.io/crates/af-opencl-interop
https://github.com/arrayfire/arrayfire-rust/tree/master/opencl-interophttps://github.com/arrayfire/arrayfire-rust/tree/master/opencl-interop
documentation of af_opencl_interophttps://arrayfire.org/arrayfire-rust/af_opencl_interop/index.html
Give feedback.https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/nodeSpace
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
nodeSpacehttps://patch-diff.githubusercontent.com/nodeSpace
Feb 11, 2021 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-358457
Give feedback.https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/9prady9
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
9prady9https://patch-diff.githubusercontent.com/9prady9
Feb 11, 2021 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-358572
Give feedback.https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/nodeSpace
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
nodeSpacehttps://patch-diff.githubusercontent.com/nodeSpace
Feb 12, 2021 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-361415
Give feedback.https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/9prady9
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
9prady9https://patch-diff.githubusercontent.com/9prady9
Feb 12, 2021 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-361608
Give feedback.https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/nodeSpace
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
Please reload this pagehttps://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
nodeSpacehttps://patch-diff.githubusercontent.com/nodeSpace
Feb 13, 2021 https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278#discussioncomment-364500
#282 (comment)https://github.com/arrayfire/arrayfire-rust/issues/282#issue-807655490
Give feedback.https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
9prady9https://patch-diff.githubusercontent.com/9prady9
Sign up for freehttps://patch-diff.githubusercontent.com/join?source=comment-repo
Sign in to commenthttps://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Farrayfire%2Farrayfire-rust%2Fdiscussions%2F278
🙏 Q&A https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/categories/q-a
https://patch-diff.githubusercontent.com/nodeSpace
https://patch-diff.githubusercontent.com/9prady9
https://patch-diff.githubusercontent.com/arrayfire/arrayfire-rust/discussions/278
https://patch-diff.githubusercontent.com/settings/replies?return_to=1
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.