Commit 933d4754 authored by Mark Ruzindana's avatar Mark Ruzindana
Browse files

Writing to unmodified binary file in flag_beamsave_thread.c

parent 296a69d0
...@@ -57,7 +57,7 @@ void update_weights(char * filename){ ...@@ -57,7 +57,7 @@ void update_weights(char * filename){
//weights_dc = (float complex *)malloc(BN_WEIGHTS*sizeof(float complex *)); //weights_dc = (float complex *)malloc(BN_WEIGHTS*sizeof(float complex *));
//weights_dc_n = (float complex *)malloc(BN_WEIGHTS*sizeof(float complex *)); //weights_dc_n = (float complex *)malloc(BN_WEIGHTS*sizeof(float complex *));
// For pinned memory //////////////////////////////////////////////////// // For pinned memory ////////////////////////////////////////////////////
// Weights doesn't need pinned memory implemented because it is less than 16 MB /////////// // Weights don't need pinned memory implemented because it is less than 16 MB ///////////
cudaMallocHost((void **)&bf_weights,2*BN_WEIGHTS*sizeof(float complex *)); cudaMallocHost((void **)&bf_weights,2*BN_WEIGHTS*sizeof(float complex *));
cudaMallocHost((void **)&weights_dc,BN_WEIGHTS*sizeof(float complex *)); cudaMallocHost((void **)&weights_dc,BN_WEIGHTS*sizeof(float complex *));
cudaMallocHost((void **)&weights_dc_n,BN_WEIGHTS*sizeof(float complex *)); cudaMallocHost((void **)&weights_dc_n,BN_WEIGHTS*sizeof(float complex *));
...@@ -728,7 +728,6 @@ void rtbfCleanup() { ...@@ -728,7 +728,6 @@ void rtbfCleanup() {
if (d_data1 != NULL) { if (d_data1 != NULL) {
cudaFree(d_data1); cudaFree(d_data1);
//cudaFreeHost(d_data1); // Clean up pinned memory (use cudaFreeHost() with cudaMallocHost())
} }
if (d_data2 != NULL) { if (d_data2 != NULL) {
...@@ -741,7 +740,6 @@ void rtbfCleanup() { ...@@ -741,7 +740,6 @@ void rtbfCleanup() {
if (d_weights != NULL) { if (d_weights != NULL) {
cudaFree(d_weights); cudaFree(d_weights);
//cudaFreeHost(d_weights); // Clean up pinned memory (use cudaFreeHost() with cudaMallocHost())
} }
if (d_arr_A != NULL) { if (d_arr_A != NULL) {
......
...@@ -57,7 +57,7 @@ void update_weights(char * filename){ ...@@ -57,7 +57,7 @@ void update_weights(char * filename){
//weights_dc = (float complex *)malloc(BN_WEIGHTS*sizeof(float complex *)); //weights_dc = (float complex *)malloc(BN_WEIGHTS*sizeof(float complex *));
//weights_dc_n = (float complex *)malloc(BN_WEIGHTS*sizeof(float complex *)); //weights_dc_n = (float complex *)malloc(BN_WEIGHTS*sizeof(float complex *));
// For pinned memory //////////////////////////////////////////////////// // For pinned memory ////////////////////////////////////////////////////
// Weights doesn't need pinned memory implemented because it is less than 16 MB /////////// // Weights don't need pinned memory implemented because it is less than 16 MB ///////////
cudaMallocHost((void **)&bf_weights,2*BN_WEIGHTS*sizeof(float complex *)); cudaMallocHost((void **)&bf_weights,2*BN_WEIGHTS*sizeof(float complex *));
cudaMallocHost((void **)&weights_dc,BN_WEIGHTS*sizeof(float complex *)); cudaMallocHost((void **)&weights_dc,BN_WEIGHTS*sizeof(float complex *));
cudaMallocHost((void **)&weights_dc_n,BN_WEIGHTS*sizeof(float complex *)); cudaMallocHost((void **)&weights_dc_n,BN_WEIGHTS*sizeof(float complex *));
...@@ -728,7 +728,6 @@ void rtbfCleanup() { ...@@ -728,7 +728,6 @@ void rtbfCleanup() {
if (d_data1 != NULL) { if (d_data1 != NULL) {
cudaFree(d_data1); cudaFree(d_data1);
//cudaFreeHost(d_data1); // Clean up pinned memory (use cudaFreeHost() with cudaMallocHost())
} }
if (d_data2 != NULL) { if (d_data2 != NULL) {
...@@ -741,7 +740,6 @@ void rtbfCleanup() { ...@@ -741,7 +740,6 @@ void rtbfCleanup() {
if (d_weights != NULL) { if (d_weights != NULL) {
cudaFree(d_weights); cudaFree(d_weights);
//cudaFreeHost(d_weights); // Clean up pinned memory (use cudaFreeHost() with cudaMallocHost())
} }
if (d_arr_A != NULL) { if (d_arr_A != NULL) {
......
...@@ -69,6 +69,8 @@ static void *run(hashpipe_thread_args_t * args) ...@@ -69,6 +69,8 @@ static void *run(hashpipe_thread_args_t * args)
hputi4(st.buf, "NULBLKIN", block_idx); hputi4(st.buf, "NULBLKIN", block_idx);
hashpipe_status_unlock_safe(&st); hashpipe_status_unlock_safe(&st);
fprintf(stderr, "Writing to /dev/null\n");
// Mark block as free // Mark block as free
hashpipe_databuf_set_free(db, block_idx); hashpipe_databuf_set_free(db, block_idx);
......
#define XGPU_VERSION 0.1+182@g6ce42de-dirty #define XGPU_VERSION 0.1+183@g296a69d-dirty
...@@ -71,8 +71,11 @@ static void * run(hashpipe_thread_args_t * args) { ...@@ -71,8 +71,11 @@ static void * run(hashpipe_thread_args_t * args) {
hashpipe_status_unlock_safe(&st); hashpipe_status_unlock_safe(&st);
char filename[256]; char filename[256];
sprintf(filename, "%s/TGBT16A_508_01/TMP/BF/beamformer_%s_mcnt_%lld.out", data_dir, BANK, (long long)start_mcnt); //sprintf(filename, "%s/TGBT16A_508_01/TMP/BF/beamformer_%s_mcnt_%lld.out", data_dir, BANK, (long long)start_mcnt);
fprintf(stderr, "Saving to %s\n", filename); //fprintf(stderr, "Saving to %s\n", filename);
//sprintf(filename, "/dev/null");
sprintf(filename, "%s/TGBT16A_508_01/TMP/BF/beamformer_%s.out", data_dir, BANK);
fprintf(stderr, "Saving to %s at mcnt %lld\n", filename, (long long)start_mcnt);
//printf("RTBF: mcnt: %lld\n", (long long)start_mcnt); //printf("RTBF: mcnt: %lld\n", (long long)start_mcnt);
if (SAVE) { if (SAVE) {
float * p = (float *)db_in->block[curblock_in].data; float * p = (float *)db_in->block[curblock_in].data;
......
/* flag_beamsave_thread.c
*
* Routine to save total power outputs to file for data verification
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include "hashpipe.h"
#include "flag_databuf.h"
#include <xgpu.h>
// #include "total_power.h"
// Create thread status buffer
static hashpipe_status_t * st_p;
// Run method for the thread
static void * run(hashpipe_thread_args_t * args) {
// Local aliases to shorten access to args fields
flag_gpu_beamformer_output_databuf_t * db_in = (flag_gpu_beamformer_output_databuf_t *)args->ibuf;
hashpipe_status_t st = args->st;
const char * status_key = args->thread_desc->skey;
st_p = &st; // allow global (this source file) access to the status buffer
//int instance_id = args[0].instance_id;
char data_dir[128];
hashpipe_status_lock_safe(&st);
hgets(st.buf, "DATADIR", 127, data_dir);
hashpipe_status_unlock_safe(&st);
if (data_dir == NULL) {
printf("SAV: DATADIR = .\n");
}
else {
printf("SAV: DATADIR = %s\n", data_dir);
}
// Mark thread as ready to run
hashpipe_status_lock_safe(&st);
hputi4(st.buf, "SAVEREADY", 1);
hashpipe_status_unlock_safe(&st);
int rv;
int curblock_in = 0;
while (run_threads()) {
// Wait for input buffer block to be filled
while ((rv=flag_gpu_beamformer_output_databuf_wait_filled(db_in, curblock_in)) != HASHPIPE_OK) {
if (rv==HASHPIPE_TIMEOUT) {
hashpipe_status_lock_safe(&st);
hputs(st.buf, status_key, "waiting for free block");
hashpipe_status_unlock_safe(&st);
}
else {
hashpipe_error(__FUNCTION__, "error waiting for filled databuf block");
pthread_exit(NULL);
break;
}
}
uint64_t start_mcnt = db_in->block[curblock_in].header.mcnt;
int good_data = (int)(db_in->block[curblock_in].header.good_data);
char BANK[5];
hashpipe_status_lock_safe(&st);
hgets(st.buf, "DATADIR", 127, data_dir);
hgets(st.buf, "BANKNAM", 4, BANK);
hashpipe_status_unlock_safe(&st);
char filename[256];
//sprintf(filename, "%s/TGBT16A_508_01/TMP/BF/beamformer_%s_mcnt_%lld.out", data_dir, BANK, (long long)start_mcnt);
//fprintf(stderr, "Saving to %s\n", filename);
//sprintf(filename, "/dev/null");
sprintf(filename, "%s/TGBT16A_508_01/TMP/BF/beamformer_%s.out", data_dir, BANK);
fprintf(stderr, "Saving to %s at mcnt %lld\n", filename, (long long)start_mcnt);
//printf("RTBF: mcnt: %lld\n", (long long)start_mcnt);
if (SAVE) {
float * p = (float *)db_in->block[curblock_in].data;
FILE * filePtr = fopen(filename, "w");
fwrite(p, sizeof(float), N_BEAM_SAMPS, filePtr);
fwrite(&good_data, sizeof(int), 1, filePtr);
fclose(filePtr);
}
// Mark input block as free and wait for next block
flag_gpu_beamformer_output_databuf_set_free(db_in, curblock_in);
curblock_in = (curblock_in + 1) % db_in->header.n_block;
// Check if program killed
pthread_testcancel();
}
// Thread terminates after loop
return NULL;
}
// Thread description
static hashpipe_thread_desc_t bsave_thread = {
name: "flag_beamsave_thread",
skey: "BEAMSAVE",
init: NULL,
run: run,
ibuf_desc: {flag_gpu_beamformer_output_databuf_create},
obuf_desc: {NULL}
};
static __attribute__((constructor)) void ctor() {
register_hashpipe_thread(&bsave_thread);
}
...@@ -292,7 +292,7 @@ static inline int64_t process_packet(flag_input_databuf_t * db, struct hashpipe_ ...@@ -292,7 +292,7 @@ static inline int64_t process_packet(flag_input_databuf_t * db, struct hashpipe_
while ((rv = flag_input_databuf_wait_free(db, get_block_idx(b))) != HASHPIPE_OK) { while ((rv = flag_input_databuf_wait_free(db, get_block_idx(b))) != HASHPIPE_OK) {
if (rv == HASHPIPE_TIMEOUT) { if (rv == HASHPIPE_TIMEOUT) {
printf("NET: HANGING HERE!!!!!!!!!!\n"); printf("NET: Initializing next block, HANGING HERE!!!!!!!!!!\n");
continue; continue;
} }
else { else {
...@@ -365,6 +365,7 @@ static inline int64_t process_packet(flag_input_databuf_t * db, struct hashpipe_ ...@@ -365,6 +365,7 @@ static inline int64_t process_packet(flag_input_databuf_t * db, struct hashpipe_
int rv; int rv;
while ((rv = flag_input_databuf_wait_free(db, dest_block_idx)) != HASHPIPE_OK) { while ((rv = flag_input_databuf_wait_free(db, dest_block_idx)) != HASHPIPE_OK) {
if (rv == HASHPIPE_TIMEOUT) { if (rv == HASHPIPE_TIMEOUT) {
printf("NET: Calculating starting points, HANGING HERE!!!!!!!!!!\n");
continue; continue;
} }
else { else {
...@@ -525,6 +526,7 @@ static void *run(hashpipe_thread_args_t * args) { ...@@ -525,6 +526,7 @@ static void *run(hashpipe_thread_args_t * args) {
// Wait until block semaphore is free // Wait until block semaphore is free
while ((rv = flag_input_databuf_wait_free(db, i)) != HASHPIPE_OK) { while ((rv = flag_input_databuf_wait_free(db, i)) != HASHPIPE_OK) {
if (rv == HASHPIPE_TIMEOUT) { if (rv == HASHPIPE_TIMEOUT) {
printf("NET: Waiting until semaphore is free, HANGING HERE!!!!!!!!!!\n");
continue; continue;
} }
if (errno == EINTR) { // Interrupt occurred if (errno == EINTR) { // Interrupt occurred
......
...@@ -196,6 +196,7 @@ static void * run(hashpipe_thread_args_t * args) { ...@@ -196,6 +196,7 @@ static void * run(hashpipe_thread_args_t * args) {
// Wait for output block to become free // Wait for output block to become free
while ((rv=flag_gpu_beamformer_output_databuf_wait_free(db_out, curblock_out)) != HASHPIPE_OK) { while ((rv=flag_gpu_beamformer_output_databuf_wait_free(db_out, curblock_out)) != HASHPIPE_OK) {
if (rv==HASHPIPE_TIMEOUT) { if (rv==HASHPIPE_TIMEOUT) {
printf("RTBF: Waiting for output block to be free, HANGING HERE!!!!!!!!!!\n");
continue; continue;
} else { } else {
hashpipe_error(__FUNCTION__, "error waiting for free databuf"); hashpipe_error(__FUNCTION__, "error waiting for free databuf");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment