Date: Wed, 23 Sep 2015 11:53:23 +0000 (UTC) From: Jan Beich <jbeich@FreeBSD.org> To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r397610 - in head/graphics: . waifu2x-converter-cpp waifu2x-converter-cpp/files Message-ID: <201509231153.t8NBrNIk009276@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jbeich Date: Wed Sep 23 11:53:22 2015 New Revision: 397610 URL: https://svnweb.freebsd.org/changeset/ports/397610 Log: graphics/waifu2x-converter-cpp: add new port waifu2x achieves image superresolution for anime-style art using deep convolutional neural networks from Torch. waifu2x-converter-cpp reimplements its converter function in C++ using OpenCV. https://github.com/tanakamura/waifu2x-converter-cpp Added: head/graphics/waifu2x-converter-cpp/ head/graphics/waifu2x-converter-cpp/Makefile (contents, props changed) head/graphics/waifu2x-converter-cpp/distinfo (contents, props changed) head/graphics/waifu2x-converter-cpp/files/ head/graphics/waifu2x-converter-cpp/files/patch-freebsd (contents, props changed) head/graphics/waifu2x-converter-cpp/files/patch-no-sse3 (contents, props changed) head/graphics/waifu2x-converter-cpp/files/patch-non-x86 (contents, props changed) head/graphics/waifu2x-converter-cpp/pkg-descr (contents, props changed) Modified: head/graphics/Makefile (contents, props changed) Modified: head/graphics/Makefile ============================================================================== --- head/graphics/Makefile Wed Sep 23 07:21:26 2015 (r397609) +++ head/graphics/Makefile Wed Sep 23 11:53:22 2015 (r397610) @@ -1030,6 +1030,7 @@ SUBDIR += volpack SUBDIR += vp SUBDIR += waffle + SUBDIR += waifu2x-converter-cpp SUBDIR += webp SUBDIR += whirlgif SUBDIR += white_dune Added: head/graphics/waifu2x-converter-cpp/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/graphics/waifu2x-converter-cpp/Makefile Wed Sep 23 11:53:22 2015 (r397610) @@ -0,0 +1,63 @@ +# $FreeBSD$ + +PORTNAME= waifu2x-converter-cpp +DISTVERSION= 1.0.0-237 +DISTVERSIONSUFFIX= -gca65c93 +CATEGORIES= graphics + +MAINTAINER= jbeich@FreeBSD.org +COMMENT= Scale and denoise images using convolutional neural networks + +LICENSE= BSD2CLAUSE MIT +LICENSE_COMB= multi +LICENSE_FILE_BSD2CLAUSE=${WRKSRC}/LICENSE +LICENSE_FILE_MIT= ${WRKSRC}/LICENSE + +BUILD_DEPENDS= ${LOCALBASE}/include/CL/opencl.h:${PORTSDIR}/devel/opencl +LIB_DEPENDS= libopencv_highgui.so:${PORTSDIR}/graphics/opencv \ + libopencv_imgproc.so:${PORTSDIR}/graphics/opencv-core + +USE_GITHUB= yes +GH_ACCOUNT= tanakamura + +USES= cmake compiler:c++11-lib dos2unix +CMAKE_ARGS= -DOPENCV_PREFIX="${LOCALBASE}" \ + -DOpenCL_LIBRARY="${LOCALBASE}/lib/libOpenCL.so" +CFLAGS+= -D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_MATH_TR1 \ + -D_DECLARE_C99_LDBL_MATH # XXX ports/193528 +LDFLAGS+= -Wl,--as-needed # avoid overlinking (opencv deps) +USE_LDCONFIG= yes +PLIST_FILES= bin/${PORTNAME} \ + include/w2xconv.h \ + lib/libw2xc.so +PORTDATA= models_rgb +PORTDOCS= * + +OPTIONS_DEFINE= DOCS SIMD +OPTIONS_DEFAULT=SIMD + +SIMD_CMAKE_OFF= -DX86OPT=off + +post-patch: + @${REINPLACE_CMD} -e 's,-O2,,; /SYMBOL/s,-s,,' \ + ${WRKSRC}/CMakeLists.txt + @${REINPLACE_CMD} -e '/"models/s,","${DATADIR}/,' \ + ${WRKSRC}/src/main.cpp + +pre-install: +# XXX Fails on 9.x with error code 10 + -(cd ${WRKSRC} && ./runtest) + +do-install: + ${INSTALL_PROGRAM} ${WRKSRC}/${PORTNAME} ${STAGEDIR}${PREFIX}/bin + ${INSTALL_LIB} ${WRKSRC}/libw2xc.so ${STAGEDIR}${PREFIX}/lib + ${INSTALL_DATA} ${WRKSRC}/src/w2xconv.h ${STAGEDIR}${PREFIX}/include + (cd ${WRKSRC} && ${COPYTREE_SHARE} \ + "${PORTDATA}" ${STAGEDIR}${DATADIR}) + +post-install-DOCS-on: + (cd ${WRKSRC} && ${COPYTREE_SHARE} "appendix" ${STAGEDIR}${DOCSDIR}) + (cd ${WRKSRC}/docs && ${COPYTREE_SHARE} \ + "internals" ${STAGEDIR}${DOCSDIR}) + +.include <bsd.port.mk> Added: head/graphics/waifu2x-converter-cpp/distinfo ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/graphics/waifu2x-converter-cpp/distinfo Wed Sep 23 11:53:22 2015 (r397610) @@ -0,0 +1,2 @@ +SHA256 (tanakamura-waifu2x-converter-cpp-1.0.0-237-gca65c93_GH0.tar.gz) = 5b34ecc43a9c9f976ab92c72b1ba6f45b8470ea05bb976738e732c3c01290c8e +SIZE (tanakamura-waifu2x-converter-cpp-1.0.0-237-gca65c93_GH0.tar.gz) = 14848013 Added: head/graphics/waifu2x-converter-cpp/files/patch-freebsd ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/graphics/waifu2x-converter-cpp/files/patch-freebsd Wed Sep 23 11:53:22 2015 (r397610) @@ -0,0 +1,92 @@ +https://github.com/tanakamura/waifu2x-converter-cpp/pull/3 + +diff --git src/Buffer.hpp src/Buffer.hpp +index 2152cf3..e69d10b 100644 +--- src/Buffer.hpp ++++ src/Buffer.hpp +@@ -1,8 +1,10 @@ + #ifndef BUFFER_HPP + #define BUFFER_HPP + +-#ifndef __APPLE__ ++#if defined(_MSC_VER) + #include <malloc.h> ++#elif defined(__GNUC__) ++#include <mm_malloc.h> + #endif + + #include <stdlib.h> +diff --git src/Env.hpp src/Env.hpp +index 8087431..7003c80 100644 +--- src/Env.hpp ++++ src/Env.hpp +@@ -26,7 +26,7 @@ struct ComputeEnv { + + struct W2XConvProcessor target_processor; + +-#ifndef __APPLE__ ++#if defined(_WIN32) || defined(__linux) + w2xc::ThreadPool *tpool; + #endif + ComputeEnv(); +diff --git src/modelHandler_avx_func.hpp src/modelHandler_avx_func.hpp +index 2459792..27514e5 100644 +--- src/modelHandler_avx_func.hpp ++++ src/modelHandler_avx_func.hpp +@@ -699,7 +699,7 @@ filter_AVX_impl0(ComputeEnv *env, + } + }; + +-#ifdef __APPLE__ ++#if !defined(_WIN32) && !defined(__linux) + std::vector<std::thread> workerThreads; + for (int ji=0; ji<nJob; ji++) { + workerThreads.emplace_back(std::thread(func)); +diff --git src/threadPool.cpp src/threadPool.cpp +index 6c10f12..3b32f07 100644 +--- src/threadPool.cpp ++++ src/threadPool.cpp +@@ -2,7 +2,7 @@ + #include <atomic> + #include "threadPool.hpp" + +-#ifndef __APPLE__ ++#if defined(_WIN32) || defined(__linux) + + namespace w2xc { + +diff --git src/threadPool.hpp src/threadPool.hpp +index 2a905ea..34f6586 100644 +--- src/threadPool.hpp ++++ src/threadPool.hpp +@@ -1,7 +1,7 @@ + #ifndef THREAD_POOL_HPP + #define THREAD_POOL_HPP + +-#ifndef __APPLE__ ++#if defined(_WIN32) || defined(__linux) + + #include <thread> + #include <atomic> +diff --git src/w2xconv.cpp src/w2xconv.cpp +index 5ed00bd..de78ad8 100644 +--- src/w2xconv.cpp ++++ src/w2xconv.cpp +@@ -36,7 +36,7 @@ w2xconv_init(enum W2XConvGPUMode gpu, + nJob = std::thread::hardware_concurrency(); + } + +-#ifndef __APPLE__ ++#if defined(_WIN32) || defined(__linux) + impl->env.tpool = w2xc::initThreadPool(nJob); + #endif + +@@ -248,7 +248,7 @@ w2xconv_fini(struct W2XConv *conv) + + w2xc::finiCUDA(&impl->env); + w2xc::finiOpenCL(&impl->env); +-#ifndef __APPLE__ ++#if defined(_WIN32) || defined(__linux) + w2xc::finiThreadPool(impl->env.tpool); + #endif + Added: head/graphics/waifu2x-converter-cpp/files/patch-no-sse3 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/graphics/waifu2x-converter-cpp/files/patch-no-sse3 Wed Sep 23 11:53:22 2015 (r397610) @@ -0,0 +1,70 @@ +https://github.com/tanakamura/waifu2x-converter-cpp/pull/5 + +diff --git src/Env.cpp src/Env.cpp +index 76c1859..9ad0a3c 100644 +--- src/Env.cpp ++++ src/Env.cpp +@@ -28,6 +28,10 @@ ComputeEnv::ComputeEnv() + #endif + this->flags = 0; + ++ if (ecx & (1<<0)) { ++ this->flags |= ComputeEnv::HAVE_CPU_SSE3; ++ } ++ + if ((ecx & 0x18000000) == 0x18000000) { + this->flags |= ComputeEnv::HAVE_CPU_AVX; + } +diff --git src/Env.hpp src/Env.hpp +index 8087431..0c2e22a 100644 +--- src/Env.hpp ++++ src/Env.hpp +@@ -19,6 +19,7 @@ struct ComputeEnv { + + static const int HAVE_CPU_FMA = 1<<0; + static const int HAVE_CPU_AVX = 1<<1; ++ static const int HAVE_CPU_SSE3 = 1<<2; + + int flags; + +diff --git src/modelHandler.cpp src/modelHandler.cpp +index 2f72442..1e74ba0 100644 +--- src/modelHandler.cpp ++++ src/modelHandler.cpp +@@ -100,6 +100,7 @@ bool Model::filter_AVX_OpenCL(ComputeEnv *env, + + bool have_fma = env->flags & ComputeEnv::HAVE_CPU_FMA; + bool have_avx = env->flags & ComputeEnv::HAVE_CPU_AVX; ++ bool have_sse3 = env->flags & ComputeEnv::HAVE_CPU_SSE3; + + bool gpu = (rt == RUN_OPENCL) || (rt == RUN_CUDA); + +@@ -317,10 +318,12 @@ bool Model::filter_AVX_OpenCL(ComputeEnv *env, + filter_AVX_impl(env, packed_input, packed_output, + nInputPlanes, nOutputPlanes, fbiases_flat, weight_flat, + size.width, size.height, nJob); +- } else { ++ } else if (have_sse3) { + filter_SSE_impl(env, packed_input, packed_output, + nInputPlanes, nOutputPlanes, fbiases_flat, weight_flat, + size.width, size.height, nJob); ++ } else { ++ filter_CV(env, packed_input_buf, packed_output_buf, size); + } + } + +@@ -379,11 +382,12 @@ bool Model::filter_AVX_OpenCL(ComputeEnv *env, + const float *packed_input = (float*)packed_input_buf->get_read_ptr_host(env, in_size); + float *packed_output = (float*)packed_output_buf->get_write_ptr_host(env); + +- if (!have_avx) { ++ if (!have_sse3) { ++ filter_CV(env, packed_input_buf, packed_output_buf, size); ++ } else if (!have_avx) { + filter_SSE_impl(env, packed_input, packed_output, + nInputPlanes, nOutputPlanes, fbiases_flat, weight_flat, + size.width, size.height, nJob); +- //filter_CV(env, packed_input_buf, packed_output_buf, size); + } else { + if (have_fma) { + filter_FMA_impl(env, packed_input, packed_output, Added: head/graphics/waifu2x-converter-cpp/files/patch-non-x86 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/graphics/waifu2x-converter-cpp/files/patch-non-x86 Wed Sep 23 11:53:22 2015 (r397610) @@ -0,0 +1,168 @@ +https://github.com/tanakamura/waifu2x-converter-cpp/pull/6 + +diff --git CMakeLists.txt CMakeLists.txt +index bcb0338..899ee7b 100644 +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -58,10 +58,24 @@ endif() + find_library(IMGCODECS_LIBRARY NAMES opencv_imgcodecs opencv_highgui + HINTS ${OPENCV_PREFIX}/lib) + ++if(CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64" OR ++ CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR ++ CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") ++ set(X86_TRUE true) ++else() ++ set(X86_TRUE false) ++endif() ++ ++option(X86OPT "Enable X86 SIMD optimizations" ${X86_TRUE}) ++if(X86OPT) ++ add_definitions(-DX86OPT) ++ set(X86OPT_SOURCES src/modelHandler_avx.cpp src/modelHandler_fma.cpp src/modelHandler_sse.cpp) ++endif() ++ + add_executable(waifu2x-converter-cpp + src/main.cpp) + add_library(w2xc SHARED +- src/modelHandler.cpp src/modelHandler_avx.cpp src/modelHandler_fma.cpp src/modelHandler_sse.cpp ++ src/modelHandler.cpp ${X86OPT_SOURCES} + src/modelHandler_OpenCL.cpp src/convertRoutine.cpp src/threadPool.cpp + src/modelHandler_CUDA.cpp src/w2xconv.cpp src/common.cpp + src/Env.cpp +diff --git src/Env.cpp src/Env.cpp +index 76c1859..2c1069d 100644 +--- src/Env.cpp ++++ src/Env.cpp +@@ -1,11 +1,13 @@ + #include "Env.hpp" + #include "Buffer.hpp" + ++#ifdef X86OPT + #ifdef __GNUC__ + #include <cpuid.h> + #else + #include <intrin.h> + #endif ++#endif // X86OPT + + ComputeEnv::ComputeEnv() + :num_cl_dev(0), +@@ -14,6 +16,9 @@ ComputeEnv::ComputeEnv() + cuda_dev_list(nullptr), + transfer_wait(0) + { ++ this->flags = 0; ++ ++#ifdef X86OPT + unsigned int eax=0, ebx=0, ecx=0, edx=0; + + #ifdef __GNUC__ +@@ -26,8 +31,6 @@ ComputeEnv::ComputeEnv() + ecx = cpuInfo[2]; + edx = cpuInfo[3]; + #endif +- this->flags = 0; +- + if (ecx & (1<<0)) { + this->flags |= ComputeEnv::HAVE_CPU_SSE3; + } +@@ -35,6 +38,7 @@ ComputeEnv::ComputeEnv() + if (ecx & (1<<12)) { + this->flags |= ComputeEnv::HAVE_CPU_FMA; + } ++#endif // X86OPT + + this->pref_block_size = 512; + } +diff --git src/modelHandler.cpp src/modelHandler.cpp +index 2f72442..1a3d87e 100644 +--- src/modelHandler.cpp ++++ src/modelHandler.cpp +@@ -306,6 +306,7 @@ bool Model::filter_AVX_OpenCL(ComputeEnv *env, + nInputPlanes, nOutputPlanes, fbiases_flat, weight_flat, + size.width, size.height, nJob); + } else { ++#ifdef X86OPT + const float *packed_input = (float*)packed_input_buf->get_read_ptr_host(env, in_size); + float *packed_output = (float*)packed_output_buf->get_write_ptr_host(env); + +@@ -322,6 +323,9 @@ bool Model::filter_AVX_OpenCL(ComputeEnv *env, + nInputPlanes, nOutputPlanes, fbiases_flat, weight_flat, + size.width, size.height, nJob); + } ++#else ++ filter_CV(env, packed_input_buf, packed_output_buf, size); ++#endif + } + + double t2 = getsec(); +@@ -376,6 +380,7 @@ bool Model::filter_AVX_OpenCL(ComputeEnv *env, + nInputPlanes, nOutputPlanes, fbiases_flat, weight_flat, + size.width, size.height, nJob); + } else { ++#ifdef X86OPT + const float *packed_input = (float*)packed_input_buf->get_read_ptr_host(env, in_size); + float *packed_output = (float*)packed_output_buf->get_write_ptr_host(env); + +@@ -395,6 +400,9 @@ bool Model::filter_AVX_OpenCL(ComputeEnv *env, + size.width, size.height, nJob); + } + } ++#else ++ filter_CV(env, packed_input_buf, packed_output_buf, size); ++#endif + } + } + +diff --git src/modelHandler_OpenCL.cpp src/modelHandler_OpenCL.cpp +index ea4fd9b..13da2a2 100644 +--- src/modelHandler_OpenCL.cpp ++++ src/modelHandler_OpenCL.cpp +@@ -16,13 +16,6 @@ + #include "CLlib.h" + #include "params.h" + +-#ifdef __GNUC__ +-#include <cpuid.h> +-#else +-#include <intrin.h> +-#endif +- +- + static const char prog[] = + #include "modelHandler_OpenCL.cl.h" + ; +diff --git src/w2xconv.cpp src/w2xconv.cpp +index 5ed00bd..94b08c4 100644 +--- src/w2xconv.cpp ++++ src/w2xconv.cpp +@@ -1,10 +1,12 @@ + #define W2XCONV_IMPL + + #include <thread> ++#ifdef X86OPT + //#if (defined __GNUC__) || (defined __clang__) + #ifndef _WIN32 + #include <cpuid.h> + #endif ++#endif // X86OPT + #include "w2xconv.h" + #include "sec.hpp" + #include "Buffer.hpp" +@@ -63,6 +65,7 @@ w2xconv_init(enum W2XConvGPUMode gpu, + c->target_processor.devid = 0; + impl->dev_name = impl->env.cl_dev_list[0].name.c_str(); + } else { ++#ifdef X86OPT + { + + #ifdef _WIN32 +@@ -91,6 +94,7 @@ w2xconv_init(enum W2XConvGPUMode gpu, + + c->target_processor.type = W2XCONV_PROC_HOST; + } ++#endif // X86OPT + } + + c->target_processor.dev_name = impl->dev_name.c_str(); Added: head/graphics/waifu2x-converter-cpp/pkg-descr ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/graphics/waifu2x-converter-cpp/pkg-descr Wed Sep 23 11:53:22 2015 (r397610) @@ -0,0 +1,5 @@ +waifu2x achieves image superresolution for anime-style art using deep +convolutional neural networks from Torch. waifu2x-converter-cpp +reimplements its converter function in C++ using OpenCV. + +WWW: https://github.com/tanakamura/waifu2x-converter-cpp
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201509231153.t8NBrNIk009276>