Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Random on multiple devices #3421

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

Merged
merged 1 commit into from
May 12, 2023
Merged

Conversation

willyborn
Copy link
Contributor

randu (special engine) fails when called after changing device

Description

Code to reproduce:
#include <arrayfire.h>

int main(int, char**) {
// Initialize the kernel array just once
af::info();

af::setDevice(0);
af::setDefaultRandomEngineType(AF_RANDOM_ENGINE_MERSENNE);
af::array d0_in{af::randu(af::dim4(10,10))};				// success

af::setDevice(1);
af::setDefaultRandomEngineType(AF_RANDOM_ENGINE_MERSENNE);
af::array d1_in{af::randu(af::dim4(10, 10))};				// <- exception
af::print("dev 1", d1_in);

}

Output:
ArrayFire v3.9.0 (OpenCL, 64-bit Windows, build 64586e0)
[0] AMD: Spectre, 6571 MB -- OpenCL 2.0 AMD-APP (3224.5) -- Device driver 3224.5 -- FP64 Support: True
-1- NVIDIA: NVIDIA GeForce GTX 750 Ti, 2047 MB -- OpenCL 3.0 CUDA -- Device driver 531.61 -- FP64 Support:
OpenCL Error (-38): Invalid Memory Object when calling clSetKernelArg

Cause:
The defaultRandomEngine is cached for each thread.
The MERSENNE type engine, uses device buffers to store his state.
By changing device, the buffers on the previous device are no longer usable.

Can this PR be backported to older versions? yes

Changes to Users

1 bug less

Checklist

  • Rebased on latest master
  • Code compiles
  • Tests pass
  • Functions added to unified API
  • Functions documented

Comment on lines 148 to 151
/*
thread_local auto *re = new RandomEngine;
*r = static_cast<af_random_engine>(re);
*r = static_cast<af_random_engine>(re);
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove these comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@willyborn willyborn force-pushed the randomMultiDevices branch from 19dcf2c to a9b2045 Compare May 11, 2023 22:09
@umar456 umar456 merged commit 11af307 into arrayfire:master May 12, 2023
@willyborn willyborn deleted the randomMultiDevices branch May 15, 2023 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.