Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

An error occurred while calculating the square of ndarray by using gpu context #9455

Closed
shitou112 opened this issue Jan 16, 2018 · 5 comments

Comments

@shitou112
Copy link

1. When I use a**2 to compute square, I encounter an error.

Input: a = nd.array([-1], mx.gpu())
       a ** 2

Output: [ nan]
        <NDArray 1 @gpu(0)>

2. However, when using ctx=mx.cpu(), the result is right.

Input: a = nd.array([-1], mx.cpu())
       a ** 2

Output: [ 1.]
        <NDArray 1 @cpu(0)>

3. when I use a*a to compute square, the result is also right.

Input: a = nd.array([-1], mx.gpu())
       a * a

Output: [ 1.]
        <NDArray 1 @gpu(0)>
@reminisce
Copy link
Contributor

Since running operators in Python is async with backend, you need to wait until the computation of pow is finished. Try this: (a**2).asnumpy().

@shitou112
Copy link
Author

01

I try asnumpy() function. But the result is wrong.

@reminisce
Copy link
Contributor

That's very strange. I couldn't reproduce the problem you encountered. Does it happen to other versions of MXNet on your machine?

@shitou112
Copy link
Author

Thank you a lot. I upgrade mxnet and the result is right.

@vdantu
Copy link
Contributor

vdantu commented Feb 27, 2018

@sandeep-krishnamurthy : please label this "Question" and close this. This seems to have been resolved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@sandeep-krishnamurthy @reminisce @shitou112 @vdantu and others