From d8e7f26e6f1ff53e9656e4b932bf898fa8dce9ac Mon Sep 17 00:00:00 2001 From: lltcggie Date: Thu, 7 Jul 2016 01:25:04 +0900 Subject: [PATCH] =?UTF-8?q?cuDNN=E3=81=AE=E3=82=A2=E3=83=AB=E3=82=B4?= =?UTF-8?q?=E3=83=AA=E3=82=BA=E3=83=A0=E3=83=87=E3=83=BC=E3=82=BF=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E3=83=91=E3=82=B9=E3=81=8C=E6=84=8F=E5=9B=B3=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=84=E7=89=A9=E3=81=AB=E3=81=AA=E3=82=8B=E3=81=93?= =?UTF-8?q?=E3=81=A8=E3=81=8C=E3=81=82=E3=82=8B=E3=81=AE=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/waifu2x.cpp | 70 +++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index 9725f63..4ab47b0 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -561,42 +561,62 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi const auto cuDNNCheckEndTime = std::chrono::system_clock::now(); - boost::filesystem::path exe_dir_path(ExeDir); - if (exe_dir_path.is_absolute()) - exe_dir_path = exe_dir_path.branch_path(); - - if (Process == "cudnn" && boost::filesystem::exists(exe_dir_path)) + if (Process == "cudnn") { - const boost::filesystem::path cudnn_data_dir_path(exe_dir_path / "cudnn_data"); + // exeのディレクトリにcuDNNのアルゴリズムデータ保存 + boost::filesystem::path cudnn_data_base_dir_path(ExeDir); + if (cudnn_data_base_dir_path.is_relative()) + cudnn_data_base_dir_path = boost::filesystem::system_complete(cudnn_data_base_dir_path); - bool isOK = false; - if (boost::filesystem::exists(cudnn_data_dir_path)) - isOK = true; + if (!boost::filesystem::is_directory(cudnn_data_base_dir_path)) + cudnn_data_base_dir_path = cudnn_data_base_dir_path.branch_path(); - if (!isOK) + if (!boost::filesystem::exists(cudnn_data_base_dir_path)) { - boost::system::error_code error; - const bool result = boost::filesystem::create_directory(cudnn_data_dir_path, error); - if (result && !error) - isOK = true; + // exeのディレクトリが取得できなければカレントディレクトリに保存 + + cudnn_data_base_dir_path = boost::filesystem::current_path(); + + if (cudnn_data_base_dir_path.is_relative()) + cudnn_data_base_dir_path = boost::filesystem::system_complete(cudnn_data_base_dir_path); + + if (!boost::filesystem::exists(cudnn_data_base_dir_path)) + cudnn_data_base_dir_path = "./"; } - if(isOK) + if (boost::filesystem::exists(cudnn_data_base_dir_path)) { - cudaDeviceProp prop; - if (cudaGetDeviceProperties(&prop, mGPUNo) == cudaSuccess) + const boost::filesystem::path cudnn_data_dir_path(cudnn_data_base_dir_path / "cudnn_data"); + + bool isOK = false; + if (boost::filesystem::exists(cudnn_data_dir_path)) + isOK = true; + + if (!isOK) { - std::string conv_filename(prop.name); - conv_filename += " conv "; + boost::system::error_code error; + const bool result = boost::filesystem::create_directory(cudnn_data_dir_path, error); + if (result && !error) + isOK = true; + } - std::string deconv_filename(prop.name); - deconv_filename += " deconv "; + if (isOK) + { + cudaDeviceProp prop; + if (cudaGetDeviceProperties(&prop, mGPUNo) == cudaSuccess) + { + std::string conv_filename(prop.name); + conv_filename += " conv "; - const boost::filesystem::path conv_data_path = cudnn_data_dir_path / conv_filename; - const boost::filesystem::path deconv_data_path = cudnn_data_dir_path / deconv_filename; + std::string deconv_filename(prop.name); + deconv_filename += " deconv "; - g_ConvCcuDNNAlgorithm.SetDataPath(conv_data_path.string()); - g_DeconvCcuDNNAlgorithm.SetDataPath(deconv_data_path.string()); + const boost::filesystem::path conv_data_path = cudnn_data_dir_path / conv_filename; + const boost::filesystem::path deconv_data_path = cudnn_data_dir_path / deconv_filename; + + g_ConvCcuDNNAlgorithm.SetDataPath(conv_data_path.string()); + g_DeconvCcuDNNAlgorithm.SetDataPath(deconv_data_path.string()); + } } } }