tqchen commented on a change in pull request #5913:
URL: https://github.com/apache/incubator-tvm/pull/5913#discussion_r444982859
##########
File path: src/runtime/ndarray.cc
##########
@@ -190,6 +193,49 @@ NDArray NDArray::Empty(std::vector<int64_t> shape,
DLDataType dtype, DLContext c
return ret;
}
+NDArray NDArray::NonEmpty(std::vector<int64_t> shape, DLDataType dtype,
DLContext ctx) {
+ NDArray ret = Internal::Create(shape, dtype, ctx);
+ NDArray dummy_cpu_arr = Internal::Create(shape, dtype, {kDLCPU, 0});
+
+ // setup memory content
+ size_t size = GetDataSize(ret.get_mutable()->dl_tensor);
+ size_t alignment = GetDataAlignment(ret.get_mutable()->dl_tensor);
+ dummy_cpu_arr.get_mutable()->dl_tensor.data =
+ DeviceAPI::Get(dummy_cpu_arr->ctx)
+ ->AllocDataSpace({kDLCPU, 0}, size, alignment, dummy_cpu_arr->dtype);
+ size_t elem_cnt = 1;
+ for (tvm_index_t i = 0; i < dummy_cpu_arr->ndim; ++i) {
+ elem_cnt *= static_cast<size_t>(dummy_cpu_arr->shape[i]);
+ }
+
+ std::random_device rd;
Review comment:
It is not wise to create a random device everytime a function is called.
Since PRNG requires us to use a consistent random number devices through out
multiple calls, consider merge the logic with
https://github.com/apache/incubator-tvm/blob/master/src/runtime/contrib/random/random.cc
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]