Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alex037yang
OpenXG-RAN
Commits
6bf628c5
Commit
6bf628c5
authored
Feb 09, 2018
by
Raymond Knopp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
took multi-segment code from private branch and optimized the input packing with AVX2 only for now.
parent
6022b821
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
173 additions
and
13 deletions
+173
-13
openair1/PHY/CODING/TESTBENCH/ldpctest.c
openair1/PHY/CODING/TESTBENCH/ldpctest.c
+13
-12
openair1/PHY/CODING/defs.h
openair1/PHY/CODING/defs.h
+1
-1
openair1/PHY/CODING/ldpc_encoder2.c
openair1/PHY/CODING/ldpc_encoder2.c
+159
-0
No files found.
openair1/PHY/CODING/TESTBENCH/ldpctest.c
View file @
6bf628c5
...
@@ -76,15 +76,15 @@ int test_ldpc(short No_iteration,
...
@@ -76,15 +76,15 @@ int test_ldpc(short No_iteration,
opp_enabled
=
1
;
opp_enabled
=
1
;
cpu_freq_GHz
=
get_cpu_freq_GHz
();
cpu_freq_GHz
=
get_cpu_freq_GHz
();
//short test_input[block_length];
//short test_input[block_length];
unsigned
char
*
test_input
;
unsigned
char
*
test_input
[
8
]
=
{
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
}
;
//short *c; //padded codeword
//short *c; //padded codeword
short
*
esimated_output
;
short
*
esimated_output
;
unsigned
char
*
channel_input
;
unsigned
char
*
channel_input
;
unsigned
char
*
channel_input_optim
;
unsigned
char
*
channel_input_optim
[
8
]
;
double
*
channel_output
;
double
*
channel_output
;
double
*
modulated_input
;
double
*
modulated_input
;
short
*
channel_output_fixed
;
short
*
channel_output_fixed
;
unsigned
int
i
,
trial
=
0
;
unsigned
int
i
,
j
,
trial
=
0
;
short
BG
,
Zc
,
Kb
,
nrows
,
ncols
;
short
BG
,
Zc
,
Kb
,
nrows
,
ncols
;
int
no_punctured_columns
,
removed_bit
;
int
no_punctured_columns
,
removed_bit
;
int
i1
;
int
i1
;
...
@@ -93,9 +93,9 @@ int test_ldpc(short No_iteration,
...
@@ -93,9 +93,9 @@ int test_ldpc(short No_iteration,
*
errors
=
0
;
*
errors
=
0
;
*
crc_misses
=
0
;
*
crc_misses
=
0
;
// generate input block
// generate input block
test_input
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
block_length
/
8
);
for
(
j
=
0
;
j
<
8
;
j
++
)
test_input
[
j
]
=
(
unsigned
char
*
)
malloc16
(
sizeof
(
unsigned
char
)
*
block_length
/
8
);
channel_input
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
68
*
384
);
channel_input
=
(
unsigned
char
*
)
malloc
16
(
sizeof
(
unsigned
char
)
*
68
*
384
);
channel_input_optim
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
68
*
384
);
for
(
j
=
0
;
j
<
8
;
j
++
)
channel_input_optim
[
j
]
=
(
unsigned
char
*
)
malloc16
(
sizeof
(
unsigned
char
)
*
68
*
384
);
modulated_input
=
(
double
*
)
malloc
(
sizeof
(
double
)
*
68
*
384
);
modulated_input
=
(
double
*
)
malloc
(
sizeof
(
double
)
*
68
*
384
);
channel_output
=
(
double
*
)
malloc
(
sizeof
(
double
)
*
68
*
384
);
channel_output
=
(
double
*
)
malloc
(
sizeof
(
double
)
*
68
*
384
);
reset_meas
(
&
time
);
reset_meas
(
&
time
);
...
@@ -107,7 +107,7 @@ int test_ldpc(short No_iteration,
...
@@ -107,7 +107,7 @@ int test_ldpc(short No_iteration,
for
(
i
=
0
;
i
<
block_length
/
8
;
i
++
)
for
(
i
=
0
;
i
<
block_length
/
8
;
i
++
)
{
{
//test_input[i]=(unsigned char) rand();
//test_input[i]=(unsigned char) rand();
test_input
[
i
]
=
217
;
for
(
j
=
0
;
j
<
8
;
j
++
)
test_input
[
j
]
[
i
]
=
217
;
}
}
//determine number of bits in codeword
//determine number of bits in codeword
...
@@ -152,7 +152,7 @@ int test_ldpc(short No_iteration,
...
@@ -152,7 +152,7 @@ int test_ldpc(short No_iteration,
// printf("puncture:%d\n",no_punctured_columns);
// printf("puncture:%d\n",no_punctured_columns);
removed_bit
=
(
nrows
-
no_punctured_columns
-
2
)
*
Zc
+
block_length
-
(
int
)(
block_length
/
((
float
)
nom_rate
/
(
float
)
denom_rate
));
removed_bit
=
(
nrows
-
no_punctured_columns
-
2
)
*
Zc
+
block_length
-
(
int
)(
block_length
/
((
float
)
nom_rate
/
(
float
)
denom_rate
));
if
(
ntrials
==
0
)
if
(
ntrials
==
0
)
ldpc_encoder_orig
(
test_input
,
channel_input
,
block_length
,
nom_rate
,
denom_rate
,
1
);
ldpc_encoder_orig
(
test_input
[
0
]
,
channel_input
,
block_length
,
nom_rate
,
denom_rate
,
1
);
for
(
trial
=
0
;
trial
<
ntrials
;
trial
++
)
for
(
trial
=
0
;
trial
<
ntrials
;
trial
++
)
{
{
...
@@ -163,18 +163,19 @@ int test_ldpc(short No_iteration,
...
@@ -163,18 +163,19 @@ int test_ldpc(short No_iteration,
//if (BG==1)
//if (BG==1)
//ldpc_encoder(test_input, channel_input,block_length,nom_rate,denom_rate);
//ldpc_encoder(test_input, channel_input,block_length,nom_rate,denom_rate);
//else
//else
ldpc_encoder_orig
(
test_input
,
channel_input
,
block_length
,
nom_rate
,
denom_rate
,
0
);
ldpc_encoder_orig
(
test_input
[
0
]
,
channel_input
,
block_length
,
nom_rate
,
denom_rate
,
0
);
stop_meas
(
&
time
);
stop_meas
(
&
time
);
start_meas
(
&
time_optim
);
start_meas
(
&
time_optim
);
ldpc_encoder_optim
(
test_input
,
channel_input_optim
,
block_length
,
nom_rate
,
denom_rate
,
&
tinput
,
&
tprep
,
&
tparity
,
&
toutput
);
// ldpc_encoder_optim_8seg(test_input[0],channel_input_optim[0],block_length,nom_rate,denom_rate,&tinput,&tprep,&tparity,&toutput);
ldpc_encoder_optim_8seg
(
test_input
,
channel_input_optim
,
block_length
,
nom_rate
,
denom_rate
,
8
,
&
tinput
,
&
tprep
,
&
tparity
,
&
toutput
);
stop_meas
(
&
time_optim
);
stop_meas
(
&
time_optim
);
if
(
ntrials
==
1
)
if
(
ntrials
==
1
)
for
(
i
=
0
;
i
<
block_length
+
(
nrows
-
no_punctured_columns
)
*
Zc
-
removed_bit
;
i
++
)
for
(
i
=
0
;
i
<
block_length
+
(
nrows
-
no_punctured_columns
)
*
Zc
-
removed_bit
;
i
++
)
if
(
channel_input
[
i
]
!=
channel_input_optim
[
i
])
printf
(
"differ in pos %d (%d,%d)
\n
"
,
i
,
if
(
channel_input
[
i
]
!=
channel_input_optim
[
0
][
i
])
printf
(
"differ in pos %d (%d,%d)
\n
"
,
i
,
channel_input
[
i
],
channel_input
[
i
],
channel_input_optim
[
i
]);
channel_input_optim
[
0
][
i
]);
//print_meas_now(&time, "", stdout);
//print_meas_now(&time, "", stdout);
// for (i=0;i<6400;i++)
// for (i=0;i<6400;i++)
...
...
openair1/PHY/CODING/defs.h
View file @
6bf628c5
...
@@ -578,5 +578,5 @@ int ldpc_encoder(unsigned char *test_input,unsigned char *channel_input,short bl
...
@@ -578,5 +578,5 @@ int ldpc_encoder(unsigned char *test_input,unsigned char *channel_input,short bl
int
ldpc_encoder_orig
(
unsigned
char
*
test_input
,
unsigned
char
*
channel_input
,
short
block_length
,
int
nom_rate
,
int
denom_rate
,
unsigned
char
gen_code
);
int
ldpc_encoder_orig
(
unsigned
char
*
test_input
,
unsigned
char
*
channel_input
,
short
block_length
,
int
nom_rate
,
int
denom_rate
,
unsigned
char
gen_code
);
int
ldpc_encoder_multi_segment
(
unsigned
char
**
test_input
,
unsigned
char
**
channel_input
,
short
block_length
,
double
rate
,
uint8_t
n_segments
);
int
ldpc_encoder_multi_segment
(
unsigned
char
**
test_input
,
unsigned
char
**
channel_input
,
short
block_length
,
double
rate
,
uint8_t
n_segments
);
int
ldpc_encoder_optim
(
unsigned
char
*
test_input
,
unsigned
char
*
channel_input
,
short
block_length
,
int
nom_rate
,
int
denom_rate
,
time_stats_t
*
tinput
,
time_stats_t
*
tprep
,
time_stats_t
*
tparity
,
time_stats_t
*
toutput
);
int
ldpc_encoder_optim
(
unsigned
char
*
test_input
,
unsigned
char
*
channel_input
,
short
block_length
,
int
nom_rate
,
int
denom_rate
,
time_stats_t
*
tinput
,
time_stats_t
*
tprep
,
time_stats_t
*
tparity
,
time_stats_t
*
toutput
);
int
ldpc_encoder_optim_8seg
(
unsigned
char
**
test_input
,
unsigned
char
**
channel_input
,
short
block_length
,
int
nom_rate
,
int
denom_rate
,
int
n_segments
,
time_stats_t
*
tinput
,
time_stats_t
*
tprep
,
time_stats_t
*
tparity
,
time_stats_t
*
toutput
);
#endif
#endif
openair1/PHY/CODING/ldpc_encoder2.c
View file @
6bf628c5
...
@@ -164,12 +164,14 @@ void encode_parity_check_part_optim(uint8_t *c,uint8_t *d, short BG,short Zc,sho
...
@@ -164,12 +164,14 @@ void encode_parity_check_part_optim(uint8_t *c,uint8_t *d, short BG,short Zc,sho
}
}
int
ldpc_encoder_optim
(
unsigned
char
*
test_input
,
unsigned
char
*
channel_input
,
short
block_length
,
int
nom_rate
,
int
denom_rate
,
time_stats_t
*
tinput
,
time_stats_t
*
tprep
,
time_stats_t
*
tparity
,
time_stats_t
*
toutput
)
int
ldpc_encoder_optim
(
unsigned
char
*
test_input
,
unsigned
char
*
channel_input
,
short
block_length
,
int
nom_rate
,
int
denom_rate
,
time_stats_t
*
tinput
,
time_stats_t
*
tprep
,
time_stats_t
*
tparity
,
time_stats_t
*
toutput
)
{
{
short
BG
,
Zc
,
Kb
,
nrows
,
ncols
;
short
BG
,
Zc
,
Kb
,
nrows
,
ncols
;
int
i
,
i1
;
int
i
,
i1
;
int
no_punctured_columns
,
removed_bit
;
int
no_punctured_columns
,
removed_bit
;
//Table of possible lifting sizes
//Table of possible lifting sizes
short
lift_size
[
51
]
=
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
18
,
20
,
22
,
24
,
26
,
28
,
30
,
32
,
36
,
40
,
44
,
48
,
52
,
56
,
60
,
64
,
72
,
80
,
88
,
96
,
104
,
112
,
120
,
128
,
144
,
160
,
176
,
192
,
208
,
224
,
240
,
256
,
288
,
320
,
352
,
384
};
short
lift_size
[
51
]
=
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
18
,
20
,
22
,
24
,
26
,
28
,
30
,
32
,
36
,
40
,
44
,
48
,
52
,
56
,
60
,
64
,
72
,
80
,
88
,
96
,
104
,
112
,
120
,
128
,
144
,
160
,
176
,
192
,
208
,
224
,
240
,
256
,
288
,
320
,
352
,
384
};
...
@@ -230,12 +232,14 @@ int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,sh
...
@@ -230,12 +232,14 @@ int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,sh
memset
(
d
,
0
,
sizeof
(
unsigned
char
)
*
nrows
*
Zc
);
memset
(
d
,
0
,
sizeof
(
unsigned
char
)
*
nrows
*
Zc
);
start_meas
(
tinput
);
start_meas
(
tinput
);
for
(
i
=
0
;
i
<
block_length
;
i
++
)
for
(
i
=
0
;
i
<
block_length
;
i
++
)
{
{
//c[i] = test_input[i/8]<<(i%8);
//c[i] = test_input[i/8]<<(i%8);
//c[i]=c[i]>>7&1;
//c[i]=c[i]>>7&1;
c
[
i
]
=
(
test_input
[
i
/
8
]
&
(
1
<<
(
i
&
7
)))
>>
(
i
&
7
);
c
[
i
]
=
(
test_input
[
i
/
8
]
&
(
1
<<
(
i
&
7
)))
>>
(
i
&
7
);
}
}
stop_meas
(
tinput
);
stop_meas
(
tinput
);
if
((
BG
==
1
)
||
(
BG
==
2
&&
Zc
>
64
))
{
if
((
BG
==
1
)
||
(
BG
==
2
&&
Zc
>
64
))
{
...
@@ -274,3 +278,158 @@ int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,sh
...
@@ -274,3 +278,158 @@ int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,sh
stop_meas
(
toutput
);
stop_meas
(
toutput
);
return
0
;
return
0
;
}
}
int
ldpc_encoder_optim_8seg
(
unsigned
char
**
test_input
,
unsigned
char
**
channel_input
,
short
block_length
,
int
nom_rate
,
int
denom_rate
,
int
n_segments
,
time_stats_t
*
tinput
,
time_stats_t
*
tprep
,
time_stats_t
*
tparity
,
time_stats_t
*
toutput
)
{
short
BG
,
Zc
,
Kb
,
nrows
,
ncols
;
int
i
,
i1
,
j
;
int
no_punctured_columns
,
removed_bit
;
//Table of possible lifting sizes
short
lift_size
[
51
]
=
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
18
,
20
,
22
,
24
,
26
,
28
,
30
,
32
,
36
,
40
,
44
,
48
,
52
,
56
,
60
,
64
,
72
,
80
,
88
,
96
,
104
,
112
,
120
,
128
,
144
,
160
,
176
,
192
,
208
,
224
,
240
,
256
,
288
,
320
,
352
,
384
};
int
simd_size
;
AssertFatal
(
n_segments
>
0
&&
n_segments
<=
8
,
"0 < n_segments %d <= 8
\n
"
,
n_segments
);
//determine number of bits in codeword
if
(
block_length
>
3840
)
{
BG
=
1
;
Kb
=
22
;
nrows
=
46
;
//parity check bits
ncols
=
22
;
//info bits
}
else
if
(
block_length
<=
3840
)
{
BG
=
2
;
nrows
=
42
;
//parity check bits
ncols
=
10
;
// info bits
if
(
block_length
>
640
)
Kb
=
10
;
else
if
(
block_length
>
560
)
Kb
=
9
;
else
if
(
block_length
>
192
)
Kb
=
8
;
else
Kb
=
6
;
}
//find minimum value in all sets of lifting size
Zc
=
0
;
for
(
i1
=
0
;
i1
<
51
;
i1
++
)
{
if
(
lift_size
[
i1
]
>=
(
double
)
block_length
/
Kb
)
{
Zc
=
lift_size
[
i1
];
//printf("%d\n",Zc);
break
;
}
}
AssertFatal
(
Zc
>
0
,
"no valid Zc found for block length %d
\n
"
,
block_length
);
if
((
Zc
&
31
)
>
0
)
simd_size
=
16
;
else
simd_size
=
32
;
unsigned
char
c
[
22
*
Zc
]
__attribute__
((
aligned
(
32
)));
//padded input, unpacked, max size
unsigned
char
d
[
46
*
Zc
]
__attribute__
((
aligned
(
32
)));
//coded parity part output, unpacked, max size
unsigned
char
c_extension
[
2
*
22
*
Zc
*
simd_size
]
__attribute__
((
aligned
(
32
)));
//double size matrix of c
// calculate number of punctured bits
no_punctured_columns
=
(
int
)((
nrows
-
2
)
*
Zc
+
block_length
-
block_length
*
3
)
/
Zc
;
removed_bit
=
(
nrows
-
no_punctured_columns
-
2
)
*
Zc
+
block_length
-
(
int
)(
block_length
*
3
);
// printf("%d\n",no_punctured_columns);
// printf("%d\n",removed_bit);
// unpack input
memset
(
c
,
0
,
sizeof
(
unsigned
char
)
*
ncols
*
Zc
);
memset
(
d
,
0
,
sizeof
(
unsigned
char
)
*
nrows
*
Zc
);
start_meas
(
tinput
);
#if 0
char temp;
for (i=0; i<block_length; i++) {
for (j=0; j<n_segments; j++) {
temp = (test_input[j][i/8]&(1<<(i&7)))>>(i&7);
//printf("c(%d,%d)=%d\n",j,i,temp);
c[i] |= (temp << j);
}
}
#else
#ifdef __AVX2__
__m256i
shufmask
=
_mm256_set_epi64x
(
0x0303030303030303
,
0x0202020202020202
,
0x0101010101010101
,
0x0000000000000000
);
__m256i
andmask
=
_mm256_set1_epi64x
(
0x8040201008040201
);
// every 8 bits -> 8 bytes, pattern repeats.
__m256i
zero256
=
_mm256_setzero_si256
();
__m256i
masks
[
8
];
register
__m256i
c256
;
masks
[
0
]
=
_mm256_set1_epi8
(
0x1
);
masks
[
1
]
=
_mm256_set1_epi8
(
0x2
);
masks
[
2
]
=
_mm256_set1_epi8
(
0x4
);
masks
[
3
]
=
_mm256_set1_epi8
(
0x8
);
masks
[
4
]
=
_mm256_set1_epi8
(
0x10
);
masks
[
5
]
=
_mm256_set1_epi8
(
0x20
);
masks
[
6
]
=
_mm256_set1_epi8
(
0x40
);
masks
[
7
]
=
_mm256_set1_epi8
(
0x80
);
for
(
i
=
0
;
i
<
block_length
>>
5
;
i
++
)
{
c256
=
_mm256_and_si256
(
_mm256_cmpeq_epi8
(
_mm256_andnot_si256
(
_mm256_shuffle_epi8
(
_mm256_set1_epi32
(((
uint32_t
*
)
test_input
[
0
])[
i
]),
shufmask
),
andmask
),
zero256
),
masks
[
0
]);
for
(
j
=
1
;
j
<
n_segments
;
j
++
)
{
c256
=
_mm256_or_si256
(
_mm256_and_si256
(
_mm256_cmpeq_epi8
(
_mm256_andnot_si256
(
_mm256_shuffle_epi8
(
_mm256_set1_epi32
(((
uint32_t
*
)
test_input
[
j
])[
i
]),
shufmask
),
andmask
),
zero256
),
masks
[
j
]),
c256
);
}
((
__m256i
*
)
c
)[
i
]
=
c256
;
}
#else
AssertFatal
(
1
==
0
,
"Need AVX2 for this
\n
"
);
#endif
#endif
stop_meas
(
tinput
);
if
((
BG
==
1
)
||
(
BG
==
2
&&
Zc
>
64
))
{
// extend matrix
start_meas
(
tprep
);
for
(
i1
=
0
;
i1
<
ncols
;
i1
++
)
{
memcpy
(
&
c_extension
[
2
*
i1
*
Zc
],
&
c
[
i1
*
Zc
],
Zc
*
sizeof
(
unsigned
char
));
memcpy
(
&
c_extension
[(
2
*
i1
+
1
)
*
Zc
],
&
c
[
i1
*
Zc
],
Zc
*
sizeof
(
unsigned
char
));
}
for
(
i1
=
1
;
i1
<
simd_size
;
i1
++
)
{
memcpy
(
&
c_extension
[(
2
*
ncols
*
Zc
*
i1
)],
&
c_extension
[
i1
],
(
2
*
ncols
*
Zc
*
sizeof
(
unsigned
char
))
-
i1
);
// memset(&c_extension[(2*ncols*Zc*i1)],0,i1);
/*
printf("shift %d: ",i1);
for (int j=0;j<64;j++) printf("%d ",c_extension[(2*ncols*Zc*i1)+j]);
printf("\n");
*/
}
stop_meas
(
tprep
);
//parity check part
start_meas
(
tparity
);
encode_parity_check_part_optim
(
c_extension
,
d
,
BG
,
Zc
,
Kb
);
stop_meas
(
tparity
);
}
else
{
if
(
encode_parity_check_part_orig
(
c
,
d
,
BG
,
Zc
,
Kb
,
block_length
)
!=
0
)
{
printf
(
"Problem with encoder
\n
"
);
return
(
-
1
);
}
}
start_meas
(
toutput
);
// information part and puncture columns
/*
memcpy(&channel_input[0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char));
memcpy(&channel_input[block_length-2*Zc], &d[0], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char));
*/
for
(
i
=
0
;
i
<
(
block_length
-
2
*
Zc
);
i
++
)
for
(
j
=
0
;
j
<
n_segments
;
j
++
)
channel_input
[
j
][
i
]
=
(
c
[
2
*
Zc
+
i
]
>>
j
)
&
1
;
for
(
i
=
0
;
i
<
((
nrows
-
no_punctured_columns
)
*
Zc
-
removed_bit
);
i
++
)
for
(
j
=
0
;
j
<
n_segments
;
j
++
)
channel_input
[
j
][
block_length
-
2
*
Zc
+
i
]
=
(
d
[
i
]
>>
j
)
&
1
;
stop_meas
(
toutput
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment