commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 12/39: fec: LDPC: Improving memory manageme


From: git
Subject: [Commit-gnuradio] [gnuradio] 12/39: fec: LDPC: Improving memory management (GSL matrices).
Date: Thu, 15 Oct 2015 21:21:28 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 8e831a3c8bf76c25c542e7cbe8ced10d6dd35f09
Author: tracierenea <address@hidden>
Date:   Sat Jul 26 15:39:39 2014 -0500

    fec: LDPC: Improving memory management (GSL matrices).
---
 gr-fec/lib/ldpc_R_U_encoder_impl.cc      | 47 ++++++++++++++++++--------------
 gr-fec/lib/ldpc_R_U_encoder_impl.h       |  2 +-
 gr-fec/lib/ldpc_bit_flip_decoder_impl.cc | 33 ++++++++++++----------
 gr-fec/lib/ldpc_bit_flip_decoder_impl.h  |  6 +++-
 4 files changed, 50 insertions(+), 38 deletions(-)

diff --git a/gr-fec/lib/ldpc_R_U_encoder_impl.cc 
b/gr-fec/lib/ldpc_R_U_encoder_impl.cc
index 7da8e12..01ebfca 100644
--- a/gr-fec/lib/ldpc_R_U_encoder_impl.cc
+++ b/gr-fec/lib/ldpc_R_U_encoder_impl.cc
@@ -92,27 +92,19 @@ namespace gr {
           gsl_matrix_set(s, index, 0, value);
         }
 
-        // Solve for p2 (parity part)
-        const gsl_matrix *A     = d_H->A();
-        const gsl_matrix *B     = d_H->B();
-        const gsl_matrix *D     = d_H->D();
-        const gsl_matrix *E     = d_H->E();
-        const gsl_matrix *inv_T = d_H->T_inverse();
-        const gsl_matrix *inv_p = d_H->phi_inverse();
-        const gsl_matrix *temp1 = d_H->mult_matrices_mod2(B, s);
-        const gsl_matrix *temp2 = d_H->mult_matrices_mod2(inv_T,
-                                                          temp1);
-        const gsl_matrix *temp3 = d_H->mult_matrices_mod2(E, temp2);
-        const gsl_matrix *temp4 = d_H->mult_matrices_mod2(D, s);
-        const gsl_matrix *temp5 = d_H->add_matrices_mod2(temp4,
-                                                         temp3);
-        const gsl_matrix *p2 = d_H->mult_matrices_mod2(inv_p, temp5);
-
-        // Solve for p1 (parity part)
-        const gsl_matrix *temp6 = d_H->mult_matrices_mod2(A, p2);
-        const gsl_matrix *temp7 = d_H->add_matrices_mod2(temp6,
-                                                         temp1);
-        const gsl_matrix *p1 = d_H->mult_matrices_mod2(inv_T, temp7);
+        // Solve for p2 and p1 (parity parts)
+        gsl_matrix *temp1 = d_H->mult_matrices_mod2(d_H->B(), s);
+        gsl_matrix *temp2 = d_H->mult_matrices_mod2(
+                                         d_H->T_inverse(), temp1);
+        gsl_matrix *temp3 = d_H->mult_matrices_mod2(d_H->E(), temp2);
+        gsl_matrix *temp4 = d_H->mult_matrices_mod2(d_H->D(), s);
+        gsl_matrix *temp5 = d_H->add_matrices_mod2(temp4, temp3);
+        gsl_matrix *p2    = d_H->mult_matrices_mod2(
+                                         d_H->phi_inverse(), temp5);
+        gsl_matrix *temp6 = d_H->mult_matrices_mod2(d_H->A(), p2);
+        gsl_matrix *temp7 = d_H->add_matrices_mod2(temp6, temp1);
+        gsl_matrix *p1    = d_H->mult_matrices_mod2(
+                                         d_H->T_inverse(), temp7);
 
         // Populate the codeword to be output
         unsigned int p1_length = (*p1).size1;
@@ -130,6 +122,19 @@ namespace gr {
           int value = gsl_matrix_get(s, index, 0);
           out[p1_length+p2_length+index] = value;
         }
+
+        // Free memory
+        gsl_matrix_free(temp1);
+        gsl_matrix_free(temp2);
+        gsl_matrix_free(temp3);
+        gsl_matrix_free(temp4);
+        gsl_matrix_free(temp5);
+        gsl_matrix_free(temp6);
+        gsl_matrix_free(temp7);
+        gsl_matrix_free(p1);
+        gsl_matrix_free(p2);
+        gsl_matrix_free(s);
+
       }
     } /* namespace code */
   } /* namespace fec */
