redirect jupyter outputs

This commit is contained in:
Dun Liang 2020-04-28 19:48:46 +08:00
parent 2ed7ae6aec
commit c1e0861446
6 changed files with 36 additions and 23 deletions

View File

@ -17,6 +17,8 @@
#pragma once #pragma once
#include "utils/log.h"
#include <stdexcept> #include <stdexcept>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -103,10 +105,10 @@ template <typename T>
void check(T result, char const *const func, const char *const file, void check(T result, char const *const func, const char *const file,
int const line) { int const line) {
if (result) { if (result) {
fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line,
static_cast<unsigned int>(result), _cudaGetErrorEnum(result), func);
DEVICE_RESET DEVICE_RESET
throw std::runtime_error("CUDA error"); LOGf << "CUDA error at" << file >> ":" >> line << " code="
>> static_cast<unsigned int>(result) >> "(" << _cudaGetErrorEnum(result) << ")"
<< func;
} }
} }
@ -123,13 +125,10 @@ inline void __getLastCudaError(const char *errorMessage, const char *file,
cudaError_t err = cudaGetLastError(); cudaError_t err = cudaGetLastError();
if (cudaSuccess != err) { if (cudaSuccess != err) {
fprintf(stderr,
"%s(%i) : getLastCudaError() CUDA error :"
" %s : (%d) %s.\n",
file, line, errorMessage, static_cast<int>(err),
cudaGetErrorString(err));
DEVICE_RESET DEVICE_RESET
exit(EXIT_FAILURE); LOGf << "CUDA error at" << file >> ":" >> line << " code="
>> static_cast<unsigned int>(err) >> "(" << _cudaGetErrorEnum(err) << ")"
<< errorMessage;
} }
} }
@ -142,11 +141,10 @@ inline void __printLastCudaError(const char *errorMessage, const char *file,
cudaError_t err = cudaGetLastError(); cudaError_t err = cudaGetLastError();
if (cudaSuccess != err) { if (cudaSuccess != err) {
fprintf(stderr, DEVICE_RESET
"%s(%i) : getLastCudaError() CUDA error :" LOGf << "CUDA error at" << file >> ":" >> line << " code="
" %s : (%d) %s.\n", >> static_cast<unsigned int>(err) >> "(" << _cudaGetErrorEnum(err) << ")"
file, line, errorMessage, static_cast<int>(err), << errorMessage;
cudaGetErrorString(err));
} }
} }
#endif #endif

View File

@ -20,10 +20,8 @@ void throw_mpi_error(int result,
char const *const func, const char *const file, int const line) { char const *const func, const char *const file, int const line) {
int resultlen; int resultlen;
MPI_Error_string(result, jt_mpi_err_buffer, &resultlen); MPI_Error_string(result, jt_mpi_err_buffer, &resultlen);
fprintf(stderr, "MPI error at %s:%d code=%d(%s) \"%s\" \n", LOGf << "MPI error at " >> file >> ":" >> line << "code="
file, line, >> result >> '(' >> jt_mpi_err_buffer >> ')' << func;
static_cast<unsigned int>(result), jt_mpi_err_buffer, func);
throw std::runtime_error("MPI error");
} }
namespace jittor { namespace jittor {

View File

@ -51,7 +51,7 @@ for mdname in all_md:
else: else:
cell["cell_type"] = "code" cell["cell_type"] = "code"
cell["outputs"] = [] cell["outputs"] = []
cell["execution_count"] = None cell["execution_count"] = 0
cells.append(cell) cells.append(cell)
ipynb = { ipynb = {
"cells":cells, "cells":cells,

View File

@ -827,6 +827,7 @@ addr2line_path = try_find_exe('addr2line')
has_pybt = check_pybt(gdb_path, python_path) has_pybt = check_pybt(gdb_path, python_path)
cc_flags += " -Wall -Werror -Wno-unknown-pragmas -std=c++14 -fPIC -march=native " cc_flags += " -Wall -Werror -Wno-unknown-pragmas -std=c++14 -fPIC -march=native "
cc_flags += " -fdiagnostics-color=always "
link_flags = " -lstdc++ -ldl -shared " link_flags = " -lstdc++ -ldl -shared "
core_link_flags = "" core_link_flags = ""
opt_flags = "" opt_flags = ""
@ -874,6 +875,7 @@ if has_cuda:
nvcc_flags = nvcc_flags.replace("-march", "-Xcompiler -march") nvcc_flags = nvcc_flags.replace("-march", "-Xcompiler -march")
nvcc_flags = nvcc_flags.replace("-Werror", "") nvcc_flags = nvcc_flags.replace("-Werror", "")
nvcc_flags = nvcc_flags.replace("-fPIC", "-Xcompiler -fPIC") nvcc_flags = nvcc_flags.replace("-fPIC", "-Xcompiler -fPIC")
nvcc_flags = nvcc_flags.replace("-fdiagnostics", "-Xcompiler -fdiagnostics")
nvcc_flags += f" -x cu --cudart=shared -ccbin='{cc_path}' --use_fast_math " nvcc_flags += f" -x cu --cudart=shared -ccbin='{cc_path}' --use_fast_math "
# nvcc warning is noise # nvcc warning is noise
nvcc_flags += " -w " nvcc_flags += " -w "

View File

@ -10,6 +10,7 @@
#include <set> #include <set>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <memory>
namespace jittor { namespace jittor {

View File

@ -280,12 +280,26 @@ bool check_vlog(const char* fileline, int verbose) {
return verbose <= log_v; return verbose <= log_v;
} }
int system_popen(const char* cmd) {
static char buf[BUFSIZ];
static string cmd2;
cmd2 = cmd;
cmd2 += " 2>&1 ";
FILE *ptr = popen(cmd2.c_str(), "r");
if (!ptr) return -1;
while (fgets(buf, BUFSIZ, ptr) != NULL) {
std::cout << buf;
std::cout.flush();
}
return pclose(ptr);
}
void system_with_check(const char* cmd) { void system_with_check(const char* cmd) {
auto ret = system(cmd); auto ret = system_popen(cmd);
ASSERT(ret!=-1) << "Run cmd failed:" << cmd << CHECK(ret!=-1) << "Run cmd failed:" << cmd <<
"\nreturn -1. This might be an overcommit issue." "\nreturn -1. This might be an overcommit issue or out of memory."
<< "Try : echo 1 >/proc/sys/vm/overcommit_memory"; << "Try : echo 1 >/proc/sys/vm/overcommit_memory";
ASSERTop(ret,==,0) << "Run cmd failed:" << cmd; CHECKop(ret,==,0) << "Run cmd failed:" << cmd;
} }
std::thread log_thread(log_main); std::thread log_thread(log_main);