Skip to content
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

Implement cuDNN activation functions. #33

Merged
merged 5 commits into from
Oct 21, 2018

Conversation

dan-zheng
Copy link
Collaborator

  • Add wrapper functions for cudnnActivationForward and
    cudnnActivationBackward.
  • Implement relu/tanh/sigmoid (original and gradient functions) using cuDNN, add tests.

TODO:

  • Support activations for non-4D tensors. This will likely require shape
    padding with "1" dimensions to work with the cuDNN API.

- Add wrapper functions for `cudnnActivationForward` and
  `cudnnActivationBackward`.
- Move `relu` to be backend-defined.
- Implement `relu` and `relu_grad` using cuDNN, add tests.
- Minor: change out-of-bounds indexing via `Dimensions.apply` to clearly
  throw `IndexOutOfBoundsException`.

TODO:
- Support `relu` for non-4D tensors. This will likely require shape
  padding with "1" dimensions to work with the cuDNN API.
- Implement other activation functions.
@dan-zheng dan-zheng requested a review from feiwang3311 October 21, 2018 20:10
}
}

override def tanh(x: Tensor) = x.map(s => Math.tanh(s).toFloat)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It'd be good to decouple these backend functions from Tensor methods (map and add_oneMinusSquare_mult).

Copy link
Owner

Choose a reason for hiding this comment

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

yes, I agree. We are sort things out as we encounter them.

@dan-zheng dan-zheng changed the title Start cuDNN activation function support. Implement cuDNN activation functions. Oct 21, 2018
I accidentally copied tanh's gradient.
@feiwang3311 feiwang3311 merged commit 90ca4ad into feiwang3311:master Oct 21, 2018
"CUDNN_CALL(cudnnActivationBackward(\n" +
" cudnnHandle, act_desc,\n" +
" ", one, ", x_desc, ", res.x.data, ", x_desc, ", res.d.data, ", x_desc, ", input.x.data, ",\n",
" ", zero, ", x_desc, ", inputGrad.data, "));\n" +
Copy link
Collaborator Author

@dan-zheng dan-zheng Oct 21, 2018

Choose a reason for hiding this comment

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

As suggested by @feiwang3311: rather than using beta = 0 and input.d += inputGrad, use beta = 1.
Same elsewhere (for conv2d, etc).
I'll take on this.

@TiarkRompf TiarkRompf mentioned this pull request Oct 22, 2018
18 tasks
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