diff --git a/gr-fec/lib/ldpc_R_U_encoder_impl.h 
b/gr-fec/lib/ldpc_R_U_encoder_impl.h
index 97102c0..d2cacff 100644
--- a/gr-fec/lib/ldpc_R_U_encoder_impl.h
+++ b/gr-fec/lib/ldpc_R_U_encoder_impl.h
@@ -38,7 +38,7 @@ namespace gr {
 
         // Number of bits in the information word
         unsigned int d_frame_size;
-        // LDPC parity check matrix to use for encoding
+        // LDPC parity check matrix object to use for encoding
         ldpc_par_chk_mtrx *d_H;
 
       public:
diff --git a/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc 
b/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
index c960bd2..dd5051d 100644
--- a/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
+++ b/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
@@ -56,6 +56,9 @@ namespace gr {
 
       ldpc_bit_flip_decoder_impl::~ldpc_bit_flip_decoder_impl()
       {
+        // Free memory
+        gsl_matrix_free(d_syndrome);
+        gsl_matrix_free(d_x);
       }
 
       int
@@ -99,27 +102,24 @@ namespace gr {
         const float *in = (const float*)inbuffer;
 
         unsigned int index, n = d_H->n();
-        gsl_matrix *x = gsl_matrix_alloc(n, 1);
+        d_x = gsl_matrix_alloc(n, 1);
         for (index = 0; index < n; index++) {
           double value = in[index] > 0 ? 1.0 : 0.0;
-          gsl_matrix_set(x, index, 0, value);
+          gsl_matrix_set(d_x, index, 0, value);
         }
 
-        // Parity check matrix to use
-        const gsl_matrix *H = d_H->H();
-
         // Initialize counter
         unsigned int count = 0;
 
         // Calculate syndrome
-        gsl_matrix *syndrome = d_H->mult_matrices_mod2(H, x);
+        d_syndrome = d_H->mult_matrices_mod2(d_H->H(), d_x);
 
         // Flag for finding a valid codeword
         bool found_word = false;
  
         // If the syndrome is all 0s, then codeword is valid and we
         // don't need to loop; we're done.
-        if (gsl_matrix_isnull(syndrome)) {
+        if (gsl_matrix_isnull(d_syndrome)) {
           found_word = true;
         }
 
@@ -132,8 +132,8 @@ namespace gr {
           // syndrome. The entry numbers correspond to the rows of
           // interest in H.
           std::vector<int> rows_of_interest_in_H;
-          for (index = 0; index < (*syndrome).size1; index++) {
-            if (gsl_matrix_get(syndrome, index, 0)) {
+          for (index = 0; index < (*d_syndrome).size1; index++) {
+            if (gsl_matrix_get(d_syndrome, index, 0)) {
               rows_of_interest_in_H.push_back(index);
             }
           }
@@ -146,7 +146,9 @@ namespace gr {
           for (i = 0; i < rows_of_interest_in_H.size(); i++) {
             unsigned int row_num = rows_of_interest_in_H[i];
             for (col_num = 0; col_num < n; col_num++) {
-              double value = gsl_matrix_get(H, row_num, col_num);
+              double value = gsl_matrix_get(d_H->H(),
+                                            row_num,
+                                            col_num);
               if (value > 0) {
                 counts[col_num] = counts[col_num] + 1;
               }
@@ -164,15 +166,15 @@ namespace gr {
 
           for (index = 0; index < n; index++) {
             if (counts[index] == max) {
-              unsigned int value = gsl_matrix_get(x, index, 0);
+              unsigned int value = gsl_matrix_get(d_x, index, 0);
               unsigned int new_value = value ^ 1;
-              gsl_matrix_set(x, index, 0, new_value);
+              gsl_matrix_set(d_x, index, 0, new_value);
             }
           }
 
           // Check the syndrome; see if valid codeword has been found
-          syndrome = d_H->mult_matrices_mod2(H, x);
-          if (gsl_matrix_isnull(syndrome)) {
+          d_syndrome = d_H->mult_matrices_mod2(d_H->H(), d_x);
+          if (gsl_matrix_isnull(d_syndrome)) {
             found_word = true;
             break;
           }
@@ -184,8 +186,9 @@ namespace gr {
         unsigned char *out = (unsigned char*) outbuffer;
         for (index = 0; index < d_frame_size; index++) {
           unsigned int i = index + n - d_frame_size;
-          int value = gsl_matrix_get(x, i, 0);
+          int value = gsl_matrix_get(d_x, i, 0);
           out[index] = value;
+
         }
       } /* ldpc_bit_flip_decoder_impl::generic_work() */     
     } /* namespace code */
diff --git a/gr-fec/lib/ldpc_bit_flip_decoder_impl.h 
b/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
index 85c6012..8763750 100644
--- a/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
+++ b/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
@@ -36,10 +36,14 @@ namespace gr {
         int get_output_size();  // k, # of bits in the info word
         unsigned int d_frame_size;
 
-        // LDPC parity check matrix to use for decoding
+        // LDPC parity check matrix object to use for decoding
         ldpc_par_chk_mtrx *d_H;
         // Maximum number of iterations to do in decoding algorithm
         unsigned int d_max_iterations;
+        // Syndrome for each codeword guess
+        gsl_matrix *d_syndrome;
+        // Codeword
+        gsl_matrix *d_x;
 
       public:
         ldpc_bit_flip_decoder_impl(ldpc_par_chk_mtrx *H_obj,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]