forked from mindspore-Ecosystem/mindspore
commit
92c7eeb24d
|
@ -163,7 +163,7 @@ int KernelMod::Resize(const BaseOperatorPtr &base_operator, const std::vector<Ke
|
|||
shape.empty() ? type_size : std::accumulate(shape.begin(), shape.end(), type_size, std::multiplies<size_t>());
|
||||
tensor_size = std::max(tensor_size, type_size);
|
||||
}
|
||||
input_size_list_.emplace_back(tensor_size);
|
||||
(void)input_size_list_.emplace_back(tensor_size);
|
||||
}
|
||||
|
||||
output_size_list_.clear();
|
||||
|
@ -186,7 +186,7 @@ int KernelMod::Resize(const BaseOperatorPtr &base_operator, const std::vector<Ke
|
|||
shape.empty() ? type_size : std::accumulate(shape.begin(), shape.end(), type_size, std::multiplies<size_t>());
|
||||
tensor_size = std::max(tensor_size, type_size);
|
||||
}
|
||||
output_size_list_.emplace_back(tensor_size);
|
||||
(void)output_size_list_.emplace_back(tensor_size);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ void TensorsQueueClearCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
}
|
||||
|
||||
bool TensorsQueueClearCpuKernelMod::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &,
|
||||
const std::vector<AddressPtr> &outputs) {
|
||||
const std::vector<AddressPtr> &) {
|
||||
CPUTensorsQueuePtr tensors_q = GetTensorsQueue(inputs);
|
||||
std::unique_lock<std::mutex> lock_(tq_mutex_);
|
||||
// Return all the element addr back to store, and the tensors_q will be empty.
|
||||
|
|
|
@ -82,10 +82,10 @@ int SparseMatirxAddCpuKernelMod::Resize(const BaseOperatorPtr &base_operator,
|
|||
}
|
||||
output_size_list_.clear();
|
||||
auto max_out_size = std::min(input_size_list_[kAIndicesIdx] + input_size_list_[kBIndicesIdx], dense_size_);
|
||||
output_size_list_.emplace_back(input_size_list_[0]);
|
||||
output_size_list_.emplace_back(max_out_size);
|
||||
output_size_list_.emplace_back(max_out_size / GetTypeByte(TypeIdToType(types_[kAIndicesIdx])) *
|
||||
GetTypeByte(TypeIdToType(types_[kAValuesIdx])));
|
||||
(void)output_size_list_.emplace_back(input_size_list_[0]);
|
||||
(void)output_size_list_.emplace_back(max_out_size);
|
||||
(void)output_size_list_.emplace_back(max_out_size / GetTypeByte(TypeIdToType(types_[kAIndicesIdx])) *
|
||||
GetTypeByte(TypeIdToType(types_[kAValuesIdx])));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -118,14 +118,14 @@ bool SparseMatirxAddCpuKernelMod::LaunchKernel(const std::vector<AddressPtr> &in
|
|||
c_indptr[0] = 0;
|
||||
std::set<T> index_set;
|
||||
size_t c_idx = 0;
|
||||
T a_v = 0;
|
||||
T b_v = 0;
|
||||
S a_v = 0;
|
||||
S b_v = 0;
|
||||
size_t a_v_idx = 0;
|
||||
size_t b_v_idx = 0;
|
||||
auto task = [this, &a_indptr, &a_indices, &a_values, &b_indptr, &b_indices, &b_values, &alpha, &beta, &c_indptr,
|
||||
&c_indices, &c_values, &index_set, &c_idx, &a_v, &b_v, &a_v_idx, &b_v_idx](size_t start, size_t end) {
|
||||
for (size_t i = start; i < end; i++) {
|
||||
size_t max_mask_len = a_indptr[i + 1] - a_indptr[i] + b_indptr[i + 1] - b_indptr[i];
|
||||
size_t max_mask_len = static_cast<size_t>(a_indptr[i + 1] - a_indptr[i] + b_indptr[i + 1] - b_indptr[i]);
|
||||
// Masks for recording the valid location.
|
||||
std::vector<bool> mask_a(max_mask_len, false);
|
||||
std::vector<bool> mask_b(max_mask_len, false);
|
||||
|
@ -139,17 +139,17 @@ bool SparseMatirxAddCpuKernelMod::LaunchKernel(const std::vector<AddressPtr> &in
|
|||
}
|
||||
// index_set.size() are the valid numbers to set indptr.
|
||||
c_indptr[i + 1] = c_indptr[i] + static_cast<T>(index_set.size());
|
||||
for (auto it = index_set.begin(); it != index_set.end(); it++) {
|
||||
if (mask_a[*it]) {
|
||||
for (auto it = index_set.cbegin(); it != index_set.cend(); it++) {
|
||||
if (mask_a[static_cast<size_t>(*it)]) {
|
||||
// Independent cursor for indeices to get value. Increase the cursor once used.
|
||||
a_v = a_values[a_v_idx];
|
||||
a_v_idx++;
|
||||
}
|
||||
if (mask_b[*it]) {
|
||||
if (mask_b[static_cast<T>(*it)]) {
|
||||
b_v = b_values[b_v_idx];
|
||||
b_v_idx++;
|
||||
}
|
||||
c_values[c_idx] = alpha[0] * a_v + beta[0] * b_v;
|
||||
c_values[c_idx] = alpha[IntToSize(0)] * a_v + beta[IntToSize(0)] * b_v;
|
||||
c_indices[c_idx] = *it;
|
||||
c_idx++;
|
||||
b_v = 0; // Reset the tmp value, real number or zero.
|
||||
|
|
|
@ -43,7 +43,7 @@ class TensorArrayMgr {
|
|||
TensorArrayMgr(const TensorArrayMgr &) = delete;
|
||||
TensorArrayMgr(const TensorArrayMgr &&) = delete;
|
||||
TensorArrayMgr &operator=(const TensorArrayMgr &&) = delete;
|
||||
TensorArrayMgr operator=(const TensorArrayMgr &) = delete;
|
||||
TensorArrayMgr &operator=(const TensorArrayMgr &) = delete;
|
||||
|
||||
void AddTensorArray(const int64_t handle, const TensorArrayPtr &ta) {
|
||||
MS_LOG(DEBUG) << "Add a TensorArray to map, handle is " << handle;
|
||||
|
@ -95,7 +95,7 @@ class TensorsQueueMgr {
|
|||
TensorsQueueMgr(const TensorsQueueMgr &) = delete;
|
||||
TensorsQueueMgr(const TensorsQueueMgr &&) = delete;
|
||||
TensorsQueueMgr &operator=(const TensorsQueueMgr &&) = delete;
|
||||
TensorsQueueMgr operator=(const TensorsQueueMgr &) = delete;
|
||||
TensorsQueueMgr &operator=(const TensorsQueueMgr &) = delete;
|
||||
|
||||
void AddTensorsQueue(const int64_t handle, const TensorsQueuePtr &tq) {
|
||||
MS_LOG(DEBUG) << "Add a TensorsQueue to map, handle is " << handle;
|
||||
|
|
|
@ -54,7 +54,13 @@ void TensorsQueue::CopyTensor(const mindspore::kernel::AddressPtr &, const minds
|
|||
size_t TensorsQueue::AvailableSize() {
|
||||
return (rear_ > front_) ? (rear_ - front_) : (LongToSize(size_) - front_ + rear_);
|
||||
}
|
||||
bool TensorsQueue::IsFull() { return (rear_ + IntToSize(1)) % LongToSize(size_) == front_; }
|
||||
bool TensorsQueue::IsFull() {
|
||||
if (size_ <= 0) {
|
||||
return false;
|
||||
} else {
|
||||
return (rear_ + IntToSize(1)) % LongToSize(size_) == front_;
|
||||
}
|
||||
}
|
||||
bool TensorsQueue::IsEmpty() { return front_ == rear_; }
|
||||
|
||||
bool TensorsQueue::Put(const mindspore::kernel::AddressPtrList &dev_addr) {
|
||||
|
@ -69,6 +75,9 @@ bool TensorsQueue::Put(const mindspore::kernel::AddressPtrList &dev_addr) {
|
|||
for (int64_t i = 0; i < elements_num_; i++) {
|
||||
CopyTensor(element[LongToSize(i)], dev_addr[LongToSize(i) + IntToSize(1)]);
|
||||
}
|
||||
if (size_ <= 0) {
|
||||
return false;
|
||||
}
|
||||
rear_ = (rear_ + 1) % LongToSize(size_);
|
||||
MS_LOG(DEBUG) << "Put an element into " << name_ << ", now the avliable q size is [" << AvailableSize() << "/"
|
||||
<< size_ << "]";
|
||||
|
@ -84,6 +93,9 @@ bool TensorsQueue::Put(const mindspore::kernel::AddressPtrList &dev_addr, void *
|
|||
for (int64_t i = 0; i < elements_num_; i++) {
|
||||
CopyTensor(element[LongToSize(i)], dev_addr[LongToSize(i) + IntToSize(1)], stream);
|
||||
}
|
||||
if (size_ <= 0) {
|
||||
return false;
|
||||
}
|
||||
rear_ = (rear_ + IntToSize(1)) % LongToSize(size_);
|
||||
MS_LOG(DEBUG) << "Put an element into " << name_ << ", now the avliable q size is [" << AvailableSize() << "/"
|
||||
<< size_ << "]";
|
||||
|
|
|
@ -49,8 +49,8 @@ class TensorsQueue {
|
|||
virtual void CopyTensor(const mindspore::kernel::AddressPtr &dst, const mindspore::kernel::AddressPtr &src);
|
||||
virtual void CopyTensor(const mindspore::kernel::AddressPtr &dst, const mindspore::kernel::AddressPtr &src,
|
||||
void *stream);
|
||||
virtual bool Get(const mindspore::kernel::AddressPtrList &outputs, const bool &pop_after_get);
|
||||
virtual bool Get(const mindspore::kernel::AddressPtrList &outputs, const bool &pop_after_get, void *stream);
|
||||
virtual bool Get(const mindspore::kernel::AddressPtrList &dev_addr, const bool &pop_after_get);
|
||||
virtual bool Get(const mindspore::kernel::AddressPtrList &dev_addr, const bool &pop_after_get, void *stream);
|
||||
|
||||
// Common functions for TensorsQueue which are device independent.
|
||||
virtual void Clear();
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "utils/log_adapter.h"
|
||||
|
||||
namespace mindspore {
|
||||
SignalGuard::SignalGuard(IntHandlerFunc IntHandler) { RegisterHandlers(IntHandler); }
|
||||
SignalGuard::SignalGuard(IntHandlerFunc func) { RegisterHandlers(func); }
|
||||
|
||||
SignalGuard::~SignalGuard() {
|
||||
if (old_handler != nullptr) {
|
||||
|
|
|
@ -57,16 +57,16 @@ AbstractBasePtr InferImplTensorArrayStack(const AnalysisEnginePtr &, const Primi
|
|||
auto max_shape_ = ele_shape;
|
||||
auto min_shape_ = ele_shape;
|
||||
auto out_shape_ = ele_shape;
|
||||
(void)max_shape_.insert(max_shape_.begin(), kMaxElement);
|
||||
(void)min_shape_.insert(min_shape_.begin(), 1);
|
||||
(void)out_shape_.insert(out_shape_.begin(), -1);
|
||||
(void)max_shape_.insert(max_shape_.cbegin(), kMaxElement);
|
||||
(void)min_shape_.insert(min_shape_.cbegin(), 1);
|
||||
(void)out_shape_.insert(out_shape_.cbegin(), -1);
|
||||
ShapeVector out_shape = out_shape_;
|
||||
ShapeVector min_shape = min_shape_;
|
||||
ShapeVector max_shape = max_shape_;
|
||||
output = std::make_shared<AbstractTensor>(type, std::make_shared<Shape>(out_shape, min_shape, max_shape));
|
||||
} else {
|
||||
auto out_shape_ = ele_shape;
|
||||
(void)out_shape_.insert(out_shape_.begin(), size);
|
||||
(void)out_shape_.insert(out_shape_.cbegin(), size);
|
||||
ShapeVector out_shape = out_shape_;
|
||||
output = std::make_shared<AbstractTensor>(type, std::make_shared<Shape>(out_shape));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue