Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions csrc/fastdeploy/function/eigen.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ struct EigenMatrix : public EigenTensor<T, 2, MajorType, IndexType> {
int num_col_dims) {
int rank = tensor.shape.size();
FDASSERT((num_col_dims > 0 && num_col_dims < rank),
"Input dimension number(num_col_dims).");
"Input dimension number(num_col_dims) must be between 0 and %d, "
"but received number is %d.",
rank, num_col_dims);
const int n = SizeToAxis(num_col_dims, tensor.shape);
const int d = SizeFromAxis(num_col_dims, tensor.shape);
return EigenMatrix::From(tensor, {n, d});
Expand All @@ -114,7 +116,9 @@ struct EigenMatrix : public EigenTensor<T, 2, MajorType, IndexType> {
int num_col_dims) {
int rank = tensor.shape.size();
FDASSERT((num_col_dims > 0 && num_col_dims < rank),
"Input dimension number(num_col_dims).");
"Input dimension number(num_col_dims) must be between 0 and %d, "
"but received number is %d.",
rank, num_col_dims);
const int n = SizeToAxis(num_col_dims, tensor.shape);
const int d = SizeFromAxis(num_col_dims, tensor.shape);
return EigenMatrix::From(tensor, {n, d});
Expand Down
7 changes: 5 additions & 2 deletions csrc/fastdeploy/function/softmax.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ void SoftmaxKernel(const FDTensor& x, FDTensor* out, int axis) {
}

void Softmax(const FDTensor& x, FDTensor* out, int axis) {
FDASSERT(std::abs(axis) < x.shape.size(),
"The given axis should be smaller than the input's dimension");
FDASSERT(
std::abs(axis) < x.shape.size(),
"The absolute given axis should be smaller than the input's "
"dimension. Expected absolute axis is smaller than %d, but receive %d.",
x.shape.size(), std::abs(axis));
FD_VISIT_FLOAT_TYPES(x.dtype, "SoftmaxKernel",
([&] { SoftmaxKernel<data_t>(x, out, axis); }));
}
Expand Down
8 changes: 6 additions & 2 deletions csrc/fastdeploy/function/transpose.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ void Transpose(const FDTensor& x, FDTensor* out,
const std::vector<int64_t>& dims) {
size_t dims_size = dims.size();
FDASSERT(dims_size == x.shape.size(),
"The input tensor's dimension should be equal to the dims's size.");
"The input tensor's dimension should be equal to the dims's size. "
"Expect dims size is %d, but receive %d.",
x.shape.size(), dims_size);
std::vector<int> count(dims_size, 0);
for (size_t i = 0; i < dims_size; i++) {
FDASSERT(dims[i] >= 0, "The dims should be greater than or equal to 0.");
FDASSERT(dims[i] >= 0,
"The dims should be greater than or equal to 0, but receive %d.",
dims[i]);
FDASSERT(dims[i] < static_cast<int>(dims_size) && ++count[dims[i]] == 1,
"Each element of Attribute axis should be a unique value range "
"from 0 to (dims - 1), where the dims is the axis's size, unique "
Expand Down
62 changes: 36 additions & 26 deletions csrc/fastdeploy/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include <stdlib.h>
#include <cstdio>

#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -85,10 +86,14 @@ FASTDEPLOY_DECL bool ReadBinaryFromFile(const std::string& file,
FDLogger(true, "[INFO]") << __REL_FILE__ << "(" << __LINE__ \
<< ")::" << __FUNCTION__ << "\t"

#define FDASSERT(condition, message) \
if (!(condition)) { \
FDERROR << message << std::endl; \
std::abort(); \
#define FDASSERT(condition, format, ...) \
if (!(condition)) { \
std::string format_string(format); \
int n = std::snprintf(nullptr, 0, format_string.data(), ##__VA_ARGS__); \
std::vector<char> buffer(n + 1); \
std::snprintf(buffer.data(), n + 1, format_string.data(), ##__VA_ARGS__); \
FDERROR << buffer.data() << std::endl; \
std::abort(); \
}

///////// Basic Marco ///////////
Expand Down Expand Up @@ -119,41 +124,46 @@ FASTDEPLOY_DECL bool ReadBinaryFromFile(const std::string& file,
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \
__VA_ARGS__) \
default: \
FDASSERT(false, \
"Invalid enum data type. Only accept data type BOOL, INT32, " \
"INT64, FP32, FP64.") \
FDASSERT( \
false, \
"Invalid enum data type. Expect to accept data type BOOL, INT32, " \
"INT64, FP32, FP64, but receive type %s.", \
Str(__dtype__)); \
} \
}()

#define FD_VISIT_FLOAT_TYPES(TYPE, NAME, ...) \
#define FD_VISIT_FLOAT_TYPES(TYPE, NAME, ...) \
[&] { \
const auto& __dtype__ = TYPE; \
switch (__dtype__) { \
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \
__VA_ARGS__) \
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \
__VA_ARGS__) \
default: \
FDASSERT(false, \
"Invalid enum data type. Expect to accept data type FP32, " \
"FP64, but receive type %s.", \
Str(__dtype__)); \
} \
}()

#define FD_VISIT_INT_TYPES(TYPE, NAME, ...) \
[&] { \
const auto& __dtype__ = TYPE; \
switch (__dtype__) { \
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \
__VA_ARGS__) \
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \
__VA_ARGS__) \
default: \
FDASSERT(false, \
"Invalid enum data type. Only accept data type FP32, FP64.") \
"Invalid enum data type. Expect to accept data type INT32, " \
"INT64, but receive type %s.", \
Str(__dtype__)); \
} \
}()

#define FD_VISIT_INT_TYPES(TYPE, NAME, ...) \
[&] { \
const auto& __dtype__ = TYPE; \
switch (__dtype__) { \
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \
__VA_ARGS__) \
FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \
__VA_ARGS__) \
default: \
FDASSERT( \
false, \
"Invalid enum data type. Only accept data type INT32, INT64.") \
} \
}()

FASTDEPLOY_DECL std::vector<int64_t> GetStride(
const std::vector<int64_t>& dims);

Expand Down
1 change: 1 addition & 0 deletions tests/function/test_reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <array>
#include <vector>
#include "fastdeploy/core/fd_tensor.h"
#include "fastdeploy/function/reduce.h"
Expand Down