Skip to content

Fixed assignment with idx after changing device #3420

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

Conversation

willyborn
Copy link
Contributor

After changing device, the assignment with index generates an exception (Invalid Memory Object when calling clSetkernelArg)

Description

Code to reproduce:
#include <arrayfire.h>

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

const int idx[]{1, 3};

af::setDevice(0);
af::array d0_idx(2, idx, afHost);
af::array d0_in(10, 10);
d0_in(d0_idx) = 1.0;  					// success

af::setDevice(1);
af::array d1_idx(2, idx, afHost);
af::array d1_in(10, 10);
d1_in(d1_idx) = 2.0;  					// <- exception

}

Output:
ArrayFire v3.9.0 (OpenCL, 64-bit Windows, build b184388)
[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: True
OpenCL Error (-38): Invalid Memory Object when calling clSetKernelArg

Cause:
For Assignments on arrays with indexes, empty indexes are internally generated.
For each empty index, an empty device buffer is used as parameter to the assign kernel.
Since the empty device buffer remains unchanged, the resulting buffer of the 1st time is cached.
The cached device buffer is however dependent on the context, explaining why it failed after setdevice(1) (=changed context).

Changes to Users

1 bug less.

Checklist

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

@umar456 umar456 merged commit 8e3d1fa into arrayfire:master May 12, 2023
@willyborn willyborn deleted the assignMultiDevs 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