Skip to content
Permalink
Browse files

Add script to help formatting source files

  • Loading branch information...
Po Yen Chen
Po Yen Chen committed Mar 10, 2019
1 parent 26b23b7 commit 27827f38c9c86971d7544e6426f9d71c30ee3448
@@ -160,8 +160,7 @@ void CodeEmitVisitor::visit(const Conv& pOp)
NVDLA_DBG("max_conv_H: %d\n", max_conv_H);
} else {
std::ostringstream os;
os << "fcube_group.banks(" << fcube_group.banks
<< ") + winfo.banks(" << winfo.banks << ") > " << 16;
os << "fcube_group.banks(" << fcube_group.banks << ") + winfo.banks(" << winfo.banks << ") > " << 16;
fatal(nvdla_exceed_hardware_limit) << os.str();
}
}
@@ -844,8 +843,7 @@ void CodeEmitVisitor::visit(const Gemm& pOp)
winfo.reduceBanks();
} else {
std::ostringstream os;
os << "finfo.banks(" << finfo.banks
<< ") + winfo.banks(" << winfo.banks << ") > " << 16;
os << "finfo.banks(" << finfo.banks << ") + winfo.banks(" << winfo.banks << ") > " << 16;
fatal(nvdla_exceed_hardware_limit) << os.str();
}
}
@@ -1145,11 +1143,11 @@ int CodeEmitVisitor::packWeight(const Tensor* t, int dims[4], int gidx)
return mle.id;
}

int CodeEmitVisitor::packBias(const ComputeOperator &co, const Tensor* t, int dims[4], int gidx)
int CodeEmitVisitor::packBias(const ComputeOperator& co, const Tensor* t, int dims[4], int gidx)
{
if (dims[1] != 1 && dims[2] != 1 && dims[3] != 1) {
NVDLA_DBG("PACK FEATURE, FEATURE IS NOT 1D ARRAY ##################################");
fatal(nvdla_unsupported_attribute) << "bais" << "is not 1D array" << co.name();
fatal(nvdla_unsupported_attribute) << "bais is not 1D array" << co.name();
}
std::string blob_name = "tb-" + std::to_string(m_pMeta.m_NumBlobs++);
NvDlaCubeInfo finfo(NVDLA_CUBE_FEATURE, 1, dims[0], dims[2], dims[3], sizeof(unsigned short));
@@ -41,7 +41,7 @@ class CodeEmitVisitor : public CustomVisitor<CodeEmitVisitor>

void conv(const Tensor* x, const Tensor* w, const Tensor* b, const Tensor* y);
int packWeight(const Tensor* t, int dims[4], int gidx);
int packBias(const ComputeOperator &co, const Tensor* t, int dims[4], int gidx);
int packBias(const ComputeOperator& co, const Tensor* t, int dims[4], int gidx);

void issueEmuOp(NvDlaEmuOperation* op);
int issueEmuAddr(int mid);
@@ -153,17 +153,16 @@ NvDlaCubeInfo::NvDlaCubeInfo(nvdla_cube_type m, int n, int c, int h, int w, int
int segment_c = UNIT_ALIGNMENT(dim_c, atom_c);
size = dim_n * segment_c * dim_h * dim_w * ELEMENT_SIZE;


// copy how SystemC calculate entry per slice
int atom_per_channel = DIV_ROUNDUP((dim_c * element_size), FEATURE_ATOM_CUBE_SIZE);
int entry_per_slice = (atom_per_channel / 4) * dim_w;
int atom_per_channel = DIV_ROUNDUP((dim_c * element_size), FEATURE_ATOM_CUBE_SIZE);
int entry_per_slice = (atom_per_channel / 4) * dim_w;
// Same check as in IP_TOT/tools/cc_sanity_checker.pl (line350~357)
if ((atom_per_channel % 4) ==3)
entry_per_slice += dim_w;
else if ((atom_per_channel % 4) ==2)
entry_per_slice += (dim_w + 1)/2;
else if ((atom_per_channel % 4) ==1)
entry_per_slice += (dim_w + 3)/4;
if ((atom_per_channel % 4) == 3)
entry_per_slice += dim_w;
else if ((atom_per_channel % 4) == 2)
entry_per_slice += (dim_w + 1) / 2;
else if ((atom_per_channel % 4) == 1)
entry_per_slice += (dim_w + 3) / 4;

eps = entry_per_slice;
NVDLA_DBG("Cube_Info %d %d/%d %d %d %d %d\n", dim_n, dim_c, segment_c, dim_h, dim_w, ELEMENT_SIZE, eps);
@@ -0,0 +1,30 @@
#!/bin/bash

set -e

ONNC_DIR="$( realpath $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.. )"
CLANG_FORMAT=clang-format-7

DIRS=(
lib/Target/NvDla
)

EXCLUDE_DIRS=(
lib/Target/NvDla/include
lib/Target/Sophon
)


for dir in $DIRS
do
cd $ONNC_DIR/$dir

FILES=$(find . -iname "*.h" -o -iname "*.hpp" -o -iname "*.c" -o -iname "*.cpp" -o -iname "*.cxx" -type f | xargs realpath)

for exclude_dir in "${EXCLUDE_DIRS[@]}"
do
FILES=$(printf '%s\n' "${FILES[@]}" | grep -v "^$ONNC_DIR/$exclude_dir")
done

printf '%s\n' "${FILES[@]}" | xargs $CLANG_FORMAT -style=file -i
done

0 comments on commit 27827f3

Please sign in to comment.
You can’t perform that action at this time.