Skip to content
Snippets Groups Projects
debug.cc 1.84 KiB


#ifndef RUNTIME_DEBUG
#define RUNTIME_DEBUG

#define LOG_DEBUG 0 // Sets the debug logging to true
#define LOG_INFO 1  // Sets the info logging to true
#define ASSERT_FLAG // Sets assertions to true (opposite of NDEBUG macro)

#include "debug.h"
#include "tensor.h"
#include <sstream>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

void INFO(const char *format, ...) {
  if (!LOG_INFO) // Don't print if logging info is disabled
    return;
  va_list args;
  va_start(args, format);
  printf("INFO: ");
  vprintf(format, args);
  va_end(args);
}

void DEBUG(const char *format, ...) {
  if (!LOG_DEBUG) // Don't print if logging info is disabled
    return;
  va_list args;
  va_start(args, format);
  printf("DEBUG: ");
  vprintf(format, args);
  va_end(args);
}

void ERROR(const char *format, ...) {
  if (!LOG_DEBUG) // Don't print if logging info is disabled
    return;
  va_list args;
  va_start(args, format);
  printf("ERROR!: ");
  vprintf(format, args);
  va_end(args);

  abort();
}

void fillOnes(struct Tensor *tensor) {
  // initialization is specific to the floating point type
  if (tensor->data_type == CUDNN_DATA_FLOAT) {
    float *data_arr = (float *)tensor->host_data;
    for (unsigned int i = 0; i < tensor->num_elems; i++) {
      data_arr[i] = 1.0;
    }
  }
}

void printTensorDescInfo(struct Tensor *tensor) {

  cudnnDataType_t dType;
  int nStride, cStride, hStride, wStride;
  int size1, size2, size3, size4;
  cudnnGetTensor4dDescriptor(tensor->tensor_desc, &dType, &size1, &size2,
                             &size3, &size4, &nStride, &cStride, &hStride,
                             &wStride);

  DEBUG("dType = %d, size1 = %d, size2 = %d, size3 = %d, size4 = %d \n", dType,
        size1, size2, size3, size4);
  DEBUG("nStride = %d, cStride = %d, hStride = %d, wStride = %d \n", nStride,
        cStride, hStride, wStride);
}

#endif