You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2020/06/18 12:28:30 UTC
[singa] branch dev updated: fix gaussian
CURAND_STATUS_LENGTH_NOT_MULTIPLE
This is an automated email from the ASF dual-hosted git repository.
wangwei pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/singa.git
The following commit(s) were added to refs/heads/dev by this push:
new 2d28b11 fix gaussian CURAND_STATUS_LENGTH_NOT_MULTIPLE
new 8656a4c Merge pull request #729 from dcslin/gaussian
2d28b11 is described below
commit 2d28b113730f8ac2e00497857ced80e8f4e8aab9
Author: dcslin <13...@users.noreply.github.com>
AuthorDate: Fri Jun 12 01:57:59 2020 +0000
fix gaussian CURAND_STATUS_LENGTH_NOT_MULTIPLE
---
src/core/tensor/tensor_math_cuda.h | 11 ++++++++++-
test/python/test_tensor.py | 7 +++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/core/tensor/tensor_math_cuda.h b/src/core/tensor/tensor_math_cuda.h
index bcc97fb..f331cd7 100644
--- a/src/core/tensor/tensor_math_cuda.h
+++ b/src/core/tensor/tensor_math_cuda.h
@@ -802,7 +802,16 @@ void Gaussian<float, lang::Cuda>(const float mean, const float std, Tensor* out,
auto rgen = ctx->curand_generator;
float* outPtr = static_cast<float*>(out->block()->mutable_data());
const size_t num = out->Size();
- CURAND_CHECK(curandGenerateNormal(rgen, outPtr, num, mean, std));
+
+ // CURAND_STATUS_LENGTH_NOT_MULTIPLE
+ if (num % 2 != 0) {
+ Tensor tmp(Shape{num + 1}, out->device());
+ float* outPtr_tmp = static_cast<float*>(tmp.block()->mutable_data());
+ CURAND_CHECK(curandGenerateNormal(rgen, outPtr_tmp, num + 1, mean, std));
+ CopyDataToFrom(out, tmp, num, 0, 0);
+ } else {
+ CURAND_CHECK(curandGenerateNormal(rgen, outPtr, num, mean, std));
+ }
}
// =========================Blas operations==================================
diff --git a/test/python/test_tensor.py b/test/python/test_tensor.py
index a3e4b2c..9ba2899 100644
--- a/test/python/test_tensor.py
+++ b/test/python/test_tensor.py
@@ -467,6 +467,13 @@ class TestTensorMethods(unittest.TestCase):
def test_matmul_transpose_gpu(self):
self._matmul_transpose_helper(gpu_dev)
+ @unittest.skipIf(not singa_api.USE_CUDA, 'CUDA is not enabled')
+ def test_gaussian_gpu(self, dev=gpu_dev):
+ x = tensor.Tensor((3, 5, 3, 5), device=dev)
+ x.gaussian(0, 1)
+ x = tensor.Tensor((4, 5, 3, 2), device=dev)
+ x.gaussian(0, 1)
+
if __name__ == '__main__':
unittest.main()