From c1e0861446627dc98db5870599dae9dad3ef4374 Mon Sep 17 00:00:00 2001 From: Dun Liang Date: Tue, 28 Apr 2020 19:48:46 +0800 Subject: [PATCH] redirect jupyter outputs --- extern/cuda/inc/helper_cuda.h | 26 ++++++++++++-------------- extern/mpi/src/mpi_warper.cc | 6 ++---- notebook/md_to_ipynb.py | 2 +- python/jittor/compiler.py | 2 ++ src/types.h | 1 + src/utils/log.cc | 22 ++++++++++++++++++---- 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/extern/cuda/inc/helper_cuda.h b/extern/cuda/inc/helper_cuda.h index f3afd793..37acec8d 100644 --- a/extern/cuda/inc/helper_cuda.h +++ b/extern/cuda/inc/helper_cuda.h @@ -17,6 +17,8 @@ #pragma once +#include "utils/log.h" + #include #include #include @@ -103,10 +105,10 @@ template void check(T result, char const *const func, const char *const file, int const line) { if (result) { - fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line, - static_cast(result), _cudaGetErrorEnum(result), func); DEVICE_RESET - throw std::runtime_error("CUDA error"); + LOGf << "CUDA error at" << file >> ":" >> line << " code=" + >> static_cast(result) >> "(" << _cudaGetErrorEnum(result) << ")" + << func; } } @@ -123,13 +125,10 @@ inline void __getLastCudaError(const char *errorMessage, const char *file, cudaError_t err = cudaGetLastError(); if (cudaSuccess != err) { - fprintf(stderr, - "%s(%i) : getLastCudaError() CUDA error :" - " %s : (%d) %s.\n", - file, line, errorMessage, static_cast(err), - cudaGetErrorString(err)); DEVICE_RESET - exit(EXIT_FAILURE); + LOGf << "CUDA error at" << file >> ":" >> line << " code=" + >> static_cast(err) >> "(" << _cudaGetErrorEnum(err) << ")" + << errorMessage; } } @@ -142,11 +141,10 @@ inline void __printLastCudaError(const char *errorMessage, const char *file, cudaError_t err = cudaGetLastError(); if (cudaSuccess != err) { - fprintf(stderr, - "%s(%i) : getLastCudaError() CUDA error :" - " %s : (%d) %s.\n", - file, line, errorMessage, static_cast(err), - cudaGetErrorString(err)); + DEVICE_RESET + LOGf << "CUDA error at" << file >> ":" >> line << " code=" + >> static_cast(err) >> "(" << _cudaGetErrorEnum(err) << ")" + << errorMessage; } } #endif diff --git a/extern/mpi/src/mpi_warper.cc b/extern/mpi/src/mpi_warper.cc index a25e531f..3bc50781 100644 --- a/extern/mpi/src/mpi_warper.cc +++ b/extern/mpi/src/mpi_warper.cc @@ -20,10 +20,8 @@ void throw_mpi_error(int result, char const *const func, const char *const file, int const line) { int resultlen; MPI_Error_string(result, jt_mpi_err_buffer, &resultlen); - fprintf(stderr, "MPI error at %s:%d code=%d(%s) \"%s\" \n", - file, line, - static_cast(result), jt_mpi_err_buffer, func); - throw std::runtime_error("MPI error"); + LOGf << "MPI error at " >> file >> ":" >> line << "code=" + >> result >> '(' >> jt_mpi_err_buffer >> ')' << func; } namespace jittor { diff --git a/notebook/md_to_ipynb.py b/notebook/md_to_ipynb.py index 9699da89..c1548c8b 100644 --- a/notebook/md_to_ipynb.py +++ b/notebook/md_to_ipynb.py @@ -51,7 +51,7 @@ for mdname in all_md: else: cell["cell_type"] = "code" cell["outputs"] = [] - cell["execution_count"] = None + cell["execution_count"] = 0 cells.append(cell) ipynb = { "cells":cells, diff --git a/python/jittor/compiler.py b/python/jittor/compiler.py index c0a0bbcd..a622ce2b 100644 --- a/python/jittor/compiler.py +++ b/python/jittor/compiler.py @@ -827,6 +827,7 @@ addr2line_path = try_find_exe('addr2line') has_pybt = check_pybt(gdb_path, python_path) cc_flags += " -Wall -Werror -Wno-unknown-pragmas -std=c++14 -fPIC -march=native " +cc_flags += " -fdiagnostics-color=always " link_flags = " -lstdc++ -ldl -shared " core_link_flags = "" opt_flags = "" @@ -874,6 +875,7 @@ if has_cuda: nvcc_flags = nvcc_flags.replace("-march", "-Xcompiler -march") nvcc_flags = nvcc_flags.replace("-Werror", "") 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 warning is noise nvcc_flags += " -w " diff --git a/src/types.h b/src/types.h index 900ca727..0e3895da 100644 --- a/src/types.h +++ b/src/types.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace jittor { diff --git a/src/utils/log.cc b/src/utils/log.cc index d6d6566e..3844b598 100644 --- a/src/utils/log.cc +++ b/src/utils/log.cc @@ -280,12 +280,26 @@ bool check_vlog(const char* fileline, int verbose) { 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) { - auto ret = system(cmd); - ASSERT(ret!=-1) << "Run cmd failed:" << cmd << - "\nreturn -1. This might be an overcommit issue." + auto ret = system_popen(cmd); + CHECK(ret!=-1) << "Run cmd failed:" << cmd << + "\nreturn -1. This might be an overcommit issue or out of 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);