提交 b0980fd1 编写于 作者: 饶先宏's avatar 饶先宏

202108020625 lrn: real parameter type

上级 59673dde
......@@ -981,11 +981,9 @@ int node_setup(cnn_layer_node* node, FILE * pCodeFile)
fprintf(pCodeFile,
"\thdl4se_cnn_lrn #(\n"
"\t\t%4d, %4d, %4d,\t/* 输入大小 */ \n"
"\t\t%4d, %4d, %4d,\t/* 输出大小 */\n"
"\t\t%4d, %f, %f, %f,\t/* locasize, k, alpha, beta */\n"
"\t\t`%s) \t/* 模式 */\n",
node->inputsize[0][1], node->inputsize[0][0], node->inputsize[0][2],
node->outputsize[0][1], node->outputsize[0][0], node->outputsize[0][2],
pInfo->local_size, pInfo->k, pInfo->alpha, pInfo->beta,
norm_region_name[pInfo->norm_region]
);
......
......@@ -33,7 +33,7 @@
* cnncell_lrn.c
修改记录:
202107061559: rxh, initial version
202107181112: rxh, initial version
202107181112: rxh, macro version
*/
#include "stdlib.h"
#include "stdio.h"
......@@ -60,13 +60,25 @@ IDLIST
VID(wDataWriteEnable),
VID(wDataWrite),
VID(bDataWriteData),
VID(index),
VID(state),
END_IDLIST
MODULE_DECLARE(cnncell_lrn)
int w, h, c;
int region;
int local_size;
float k, alpha, beta;
float* buf;
float* square;
END_MODULE_DECLARE(cnncell_lrn)
enum cnncell_lrn_state {
LRN_READ,
LRN_CALC,
LRN_WRITE,
};
DEFINE_FUNC(cnncell_lrn_gen_read) {
vput(wDataRead, 1);
} END_DEFINE_FUNC
......@@ -76,16 +88,46 @@ DEFINE_FUNC(cnncell_lrn_gen_write) {
} END_DEFINE_FUNC
DEFINE_FUNC(cnncell_lrn_clktick) {
int state = vget(state);
int index = vget(index);
if (vget(nwReset) == 0) {
state = LRN_READ;
index = 0;
}
else if (state == LRN_READ) {
}
else if (state == LRN_CALC) {
}
else if (state == LRN_WRITE) {
}
vput(state, state);
vput(index, index);
} END_DEFINE_FUNC
DEFINE_FUNC(cnncell_lrn_deinit) {
if (pobj->buf != NULL)
free(pobj->buf);
if (pobj->square != NULL)
free(pobj->square);
} END_DEFINE_FUNC
MODULE_INIT(cnncell_lrn)
pobj->w = (int)MODULE_PARAM(0);
pobj->h = (int)MODULE_PARAM(1);
pobj->c = (int)MODULE_PARAM(2);
pobj->region = (int)MODULE_PARAM(3);
pobj->local_size = (int)MODULE_PARAM(3);
pobj->k = (float)MODULE_PARAM_REAL(4);
pobj->alpha = (float)MODULE_PARAM_REAL(5);
pobj->beta = (float)MODULE_PARAM_REAL(6);
pobj->region = (int)MODULE_PARAM(7);
pobj->buf = (float *)malloc(pobj->c * sizeof(float));
pobj->square = (float*)malloc((pobj->c + pobj->local_size) * sizeof(float));
if ((pobj->buf == NULL) || (pobj->square == NULL))
return -1;
PORT_IN(wClk, 1);
PORT_IN(nwReset, 1);
......@@ -98,6 +140,9 @@ MODULE_INIT(cnncell_lrn)
GPORT_OUT(wDataWrite, 1, cnncell_lrn_gen_write);
GPORT_OUT(bDataWriteData, 32, cnncell_lrn_gen_write);
REG(index, 16);
REG(state, 3);
CLKTICK_FUNC(cnncell_lrn_clktick);
DEINIT_FUNC(cnncell_lrn_deinit);
......
......@@ -31,7 +31,7 @@
/*
* Created by HDL4SE @ Sun Aug 1 20:55:40 2021
* Created by HDL4SE @ Mon Aug 2 06:11:45 2021
* Don't edit it.
*/
......@@ -3143,7 +3143,7 @@ GEN_MODULE_INIT
", wDataWrite_4, bDataWriteData_4");
CELL_INST("59076B10-44F2-46E4-B950-179B8D2959B6", /* hdl4se_cnn_lrn */
"lrn_5",
"32'h38, 32'h38, 32'h40, 32'h38, 32'h38, 32'h40, 32'h5, 32'sh1, 32'sh0, 32'sh0, 32'h0",
"32'h38, 32'h38, 32'h40, 32'h5, 1.000000, 0.000100, 0.750000, 32'h0",
"wClk, nwReset, wDataRead_5, wDataReadValid_5, bDataReadData_5, wDataWriteEnable_5"
", wDataWrite_5, bDataWriteData_5");
CELL_INST("230946EF-3EC1-43EC-A841-CDE8A9E97314", /* hdl4se_fifo */
......@@ -3191,7 +3191,7 @@ GEN_MODULE_INIT
", wDataWrite_8, bDataWriteData_8");
CELL_INST("59076B10-44F2-46E4-B950-179B8D2959B6", /* hdl4se_cnn_lrn */
"lrn_10",
"32'h38, 32'h38, 32'hc0, 32'h38, 32'h38, 32'hc0, 32'h5, 32'sh1, 32'sh0, 32'sh0, 32'h0",
"32'h38, 32'h38, 32'hc0, 32'h5, 1.000000, 0.000100, 0.750000, 32'h0",
"wClk, nwReset, wDataRead_10, wDataReadValid_10, bDataReadData_10, wDataWriteEnable_10"
", wDataWrite_10, bDataWriteData_10");
CELL_INST("230946EF-3EC1-43EC-A841-CDE8A9E97314", /* hdl4se_fifo */
......
......@@ -592,9 +592,9 @@ module hdl4se_cnn_lrn
parameter HEIGHT = 32'h3e8,
parameter COMPONENT = 32'h1,
parameter localsize = 32'h5,
parameter real k = 32'sh1,
parameter real alpha = 32'sh0,
parameter real beta = 32'sh0,
parameter real k = <type=1>,
parameter real alpha = <type=1>,
parameter real beta = <type=1>,
parameter LRN_NORMREGION = 32'h0
)
(
......@@ -2273,9 +2273,8 @@ module googlenet
, wDataWrite_4, bDataWriteData_4 );
hdl4se_fifo #( 32'h20, 32'h80 ) cnn_buf_4( wClk, nwReset, wDataRead_5, wDataReadValid_5, bDataReadData_5, wDataWriteEnable_4
, wDataWrite_4, bDataWriteData_4 );
hdl4se_cnn_lrn #( 32'h38, 32'h38, 32'h40, 32'h38, 32'h38, 32'h40
, 32'h5, 32'sh1, 32'sh0, 32'sh0, 32'h0
) lrn_5( wClk, nwReset, wDataRead_5, wDataReadValid_5, bDataReadData_5, wDataWriteEnable_5
hdl4se_cnn_lrn #( 32'h38, 32'h38, 32'h40, 32'h5, <type=1>, <type=1>
, <type=1>, 32'h0 ) lrn_5( wClk, nwReset, wDataRead_5, wDataReadValid_5, bDataReadData_5, wDataWriteEnable_5
, wDataWrite_5, bDataWriteData_5 );
hdl4se_fifo #( 32'h20, 32'h80 ) cnn_buf_5( wClk, nwReset, wDataRead_6, wDataReadValid_6, bDataReadData_6, wDataWriteEnable_5
, wDataWrite_5, bDataWriteData_5 );
......@@ -2305,9 +2304,8 @@ module googlenet
, wDataWriteEnable_8, wDataWrite_8, bDataWriteData_8 );
hdl4se_fifo #( 32'h20, 32'h180 ) cnn_buf_8( wClk, nwReset, wDataRead_10, wDataReadValid_10, bDataReadData_10, wDataWriteEnable_8
, wDataWrite_8, bDataWriteData_8 );
hdl4se_cnn_lrn #( 32'h38, 32'h38, 32'hc0, 32'h38, 32'h38, 32'hc0
, 32'h5, 32'sh1, 32'sh0, 32'sh0, 32'h0
) lrn_10( wClk, nwReset, wDataRead_10, wDataReadValid_10, bDataReadData_10, wDataWriteEnable_10
hdl4se_cnn_lrn #( 32'h38, 32'h38, 32'hc0, 32'h5, <type=1>, <type=1>
, <type=1>, 32'h0 ) lrn_10( wClk, nwReset, wDataRead_10, wDataReadValid_10, bDataReadData_10, wDataWriteEnable_10
, wDataWrite_10, bDataWriteData_10 );
hdl4se_fifo #( 32'h20, 32'h180 ) cnn_buf_10( wClk, nwReset, wDataRead_11, wDataReadValid_11, bDataReadData_11, wDataWriteEnable_10
, wDataWrite_10, bDataWriteData_10 );
......
......@@ -31,7 +31,7 @@
/*
* 由googlenet程序生成
* 生成时间:Sun Aug 1 20:46:55 2021
* 生成时间:Mon Aug 2 06:11:30 2021
* 请不要手工修改。
*/
`include "hdl4secell.v"
......@@ -218,7 +218,6 @@ module googlenet(
/* 局部响应归一化层 5:pool1/norm1 */
hdl4se_cnn_lrn #(
56, 56, 64, /* 输入大小 */
56, 56, 64, /* 输出大小 */
5, 1.000000, 0.000100, 0.750000, /* locasize, k, alpha, beta */
`LRN_NormRegion_ACROSS_CHANNELS) /* 模式 */
lrn_5 (
......@@ -473,7 +472,6 @@ module googlenet(
/* 局部响应归一化层 10:conv2/norm2 */
hdl4se_cnn_lrn #(
56, 56, 192, /* 输入大小 */
56, 56, 192, /* 输出大小 */
5, 1.000000, 0.000100, 0.750000, /* locasize, k, alpha, beta */
`LRN_NormRegion_ACROSS_CHANNELS) /* 模式 */
lrn_10 (
......
......@@ -248,6 +248,7 @@ int hdl4se_module_GetModule(sGeneralModule* pobj, int index, IHDL4SEModuleVar**
int hdl4se_module_GetVariableCount(sGeneralModule* pobj);
int hdl4se_module_GetVariable(sGeneralModule* pobj, int index, ModuleVariable** portinfo);
int hdl4se_module_GetParent(sGeneralModule* pobj, const IHDL4SEModuleVar ** parent);
double hdl4seGetParamReal(PointerArray* list, int index);
long long hdl4seGetParam(PointerArray* list, int index);
const char* hdl4seGetParamStr(PointerArray* list, int index);
......@@ -486,6 +487,7 @@ do { \
#define Var_idx(idx) hdl4se_module_Var(pobj->pmodule, idx)
#define MODULE_PARAM(index) hdl4seGetParam(&pobj->pmodule->parameters, index)
#define MODULE_PARAM_REAL(index) hdl4seGetParamReal(&pobj->pmodule->parameters, index)
#define MODULE_PARAM_STR(index) hdl4seGetParamStr(&pobj->pmodule->parameters, index)
DEFINE_GUID(PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS, 0xad12c414, 0x631b, 0x42cb, 0xb9, 0xbb, 0xba, 0xbd, 0x78, 0x21, 0x3f, 0xef);
......
......@@ -523,6 +523,13 @@ const char *hdl4seGetParamStr(PointerArray* list, int index)
return (const char*)list->array[index];
}
double hdl4seGetParamReal(PointerArray* list, int index)
{
if (index < 0 || index >= list->itemcount)
return 0.0;
return atof((const char*)list->array[index]);
}
long long hdl4seGetParam(PointerArray* list, int index)
{
long long ret = 0;
......
......@@ -221,6 +221,10 @@ char* moduleinstanceGetParameterString(verilogModuleInstance* moduleinstance)
expr0 = verilogExprGetData(paraminst->expr0);
if (expr0 == NULL)
return "";
if (index > 0) {
*buf++ = ',';
*buf++ = ' ';
}
if (expr0->exprtype == EXPRTYPE_STRING) {
const char* s;
s = expr0->value->string;
......@@ -237,13 +241,18 @@ char* moduleinstanceGetParameterString(verilogModuleInstance* moduleinstance)
}
*buf = '\0';
}
else if (expr0->exprtype == EXPRTYPE_REAL) {
const char* s;
s = expr0->value->string;
while (*s) {
*buf++ = *s++;
}
*buf = '\0';
}
else if (expr0->exprtype != EXPRTYPE_BIGNUMBER) {
return ""; /* Fixed Me 参数中不能有带参数的表达式? */
}
if (index > 0) {
*buf++ = ',';
*buf++ = ' ';
}
if (expr0->exprtype == EXPRTYPE_BIGNUMBER) {
if (0 != objectCall3(expr0->bignumber, GetStr, 10, buf, 1024)) {
return "";
......
此差异已折叠。
......@@ -175,7 +175,7 @@
topmodule_identifier parameter_identifier
port_identifier net_identifier
module_instance_identifier
number string unsigned_number
number string unsigned_number real
%type <ival> parameter_type
unary_operator
......@@ -4871,6 +4871,13 @@ constant_primary :
NULL //IDListVarPtr attributes
);
}
| real {
$$ = verilogparseCreateValueExpr(
EXPRTYPE_REAL, //int exprtype,
$1, //IConstStringVar* value,
NULL //IDListVarPtr attributes
);
}
| parameter_identifier {
$$ = verilogparseCreateParamExpr(
EXPRTYPE_PARAM, //int exprtype,
......@@ -5089,6 +5096,13 @@ primary :
NULL //IDListVarPtr attributes
);
}
| real {
$$ = verilogparseCreateValueExpr(
EXPRTYPE_REAL, //int exprtype,
$1, //IConstStringVar* value,
NULL //IDListVarPtr attributes
);
}
| var {
$$ = verilogparseCreateVariableExpr(
EXPRTYPE_HIERARCHICAL_IDENT,
......@@ -5394,11 +5408,14 @@ unsigned_number :
}
;
number :
real :
NUM_REAL{
$$ = $1;
}
| unsigned_number {
;
number :
unsigned_number {
$$ = $1;
}
| BIN_BASE BIN_VALUE {
......
......@@ -124,6 +124,7 @@ enum VAR_TYPE {
enum EXPR_TYPE {
EXPRTYPE_NUMBER,
EXPRTYPE_REAL,
EXPRTYPE_BIGNUMBER,
EXPRTYPE_PARAM,
EXPRTYPE_LOCALPARAM,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册