http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/rat_check ---------------------------------------------------------------------- diff --git a/rat_check b/rat_check deleted file mode 100644 index 77f0a63..0000000 --- a/rat_check +++ /dev/null @@ -1,1108 +0,0 @@ - -***************************************************** -Summary -------- -Generated at: 2016-08-17T13:11:07+08:00 -Notes: 5 -Binaries: 0 -Archives: 0 -Standards: 288 - -Apache Licensed: 269 -Generated Documents: 0 - -JavaDocs are generated and so license header is optional -Generated files do not required license headers - -18 Unknown Licenses - -******************************* - -Unapproved licenses: - - ./.gitmodules - ./.travis.yml - ./rat_check - ./cmake/Protobuf.cmake - ./cmake/Thirdparty/FindOpenCL.cmake - ./include/singa/utils/cuda_utils.h - ./include/singa/utils/tinydir.h - ./lib/cnmem/.git - ./lib/cnmem/CMakeLists.txt - ./lib/cnmem/include/cnmem.h - ./lib/cnmem/src/cnmem.cpp - ./lib/cnmem/tests/cnmem_tests.cpp - ./src/core/tensor/distribution.cl - ./src/python/swig/numpy.i - ./test/gtest/gtest-all.cc - ./test/gtest/gtest.h - ./test/gtest/gtest_main.cc - ./tool/cpplint.py - -******************************* - -Archives: - -***************************************************** - Files with Apache License headers will be marked AL - Binary files (which do not require AL headers) will be marked B - Compressed archives will be marked A - Notices, licenses etc will be marked N - !????? ./.gitmodules - !????? ./.travis.yml - AL ./CMakeLists.txt - N ./DISCLAIMER - N ./LICENSE - N ./NOTICE - N ./RELEASE_NOTES - AL ./jenkins.sh - !????? ./rat_check - AL ./bin/singa-cleanup.sh - AL ./bin/singa-console.sh - AL ./bin/singa-env.sh - AL ./bin/singa-run.sh - AL ./bin/singa-stop.sh - AL ./bin/zk-service.sh - AL ./cmake/Cuda.cmake - AL ./cmake/Dependencies.cmake - !????? ./cmake/Protobuf.cmake - AL ./cmake/Utils.cmake - AL ./cmake/Templates/singa_config.h.in - AL ./cmake/Thirdparty/FindCBLAS.cmake - AL ./cmake/Thirdparty/FindCUDNN.cmake - AL ./cmake/Thirdparty/FindGlog.cmake - AL ./cmake/Thirdparty/FindLMDB.cmake - !????? ./cmake/Thirdparty/FindOpenCL.cmake - AL ./examples/CMakeLists.txt - AL ./examples/index.rst - AL ./examples/char-rnn/sample.py - AL ./examples/char-rnn/train.py - AL ./examples/cifar10/CMakeLists.txt - AL ./examples/cifar10/alexnet-parallel.cc - AL ./examples/cifar10/alexnet.cc - AL ./examples/cifar10/alexnet.py - AL ./examples/cifar10/cifar10.h - AL ./examples/cifar10/download_data.py - AL ./examples/cifar10/predict.py - AL ./examples/cifar10/run-parallel.sh - AL ./examples/cifar10/run.sh - AL ./examples/cifar10/train.py - AL ./examples/cifar10/vgg-parallel.cc - AL ./examples/cifar10/vgg.py - AL ./examples/imagenet/CMakeLists.txt - AL ./examples/imagenet/alexnet.cc - AL ./examples/imagenet/create_data.sh - AL ./examples/imagenet/ilsvrc12.cc - AL ./examples/imagenet/ilsvrc12.h - AL ./examples/imagenet/run.sh - AL ./examples/mnist/train.py - AL ./include/singa/core/common.h - AL ./include/singa/core/device.h - AL ./include/singa/core/memory.h - AL ./include/singa/core/scheduler.h - AL ./include/singa/core/tensor.h - AL ./include/singa/io/decoder.h - AL ./include/singa/io/encoder.h - AL ./include/singa/io/integer.h - AL ./include/singa/io/network.h - AL ./include/singa/io/reader.h - AL ./include/singa/io/snapshot.h - AL ./include/singa/io/transformer.h - AL ./include/singa/io/writer.h - AL ./include/singa/model/feed_forward_net.h - AL ./include/singa/model/initializer.h - AL ./include/singa/model/layer.h - AL ./include/singa/model/loss.h - AL ./include/singa/model/metric.h - AL ./include/singa/model/optimizer.h - AL ./include/singa/model/updater.h - AL ./include/singa/utils/channel.h - !????? ./include/singa/utils/cuda_utils.h - AL ./include/singa/utils/factory.h - AL ./include/singa/utils/integer.h - AL ./include/singa/utils/logging.h - AL ./include/singa/utils/opencl_utils.h - AL ./include/singa/utils/safe_queue.h - AL ./include/singa/utils/singleton.h - AL ./include/singa/utils/string.h - AL ./include/singa/utils/timer.h - !????? ./include/singa/utils/tinydir.h - !????? ./lib/cnmem/.git - !????? ./lib/cnmem/CMakeLists.txt - N ./lib/cnmem/LICENSE - !????? ./lib/cnmem/include/cnmem.h - !????? ./lib/cnmem/src/cnmem.cpp - !????? ./lib/cnmem/tests/cnmem_tests.cpp - AL ./src/CMakeLists.txt - AL ./src/core/device/cpp_cpu.cc - AL ./src/core/device/cuda_gpu.cc - AL ./src/core/device/device.cc - AL ./src/core/device/opencl_device.cc - AL ./src/core/device/platform.cc - AL ./src/core/memory/memory.cc - AL ./src/core/scheduler/scheduler.cc - !????? ./src/core/tensor/distribution.cl - AL ./src/core/tensor/math_kernel.cu - AL ./src/core/tensor/math_kernel.h - AL ./src/core/tensor/sparse_tensor.cc - AL ./src/core/tensor/tensor.cc - AL ./src/core/tensor/tensor_math.h - AL ./src/core/tensor/tensor_math_cpp.h - AL ./src/core/tensor/tensor_math_cuda.h - AL ./src/core/tensor/tensor_math_opencl.cl - AL ./src/core/tensor/tensor_math_opencl.h - AL ./src/io/binfile_reader.cc - AL ./src/io/binfile_writer.cc - AL ./src/io/csv_decoder.cc - AL ./src/io/csv_encoder.cc - AL ./src/io/image_transformer.cc - AL ./src/io/jpg_decoder.cc - AL ./src/io/jpg_encoder.cc - AL ./src/io/lmdb_reader.cc - AL ./src/io/lmdb_writer.cc - AL ./src/io/snapshot.cc - AL ./src/io/textfile_reader.cc - AL ./src/io/textfile_writer.cc - AL ./src/io/network/endpoint.cc - AL ./src/io/network/message.cc - AL ./src/model/feed_forward_net.cc - AL ./src/model/rnn.cc - AL ./src/model/layer/activation.cc - AL ./src/model/layer/activation.h - AL ./src/model/layer/batchnorm.cc - AL ./src/model/layer/batchnorm.h - AL ./src/model/layer/convolution.cc - AL ./src/model/layer/convolution.h - AL ./src/model/layer/cudnn_activation.cc - AL ./src/model/layer/cudnn_activation.h - AL ./src/model/layer/cudnn_batchnorm.cc - AL ./src/model/layer/cudnn_batchnorm.h - AL ./src/model/layer/cudnn_convolution.cc - AL ./src/model/layer/cudnn_convolution.h - AL ./src/model/layer/cudnn_dropout.cc - AL ./src/model/layer/cudnn_dropout.h - AL ./src/model/layer/cudnn_lrn.cc - AL ./src/model/layer/cudnn_lrn.h - AL ./src/model/layer/cudnn_pooling.cc - AL ./src/model/layer/cudnn_pooling.h - AL ./src/model/layer/cudnn_rnn.cc - AL ./src/model/layer/cudnn_rnn.h - AL ./src/model/layer/cudnn_softmax.cc - AL ./src/model/layer/cudnn_softmax.h - AL ./src/model/layer/cudnn_utils.h - AL ./src/model/layer/dense.cc - AL ./src/model/layer/dense.h - AL ./src/model/layer/dropout.cc - AL ./src/model/layer/dropout.h - AL ./src/model/layer/flatten.cc - AL ./src/model/layer/flatten.h - AL ./src/model/layer/lrn.cc - AL ./src/model/layer/lrn.h - AL ./src/model/layer/pooling.cc - AL ./src/model/layer/pooling.h - AL ./src/model/layer/prelu.cc - AL ./src/model/layer/prelu.h - AL ./src/model/layer/rnn.cc - AL ./src/model/layer/rnn.h - AL ./src/model/layer/softmax.cc - AL ./src/model/layer/softmax.h - AL ./src/model/loss/mse.cc - AL ./src/model/loss/softmax_cross_entropy.cc - AL ./src/model/metric/accuracy.cc - AL ./src/model/optimizer/adagrad.cc - AL ./src/model/optimizer/local_all_reduce.cc - AL ./src/model/optimizer/nesterov.cc - AL ./src/model/optimizer/optimizer.cc - AL ./src/model/optimizer/rmsprop.cc - AL ./src/model/optimizer/sgd.cc - AL ./src/model/updater/local_updater.cc - AL ./src/model/updater/updater.cc - AL ./src/proto/core.proto - AL ./src/proto/io.proto - AL ./src/proto/model.proto - AL ./src/python/setup.py.in - AL ./src/python/singa/__init__.py - AL ./src/python/singa/command.py - AL ./src/python/singa/device.py - AL ./src/python/singa/initializer.py - AL ./src/python/singa/layer.py - AL ./src/python/singa/loss.py - AL ./src/python/singa/metric.py - AL ./src/python/singa/model.py - AL ./src/python/singa/net.py - AL ./src/python/singa/optimizer.py - AL ./src/python/singa/tensor.py - AL ./src/python/singa/utils.py - AL ./src/python/swig/core_device.i - AL ./src/python/swig/core_tensor.i - AL ./src/python/swig/model_layer.i - AL ./src/python/swig/model_loss.i - AL ./src/python/swig/model_metric.i - AL ./src/python/swig/model_optimizer.i - !????? ./src/python/swig/numpy.i - AL ./src/python/swig/singa.i - ./src/python/swig/singa_wrap.cxx - AL ./src/utils/channel.cc - AL ./src/utils/logging.cc - AL ./src/utils/opencl_utils.cc - AL ./test/CMakeLists.txt - AL ./test/gtest/CMakeLists.txt - !????? ./test/gtest/gtest-all.cc - !????? ./test/gtest/gtest.h - !????? ./test/gtest/gtest_main.cc - AL ./test/python/test_layer.py - AL ./test/python/test_optimizer.py - AL ./test/python/test_tensor.py - AL ./test/singa/test_accuracy.cc - AL ./test/singa/test_activation.cc - AL ./test/singa/test_adagrad.cc - AL ./test/singa/test_batchnorm.cc - AL ./test/singa/test_binfile_rw.cc - AL ./test/singa/test_channel.cc - AL ./test/singa/test_convolution.cc - AL ./test/singa/test_cpp_cpu.cc - AL ./test/singa/test_cross_entropy.cc - AL ./test/singa/test_csv.cc - AL ./test/singa/test_cudnn_activation.cc - AL ./test/singa/test_cudnn_batchnorm.cc - AL ./test/singa/test_cudnn_convolution.cc - AL ./test/singa/test_cudnn_dropout.cc - AL ./test/singa/test_cudnn_lrn.cc - AL ./test/singa/test_cudnn_pooling.cc - AL ./test/singa/test_cudnn_rnn.cc - AL ./test/singa/test_cudnn_softmax.cc - AL ./test/singa/test_dense.cc - AL ./test/singa/test_dropout.cc - AL ./test/singa/test_ep.cc - AL ./test/singa/test_flatten.cc - AL ./test/singa/test_image_transformer.cc - AL ./test/singa/test_initializer.cc - AL ./test/singa/test_jpg.cc - AL ./test/singa/test_layer.cc - AL ./test/singa/test_lmdb_rw.cc - AL ./test/singa/test_logging.cc - AL ./test/singa/test_lrn.cc - AL ./test/singa/test_memory.cc - AL ./test/singa/test_mse.cc - AL ./test/singa/test_nesterov.cc - AL ./test/singa/test_opencl.cc - AL ./test/singa/test_platform.cc - AL ./test/singa/test_pooling.cc - AL ./test/singa/test_prelu.cc - AL ./test/singa/test_rmsprop.cc - AL ./test/singa/test_sgd.cc - AL ./test/singa/test_snapshot.cc - AL ./test/singa/test_softmax.cc - AL ./test/singa/test_tensor.cc - AL ./test/singa/test_tensor_math.cc - AL ./test/singa/test_textfile_rw.cc - AL ./test/singa/test_timer.cc - AL ./thirdparty/install.sh - !????? ./tool/cpplint.py - AL ./tool/graph.py - AL ./tool/node.sh - AL ./tool/docker/mesos/.bashrc - AL ./tool/docker/mesos/Dockerfile - AL ./tool/docker/mesos/core-site.xml - AL ./tool/docker/mesos/hdfs-site.xml - AL ./tool/docker/mesos/install.sh - AL ./tool/docker/mesos/mapred-site.xml - AL ./tool/docker/mesos/yarn-site.xml - AL ./tool/docker/singa/.bashrc - AL ./tool/docker/singa/Dockerfile - AL ./tool/docker/singa/Dockerfile_gpu - AL ./tool/mesos/scheduler.proto - AL ./tool/mesos/singa_scheduler.cc - AL ./tool/python/singa.py - AL ./tool/python/examples/__init__.py - AL ./tool/python/examples/cifar10_cnn.py - AL ./tool/python/examples/cifar10_cnn_cudnn.py - AL ./tool/python/examples/cifar10_cnn_parameter.py - AL ./tool/python/examples/mnist_ae.py - AL ./tool/python/examples/mnist_mlp.py - AL ./tool/python/examples/mnist_mlp_parameter.py - AL ./tool/python/examples/mnist_mlp_test.py - AL ./tool/python/examples/mnist_rbm1.py - AL ./tool/python/examples/mnist_rbm2.py - AL ./tool/python/examples/mnist_rbm3.py - AL ./tool/python/examples/mnist_rbm4.py - AL ./tool/python/examples/train_cifar10.py - AL ./tool/python/examples/train_mnist.py - AL ./tool/python/examples/datasets/__init__.py - AL ./tool/python/examples/datasets/cifar10.py - AL ./tool/python/examples/datasets/mnist.py - AL ./tool/python/singa/__init__.py - AL ./tool/python/singa/driver.i - AL ./tool/python/singa/generatepy.sh - AL ./tool/python/singa/initializations.py - AL ./tool/python/singa/layer.py - AL ./tool/python/singa/model.py - AL ./tool/python/singa/parameter.py - AL ./tool/python/singa/utils/__init__.py - AL ./tool/python/singa/utils/message.py - AL ./tool/python/singa/utils/utility.py - -***************************************************** - Printing headers for files without AL header... - - -======================================================================= -==./.gitmodules -======================================================================= -[submodule "lib/cnmem"] - path = lib/cnmem - url = https://github.com/NVIDIA/cnmem.git - -======================================================================= -==./.travis.yml -======================================================================= -sudo: required -language: cpp -compiler: gcc -dist: trusty - -before_install: - - sudo apt-get -qq update - - sudo apt-get install -qq -y libopenblas-dev libgoogle-glog-dev libprotobuf-dev protobuf-compiler - - sudo apt-get install -qq -y opencl-headers ocl-icd-* - - wget https://github.com/KhronosGroup/OpenCL-CLHPP/releases/download/v2.0.9/cl2.hpp - - sudo mv cl2.hpp /usr/include/CL/ -#- sudo apt-get install -qq libgtest-dev - -before_script: - - mkdir build && cd build - - cmake .. -DUSE_CUDA=OFF -DUSE_CUDNN=OFF -DUSE_PYTHON=OFF -DBUILD_OPENCL_TESTS=OFF - -script: - - make - - ./bin/test_singa --gtest_output=xml:./../gtest.xml - - -======================================================================= -==./rat_check -======================================================================= - -======================================================================= -==./cmake/Protobuf.cmake -======================================================================= -# This script is taken from -# https://github.com/Kitware/CMake/blob/master/Modules/FindProtobuf.cmake -# and modified to our compilation. - -function(PROTOBUF_GENERATE_PYTHON OUTPUT) - if(NOT ARGN) - message(SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called - without any proto files") - return() - endif(NOT ARGN) - - set(${OUTPUT}) - foreach(FIL ${ARGN}) - get_filename_component(ABS_FIL ${FIL} ABSOLUTE) - get_filename_component(FIL_WE ${FIL} NAME_WE) - get_filename_component(PATH ${FIL} PATH) - - list(APPEND ${OUTPUT} "${CMAKE_BINARY_DIR}/python/singa/proto/${FIL_WE}_pb2.py") - - add_custom_command( - OUTPUT "${CMAKE_BINARY_DIR}/python/singa/proto/${FIL_WE}_pb2.py" - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --python_out ${CMAKE_BINARY_DIR}/python/singa/proto - --proto_path ${PATH} ${ABS_FIL} - DEPENDS ${ABS_FIL} - COMMENT "Running Python protocol buffer compiler on ${FIL}" VERBATIM) - endforeach() - - set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) - set(${OUTPUT} ${${OUTPUT}} PARENT_SCOPE) -endfunction() - -======================================================================= -==./cmake/Thirdparty/FindOpenCL.cmake -======================================================================= -# This script was taken from https://github.com/elhigu/cmake-findopencl -# and modified to support finding OpenCL 2.x C++ bindings. - -# Find OpenCL -# -# To set manually the paths, define these environment variables: -# OpenCL_INCPATH - Include path (e.g. OpenCL_INCPATH=/opt/cuda/4.0/cuda/include) -# OpenCL_LIBPATH - Library path (e.h. OpenCL_LIBPATH=/usr/lib64/nvidia) -# -# Once done this will define -# OPENCL_FOUND - system has OpenCL -# OPENCL_INCLUDE_DIRS - the OpenCL include directory -# OPENCL_LIBRARIES - link these to use OpenCL -# OPENCL_HAS_CPP_BINDINGS - system has also cl2.hpp - -FIND_PACKAGE(PackageHandleStandardArgs) - -SET (OPENCL_VERSION_STRING "0.1.0") -SET (OPENCL_VERSION_MAJOR 0) -SET (OPENCL_VERSION_MINOR 1) -SET (OPENCL_VERSION_PATCH 0) - -IF (APPLE) - - # IF OpenCL_LIBPATH is given use it and don't use default path - IF (DEFINED ENV{OpenCL_LIBPATH}) - FIND_LIBRARY(OPENCL_LIBRARIES OpenCL PATHS ENV OpenCL_LIBPATH NO_DEFAULT_PATH) - ELSE () - FIND_LIBRARY(OPENCL_LIBRARIES OpenCL DOC "OpenCL lib for OSX") - ENDIF () - - # IF OpenCL_INCPATH is given use it and find for CL/cl.h and OpenCL/cl.h do not try to find default paths - IF (DEFINED ENV{OpenCL_INCPATH}) - FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h OpenCL/cl.h PATHS ENV OpenCL_INCPATH NO_DEFAULT_PATH) - FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl2.hpp OpenCL/cl2.hpp PATHS ${OPENCL_INCLUDE_DIRS} NO_DEFAULT_PATH) - ELSE () - FIND_PATH(OPENCL_INCLUDE_DIRS OpenCL/cl.h DOC "Include for OpenCL on OSX") - FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS OpenCL/cl2.hpp DOC "Include for OpenCL CPP bindings on OSX") - ENDIF () - -ELSE (APPLE) - - IF (WIN32) - - # Find OpenCL includes and libraries from environment variables provided by vendor - SET(OPENCL_INCLUDE_SEARCH_PATHS) - SET(OPENCL_LIBRARY_SEARCH_PATHS) - SET(OPENCL_LIBRARY_64_SEARCH_PATHS) - - # Nvidia - -======================================================================= -==./include/singa/utils/cuda_utils.h -======================================================================= -// from caffe include/caffe/util/device_alternative.hpp -#ifndef SINGA_UTILS_CUDA_UTILS_H_ -#define SINGA_UTILS_CUDA_UTILS_H_ - -#include "singa/singa_config.h" -#ifdef USE_CUDA -#include <cublas_v2.h> -#include <cuda.h> -#include <cuda_runtime.h> -#include <curand.h> - -inline const char* cublasGetErrorString(cublasStatus_t error) { - switch (error) { - case CUBLAS_STATUS_SUCCESS: - return "CUBLAS_STATUS_SUCCESS"; - case CUBLAS_STATUS_NOT_INITIALIZED: - return "CUBLAS_STATUS_NOT_INITIALIZED"; - case CUBLAS_STATUS_ALLOC_FAILED: - return "CUBLAS_STATUS_ALLOC_FAILED"; - case CUBLAS_STATUS_INVALID_VALUE: - return "CUBLAS_STATUS_INVALID_VALUE"; - case CUBLAS_STATUS_ARCH_MISMATCH: - return "CUBLAS_STATUS_ARCH_MISMATCH"; - case CUBLAS_STATUS_MAPPING_ERROR: - return "CUBLAS_STATUS_MAPPING_ERROR"; - case CUBLAS_STATUS_EXECUTION_FAILED: - return "CUBLAS_STATUS_EXECUTION_FAILED"; - case CUBLAS_STATUS_INTERNAL_ERROR: - return "CUBLAS_STATUS_INTERNAL_ERROR"; -#if CUDA_VERSION >= 6000 - case CUBLAS_STATUS_NOT_SUPPORTED: - return "CUBLAS_STATUS_NOT_SUPPORTED"; -#endif -#if CUDA_VERSION >= 6050 - case CUBLAS_STATUS_LICENSE_ERROR: - return "CUBLAS_STATUS_LICENSE_ERROR"; -#endif - } - return "Unknown cublas status"; -} - -inline const char* curandGetErrorString(curandStatus_t error) { - switch (error) { - case CURAND_STATUS_SUCCESS: - return "CURAND_STATUS_SUCCESS"; - case CURAND_STATUS_VERSION_MISMATCH: - return "CURAND_STATUS_VERSION_MISMATCH"; - case CURAND_STATUS_NOT_INITIALIZED: - return "CURAND_STATUS_NOT_INITIALIZED"; - case CURAND_STATUS_ALLOCATION_FAILED: - -======================================================================= -==./include/singa/utils/tinydir.h -======================================================================= -/* -Copyright (c) 2013-2014, Cong Xu, Baudouin Feildel -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#ifndef TINYDIR_H -#define TINYDIR_H - -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#ifdef _MSC_VER -#pragma warning (disable : 4996) -#endif -#else -#include <dirent.h> -#include <libgen.h> -#include <sys/stat.h> -#endif - - -/* types */ - -#define _TINYDIR_PATH_MAX 4096 -#ifdef _WIN32 -/* extra chars for the "\\*" mask */ -#define _TINYDIR_PATH_EXTRA 2 -#else - -======================================================================= -==./lib/cnmem/.git -======================================================================= -gitdir: ../../.git/modules/lib/cnmem - -======================================================================= -==./lib/cnmem/CMakeLists.txt -======================================================================= -# CMakeLists to build the cnmem library. -cmake_minimum_required(VERSION 2.8.8) -project(cnmem) - -# We need CUDA to build that library. -find_package(CUDA QUIET REQUIRED) -include_directories(${CUDA_INCLUDE_DIRS}) - -# Rules to build the cnmem library. -include_directories(include) -add_definitions(-DCNMEM_DLLEXPORT) -add_library(cnmem SHARED src/cnmem.cpp) -set_target_properties(cnmem PROPERTIES VERSION 1.0.0 SOVERSION 1) -target_link_libraries(cnmem LINK_PUBLIC ${CUDA_LIBRARIES}) -install(TARGETS cnmem RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib) -install(FILES include/cnmem.h DESTINATION include) - -# Add the tests. -if(WITH_TESTS) - - # Get Google tests. - find_package(GTest QUIET REQUIRED) - include_directories(${GTEST_INCLUDE_DIRS}) - - # Build the executable. - add_executable(cnmem_tests tests/cnmem_tests.cpp) - if(MSVC) - if(MSVC_VERSION GREATER 1700) # Visual Studio 11 or more. - add_definitions(-DUSE_CPP_11) - endif(MSVC_VERSION GREATER 1700) - endif(MSVC) - if(CMAKE_COMPILER_IS_GNUCC) - add_definitions(-std=c++11 -DUSE_CPP_11) - endif(CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(cnmem_tests LINK_PUBLIC cnmem ${CUDA_LIBRARIES} ${GTEST_LIBRARIES} -lpthread) - install(TARGETS cnmem_tests RUNTIME DESTINATION bin) - - # On Windows, we copy the Google test DLL to the bin folder. - if(MSVC) - get_filename_component(gtest_dll_path ${GTEST_LIBRARIES} DIRECTORY) - install(FILES ${gtest_dll_path}/gtest.dll DESTINATION bin) - endif(MSVC) - -endif(WITH_TESTS) - - -======================================================================= -==./lib/cnmem/include/cnmem.h -======================================================================= -/* ********************************************************************** - * Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ********************************************************************** */ -#pragma once - -#ifdef __cplusplus -#include "cstdio" -#else -#include "stdio.h" -#endif -#include "cuda_runtime_api.h" - -#if defined(_MSC_VER) || defined(WIN32) -#ifdef CNMEM_DLLEXPORT -#define CNMEM_API __declspec(dllexport) -#else -#define CNMEM_API __declspec(dllimport) -#endif -#else -#ifdef CNMEM_DLLEXPORT -#define CNMEM_API __attribute__((visibility ("default"))) -#else -#define CNMEM_API -#endif -#endif - - -======================================================================= -==./lib/cnmem/src/cnmem.cpp -======================================================================= -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// * Neither the name of NVIDIA CORPORATION nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/////////////////////////////////////////////////////////////////////////////////////////////////// - -#include "cnmem.h" -#include <cstddef> -#include <vector> -#include <cuda_runtime_api.h> - -#if !defined(WIN32) && defined(_MSC_VER) -#define WIN32 -#endif - -#ifdef WIN32 -#include <Windows.h> -#else -#include <pthread.h> -#endif - -#if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4 // ARMv7 is the only 32-bit target that we support. -#define CNMEM_BUILD_WITH_32_BIT_POINTERS -#endif - -#define CNMEM_GRANULARITY 512 - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -======================================================================= -==./lib/cnmem/tests/cnmem_tests.cpp -======================================================================= -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// * Neither the name of NVIDIA CORPORATION nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -/////////////////////////////////////////////////////////////////////////////////////////////////// - -#include <gtest/gtest.h> -#include <cnmem.h> -#include <fstream> -#ifdef USE_CPP_11 -#include <thread> -#endif - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -static std::size_t getFreeMemory() { - cudaFree(0); - std::size_t freeMem, totalMem; - cudaMemGetInfo(&freeMem, &totalMem); - return freeMem; -} - -class CnmemTest : public ::testing::Test { - /// We determine the amount of free memory. - std::size_t mFreeMem; - -protected: - /// Do we test memory leaks. - -======================================================================= -==./src/core/tensor/distribution.cl -======================================================================= -// This code is adapted from https://github.com/amd/OpenCL-caffe/blob/stable/src/caffe/ocl/random.cl - -//Note: random generator has two parts -//first part: the open sourced threefy random generator kernel from DE Shaw Research -//second part. we wrap the kernel up to generate uniform, bernoulli and gaussion distribution generators. - -//begin: the open sourced random generator from DE Shaw Research -//https://www.deshawresearch.com/resources_random123.html -typedef uint uint32_t; - -struct r123array4x32 { - uint32_t v[4]; -}; - -enum r123_enum_threefry32x4 { - R_32x4_0_0 = 10, - R_32x4_0_1 = 26, - R_32x4_1_0 = 11, - R_32x4_1_1 = 21, - R_32x4_2_0 = 13, - R_32x4_2_1 = 27, - R_32x4_3_0 = 23, - R_32x4_3_1 = 5, - R_32x4_4_0 = 6, - R_32x4_4_1 = 20, - R_32x4_5_0 = 17, - R_32x4_5_1 = 11, - R_32x4_6_0 = 25, - R_32x4_6_1 = 10, - R_32x4_7_0 = 18, - R_32x4_7_1 = 20 -}; - -inline uint32_t RotL_32(uint32_t x, unsigned int N) { - return (x << (N & 31)) | (x >> ((32 - N) & 31)); -} - -typedef struct r123array4x32 threefry4x32_ctr_t; -typedef struct r123array4x32 threefry4x32_key_t; -typedef struct r123array4x32 threefry4x32_ukey_t; - -inline threefry4x32_ctr_t threefry4x32_R(unsigned int Nrounds, threefry4x32_ctr_t in, threefry4x32_key_t k) { - threefry4x32_ctr_t X; - uint32_t ks[4 + 1]; - int i; - ks[4] = 0x1BD11BDA; - - { - ks[0] = k.v[0]; - X.v[0] = in.v[0]; - -======================================================================= -==./src/python/swig/numpy.i -======================================================================= -/* -*- C -*- (not really, but good for syntax highlighting) */ - -/* - * Copyright (c) 2005-2015, NumPy Developers. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * * Neither the name of the NumPy Developers nor the names of any - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef SWIGPYTHON - -%{ -#ifndef SWIG_FILE_WITH_INIT -#define NO_IMPORT_ARRAY -#endif -#include "stdio.h" -#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION -#include <numpy/arrayobject.h> -%} - -/**********************************************************************/ - -%fragment("NumPy_Backward_Compatibility", "header") -{ - -======================================================================= -==./test/gtest/gtest-all.cc -======================================================================= -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: [email protected] (Markus Heule) -// -// Google C++ Testing Framework (Google Test) -// -// Sometimes it's desirable to build Google Test by compiling a single file. -// This file serves this purpose. - -// This line ensures that gtest.h can be compiled on its own, even -// when it's fused. -#include "gtest/gtest.h" - -// The following lines pull in the real gtest *.cc files. -// Copyright 2005, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. - -======================================================================= -==./test/gtest/gtest.h -======================================================================= -// Copyright 2005, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: [email protected] (Zhanyong Wan) -// -// The Google C++ Testing Framework (Google Test) -// -// This header file defines the public API for Google Test. It should be -// included by any test program that uses Google Test. -// -// IMPORTANT NOTE: Due to limitation of the C++ language, we have to -// leave some internal implementation details in this header file. -// They are clearly marked by comments like this: -// -// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. -// -// Such code is NOT meant to be used by a user directly, and is subject -// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user -// program! -// -// Acknowledgment: Google Test borrowed the idea of automatic test -// registration from Barthelemy Dagenais' ([email protected]) -// easyUnit framework. - - -======================================================================= -==./test/gtest/gtest_main.cc -======================================================================= -// Copyright 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include <stdio.h> - -#include "gtest/gtest.h" - -GTEST_API_ int main(int argc, char **argv) { - printf("Running main() from gtest_main.cc\n"); - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -======================================================================= -==./tool/cpplint.py -======================================================================= -#!/usr/bin/env python -# -# Copyright (c) 2009 Google Inc. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -"""Does google-lint on c++ files. - -The goal of this script is to identify places in the code that *may* -be in non-compliance with google style. It does not attempt to fix -up these problems -- the point is to educate. It does also not -attempt to find all problems, or to ensure that everything it does -find is legitimately a problem. - -In particular, we can get very confused by /* and // inside strings! -We do a small hack, which is to ignore //'s with "'s after them on the -same line, but it is far from perfect (in either direction). -""" - -import codecs -import copy -import getopt -import math # for log -import os -import re -import sre_compile
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/src/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 174f05e..cc1ee0c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,19 +6,19 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# +# -# generate protobuf sources +# generate protobuf sources -FILE(GLOB proto_files proto/*.proto) +FILE(GLOB proto_files proto/*.proto) protobuf_generate_cpp(proto_srcs proto_hdrs ${proto_files}) IF (USE_PYTHON) protobuf_generate_python(proto_pys ${proto_files}) @@ -111,9 +111,9 @@ IF(USE_PYTHON) file(GLOB_RECURSE python_source_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py) create_symlinks(${python_source_files}) - + SET(python_cxxs "${core_source};${io_source};${model_source};${utils_source}") - ADD_LIBRARY(_singa_wrap SHARED "${python_srcs} ${python_cxxs} ${cuda_objs}") + ADD_LIBRARY(_singa_wrap SHARED ${python_srcs} ${python_cxxs} ${cuda_objs}) SET(WRAPPER_LINKER_LIBS "${PREVIOUS_LINKER_LIBS}") TARGET_LINK_LIBRARIES(_singa_wrap ${WRAPPER_LINKER_LIBS}) TARGET_INCLUDE_DIRECTORIES(_singa_wrap PRIVATE ${PYTHON_INCLUDE_DIRS}) http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/README.md ---------------------------------------------------------------------- diff --git a/tool/python/README.md b/tool/python/README.md deleted file mode 100644 index 8c90cfe..0000000 --- a/tool/python/README.md +++ /dev/null @@ -1,375 +0,0 @@ -# Python Binding - ---- - -Python binding provides APIs for configuring a training job following -[keras](http://keras.io/), including the configuration of neural net, training -algorithm, etc. It replaces the configuration file (e.g., *job.conf*) in -protobuf format, which is typically long and error-prone to prepare. In later -version, we will add python functions to interact with the layer and neural net -objects, which would enable users to train and debug their models -interactively. - -Here is the layout of python related code, - - SINGAROOT/tool/python - |-- pb2 (has job_pb2.py) - |-- singa - |-- model.py - |-- layer.py - |-- parameter.py - |-- initialization.py - |-- utils - |-- utility.py - |-- message.py - |-- examples - |-- cifar10_cnn.py, mnist_mlp.py, , mnist_rbm1.py, mnist_ae.py, etc. - |-- datasets - |-- cifar10.py - |-- mnist.py - -## Compiling and running instructions - -In order to use the Python APIs, users need to add the following arguments when compiling -SINGA, - - ./configure --enable-python --with-python=PYTHON_DIR - make - -where PYTHON_DIR has Python.h - - -The training program is launched by - - bin/singa-run.sh -exec <user_main.py> - -where user_main.py creates the JobProto object and passes it to Driver::Train to -start the training. - -For example, - - cd SINGAROOT - bin/singa-run.sh -exec tool/python/examples/cifar10_cnn.py - - - -## Examples - - -### MLP Example - -This example uses python APIs to configure and train a MLP model over the MNIST -dataset. The configuration content is the same as that written in *SINGAROOT/examples/mnist/job.conf*. - -``` -X_train, X_test, workspace = mnist.load_data() - -m = Sequential('mlp', sys.argv) - -m.add(Dense(2500, init='uniform', activation='tanh')) -m.add(Dense(2000, init='uniform', activation='tanh')) -m.add(Dense(1500, init='uniform', activation='tanh')) -m.add(Dense(1000, init='uniform', activation='tanh')) -m.add(Dense(500, init='uniform', activation='tanh')) -m.add(Dense(10, init='uniform', activation='softmax')) - -sgd = SGD(lr=0.001, lr_type='step') -topo = Cluster(workspace) -m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo) -m.fit(X_train, nb_epoch=1000, with_test=True) -result = m.evaluate(X_test, batch_size=100, test_steps=10, test_freq=60) -``` - -### CNN Example - -This example uses python APIs to configure and train a CNN model over the Cifar10 -dataset. The configuration content is the same as that written in *SINGAROOT/examples/cifar10/job.conf*. - - -``` -X_train, X_test, workspace = cifar10.load_data() - -m = Sequential('cnn', sys.argv) - -m.add(Convolution2D(32, 5, 1, 2, w_std=0.0001, b_lr=2)) -m.add(MaxPooling2D(pool_size=(3,3), stride=2)) -m.add(Activation('relu')) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -m.add(Convolution2D(32, 5, 1, 2, b_lr=2)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size=(3,3), stride=2)) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -m.add(Convolution2D(64, 5, 1, 2)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size=(3,3), stride=2)) - -m.add(Dense(10, w_wd=250, b_lr=2, b_wd=0, activation='softmax')) - -sgd = SGD(decay=0.004, lr_type='manual', step=(0,60000,65000), step_lr=(0.001,0.0001,0.00001)) -topo = Cluster(workspace) -m.compile(updater=sgd, cluster=topo) -m.fit(X_train, nb_epoch=1000, with_test=True) -result = m.evaluate(X_test, 1000, test_steps=30, test_freq=300) -``` - - -### RBM Example - -This example uses python APIs to configure and train a RBM model over the MNIST -dataset. The configuration content is the same as that written in *SINGAROOT/examples/rbm*.conf*. - -``` -rbmid = 3 -X_train, X_test, workspace = mnist.load_data(nb_rbm=rbmid) -m = Energy('rbm'+str(rbmid), sys.argv) - -out_dim = [1000, 500, 250] -m.add(RBM(out_dim, w_std=0.1, b_wd=0)) - -sgd = SGD(lr=0.1, decay=0.0002, momentum=0.8) -topo = Cluster(workspace) -m.compile(optimizer=sgd, cluster=topo) -m.fit(X_train, alg='cd', nb_epoch=6000) -``` - -### AutoEncoder Example -This example uses python APIs to configure and train an autoencoder model over -the MNIST dataset. The configuration content is the same as that written in -*SINGAROOT/examples/autoencoder.conf*. - - -``` -rbmid = 4 -X_train, X_test, workspace = mnist.load_data(nb_rbm=rbmid+1) -m = Sequential('autoencoder', sys.argv) - -hid_dim = [1000, 500, 250, 30] -m.add(Autoencoder(hid_dim, out_dim=784, activation='sigmoid', param_share=True)) - -agd = AdaGrad(lr=0.01) -topo = Cluster(workspace) -m.compile(loss='mean_squared_error', optimizer=agd, cluster=topo) -m.fit(X_train, alg='bp', nb_epoch=12200) -``` - -### To run SINGA on GPU - -Users need to set a list of gpu ids to `device` field in fit() or evaluate(). -The number of GPUs must be the same to the number of workers configured for -cluster topology. - - -``` -gpu_id = [0] -m.fit(X_train, nb_epoch=100, with_test=True, device=gpu_id) -``` - -### TIPS - -Hidden layers for MLP can be configured as - -``` -for n in [2500, 2000, 1500, 1000, 500]: - m.add(Dense(n, init='uniform', activation='tanh')) -m.add(Dense(10, init='uniform', activation='softmax')) -``` - -Activation layer can be specified separately - -``` -m.add(Dense(2500, init='uniform')) -m.add(Activation('tanh')) -``` - -Users can explicitly specify hyper-parameters of weight and bias - -``` -par = Parameter(init='uniform', scale=0.05) -m.add(Dense(2500, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(2000, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(1500, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(1000, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(500, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(10, w_param=par, b_param=par, activation='softmax')) -``` - - -``` -parw = Parameter(init='gauss', std=0.0001) -parb = Parameter(init='const', value=0) -m.add(Convolution(32, 5, 1, 2, w_param=parw, b_param=parb, b_lr=2)) -m.add(MaxPooling2D(pool_size(3,3), stride=2)) -m.add(Activation('relu')) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -parw.update(std=0.01) -m.add(Convolution(32, 5, 1, 2, w_param=parw, b_param=parb)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size(3,3), stride=2)) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -m.add(Convolution(64, 5, 1, 2, w_param=parw, b_param=parb, b_lr=1)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size(3,3), stride=2)) - -m.add(Dense(10, w_param=parw, w_wd=250, b_param=parb, b_lr=2, b_wd=0, activation='softmax')) -``` - - -Data can be added in this way, - -``` -X_train, X_test = mnist.load_data() // parameter values are set in load_data() -m.fit(X_train, ...) // Data layer for training is added -m.evaluate(X_test, ...) // Data layer for testing is added -``` -or this way, - -``` -X_train, X_test = mnist.load_data() // parameter values are set in load_data() -m.add(X_train) // explicitly add Data layer -m.add(X_test) // explicitly add Data layer -``` - - -``` -store = Store(path='train.bin', batch_size=64, ...) // parameter values are set explicitly -m.add(Data(load='recordinput', phase='train', conf=store)) // Data layer is added -store = Store(path='test.bin', batch_size=100, ...) // parameter values are set explicitly -m.add(Data(load='recordinput', phase='test', conf=store)) // Data layer is added -``` - - -### Cases to run SINGA - -(1) Run SINGA for training - -``` -m.fit(X_train, nb_epoch=1000) -``` - -(2) Run SINGA for training and validation - -``` -m.fit(X_train, validate_data=X_valid, nb_epoch=1000) -``` - -(3) Run SINGA for test while training - -``` -m.fit(X_train, nb_epoch=1000, with_test=True) -result = m.evaluate(X_test, batch_size=100, test_steps=100) -``` - -(4) Run SINGA for test only -Assume a checkpoint exists after training - -``` -result = m.evaluate(X_test, batch_size=100, checkpoint_path=workspace+'/checkpoint/step100-worker0') -``` - - -## Implementation Details - -### Layer class (inherited) - -* Data -* Dense -* Activation -* Convolution2D -* MaxPooling2D -* AvgPooling2D -* LRN2D -* Dropout -* RBM -* Autoencoder - -### Model class - -Model class has `jobconf` (JobProto) and `layers` (layer list) - -Methods in Model class - -* add - * add Layer into Model - * 2 subclasses: Sequential model and Energy model - -* compile - * set Updater (i.e., optimizer) and Cluster (i.e., topology) components - -* fit - * set Training data and parameter values for the training - * (optional) set Validatiaon data and parameter values - * set Train_one_batch component - * specify `with_test` field if a user wants to run SINGA with test data simultaneously. - * [TODO] recieve train/validation results, e.g., accuracy, loss, ppl, etc. - -* evaluate - * set Testing data and parameter values for the testing - * specify `checkpoint_path` field if a user want to run SINGA only for testing. - * [TODO] recieve test results, e.g., accuracy, loss, ppl, etc. - -### Results - -fit() and evaluate() return train/test results, a dictionary containing - -* [key]: step number -* [value]: a list of dictionay - * 'acc' for accuracy - * 'loss' for loss - * 'ppl' for ppl - * 'se' for squred error - - -### Parameter class - -Users need to set parameter and initial values. For example, - -* Parameter (fields in Param proto) - * lr = (float) // learning rate multiplier, used to scale the learning rate when updating parameters. - * wd = (float) // weight decay multiplier, used to scale the weight decay when updating parameters. - -* Parameter initialization (fields in ParamGen proto) - * init = (string) // one of the types, 'uniform', 'constant', 'gaussian' - * high = (float) // for 'uniform' - * low = (float) // for 'uniform' - * value = (float) // for 'constant' - * mean = (float) // for 'gaussian' - * std = (float) // for 'gaussian' - -* Weight (`w_param`) is 'gaussian' with mean=0, std=0.01 at default - -* Bias (`b_param`) is 'constant' with value=0 at default - -* How to update the parameter fields - * for updating Weight, put `w_` in front of field name - * for updating Bias, put `b_` in front of field name - -Several ways to set Parameter values - -``` -parw = Parameter(lr=2, wd=10, init='gaussian', std=0.1) -parb = Parameter(lr=1, wd=0, init='constant', value=0) -m.add(Convolution2D(10, w_param=parw, b_param=parb, ...) -``` - -``` -m.add(Dense(10, w_mean=1, w_std=0.1, w_lr=2, w_wd=10, ...) -``` - -``` -parw = Parameter(init='constant', mean=0) -m.add(Dense(10, w_param=parw, w_lr=1, w_wd=1, b_value=1, ...) -``` - -### Other classes - -* Store -* Algorithm -* Updater -* SGD -* AdaGrad -* Cluster - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/__init__.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/__init__.py b/tool/python/examples/__init__.py deleted file mode 100644 index a796a7a..0000000 --- a/tool/python/examples/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/cifar10_cnn.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/cifar10_cnn.py b/tool/python/examples/cifar10_cnn.py deleted file mode 100755 index 8d4e778..0000000 --- a/tool/python/examples/cifar10_cnn.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import cifar10 - -X_train, X_test, workspace = cifar10.load_data() - -m = Sequential('cifar10-cnn', sys.argv) - -m.add(Convolution2D(32, 5, 1, 2, w_std=0.0001, b_lr=2)) -m.add(MaxPooling2D(pool_size=(3,3), stride=2)) -m.add(Activation('relu')) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -m.add(Convolution2D(32, 5, 1, 2, b_lr=2)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size=(3,3), stride=2)) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -m.add(Convolution2D(64, 5, 1, 2)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size=(3,3), stride=2)) - -m.add(Dense(10, w_wd=250, b_lr=2, b_wd=0, activation='softmax')) - -sgd = SGD(decay=0.004, momentum=0.9, lr_type='manual', step=(0,60000,65000), step_lr=(0.001,0.0001,0.00001)) -topo = Cluster(workspace) -m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo) -m.fit(X_train, nb_epoch=1000, with_test=True) -result = m.evaluate(X_test, test_steps=100, test_freq=300) - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/cifar10_cnn_cudnn.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/cifar10_cnn_cudnn.py b/tool/python/examples/cifar10_cnn_cudnn.py deleted file mode 100755 index e243834..0000000 --- a/tool/python/examples/cifar10_cnn_cudnn.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python - -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import cifar10 - -X_train, X_test, workspace = cifar10.load_data() - -m = Sequential('cifar10-cnn', sys.argv) - -m.add(Convolution2D(32, 5, 1, 2, w_std=0.0001, b_lr=2)) -m.add(MaxPooling2D(pool_size=(3,3), stride=2)) -m.add(Activation('relu')) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -m.add(Convolution2D(32, 5, 1, 2, b_lr=2)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size=(3,3), stride=2)) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -m.add(Convolution2D(64, 5, 1, 2)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size=(3,3), stride=2)) - -m.add(Dense(10, w_wd=250, b_lr=2, b_wd=0, activation='softmax')) - -sgd = SGD(decay=0.004, momentum=0.9, lr_type='manual', step=(0,60000,65000), step_lr=(0.001,0.0001,0.00001)) -topo = Cluster(workspace) -m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo) - -gpu_id = [0] -m.fit(X_train, nb_epoch=7000, with_test=True, device=gpu_id) -result = m.evaluate(X_test, test_steps=100, test_freq=1000) - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/cifar10_cnn_parameter.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/cifar10_cnn_parameter.py b/tool/python/examples/cifar10_cnn_parameter.py deleted file mode 100755 index c5470b6..0000000 --- a/tool/python/examples/cifar10_cnn_parameter.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import cifar10 - -X_train, X_test, workspace = cifar10.load_data() - -m = Sequential('cifar10-cnn', sys.argv) - -parw = Parameter(init='gaussian', std=0.0001) -parb = Parameter(init='constant') -m.add(Convolution2D(32, 5, 1, 2, w_param=parw, b_param=parb, b_lr=2)) -m.add(MaxPooling2D(pool_size=(3,3), stride=2)) -m.add(Activation('relu')) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -parw.update(std=0.01) -m.add(Convolution2D(32, 5, 1, 2, w_param=parw, b_param=parb)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size=(3,3), stride=2)) -m.add(LRN2D(3, alpha=0.00005, beta=0.75)) - -m.add(Convolution2D(64, 5, 1, 2, w_param=parw, b_param=parb, b_lr=1)) -m.add(Activation('relu')) -m.add(AvgPooling2D(pool_size=(3,3), stride=2)) - -m.add(Dense(10, w_param=parw, w_wd=250, b_param=parb, b_lr=2, b_wd=0, activation='softmax')) - -sgd = SGD(decay=0.004, lr_type='manual', step=(0,60000,65000), step_lr=(0.001,0.0001,0.00001)) -topo = Cluster(workspace) -m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo) -m.fit(X_train, nb_epoch=100, with_test=True) -result = m.evaluate(X_test, test_steps=10, test_freq=300) - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/datasets/__init__.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/datasets/__init__.py b/tool/python/examples/datasets/__init__.py deleted file mode 100644 index a796a7a..0000000 --- a/tool/python/examples/datasets/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/datasets/cifar10.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/datasets/cifar10.py b/tool/python/examples/datasets/cifar10.py deleted file mode 100644 index ef5136f..0000000 --- a/tool/python/examples/datasets/cifar10.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python - -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -from singa.model import * - -def load_data( - workspace = None, - backend = 'kvfile', - batchsize = 64, - random = 5000, - shape = (3, 32, 32), - std = 127.5, - mean = 127.5 - ): - - # using cifar10 dataset - data_dir = 'examples/cifar10' - path_train = data_dir + '/train_data.bin' - path_test = data_dir + '/test_data.bin' - path_mean = data_dir + '/image_mean.bin' - if workspace == None: workspace = data_dir - - store = Store(path=path_train, mean_file=path_mean, backend=backend, - random_skip=random, batchsize=batchsize, - shape=shape) - - data_train = Data(load='recordinput', phase='train', conf=store) - - store = Store(path=path_test, mean_file=path_mean, backend=backend, - batchsize=batchsize, - shape=shape) - - data_test = Data(load='recordinput', phase='test', conf=store) - - return data_train, data_test, workspace - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/datasets/mnist.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/datasets/mnist.py b/tool/python/examples/datasets/mnist.py deleted file mode 100644 index 0f75393..0000000 --- a/tool/python/examples/datasets/mnist.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python - -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -from singa.model import * - -def load_data( - workspace = None, - backend = 'kvfile', - nb_rbm = 0, # the number of layers for RBM and Autoencoder - checkpoint_steps = 0, - **pvalues - ): - - # using mnist dataset - data_dir = 'examples/mnist' - path_train = data_dir + '/train_data.bin' - path_test = data_dir + '/test_data.bin' - if workspace == None: workspace = data_dir - - # checkpoint path to load - checkpoint_list = None - if checkpoint_steps > 0: - workerid = 0 - checkpoint_list = [] - for i in range(nb_rbm-1, 0, -1): - checkpoint_list.append('examples/rbm/rbm{0}/checkpoint/step{1}-worker{2}'.format(str(i),checkpoint_steps,workerid)) - - store = Store(path=path_train, backend=backend, **pvalues) - data_train = Data(load='recordinput', phase='train', conf=store, checkpoint=checkpoint_list) - - store = Store(path=path_test, backend=backend, **pvalues) - data_test = Data(load='recordinput', phase='test', conf=store) - - return data_train, data_test, workspace http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/mnist_ae.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/mnist_ae.py b/tool/python/examples/mnist_ae.py deleted file mode 100755 index 888f288..0000000 --- a/tool/python/examples/mnist_ae.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import mnist - -# Sample parameter values for Autoencoder example -rbmid = 4 -pvalues = {'batchsize' : 100, 'shape' : 784, 'std_value' : 255} -X_train, X_test, workspace = mnist.load_data( - workspace = 'examples/rbm/autoencoder', - nb_rbm = rbmid+1, - checkpoint_steps = 6000, - **pvalues) - -m = Sequential('autoencoder', sys.argv) - -hid_dim = [1000, 500, 250, 30] -m.add(Autoencoder(hid_dim, out_dim=784, activation='sigmoid', param_share=True)) - -agd = AdaGrad(lr=0.01) -topo = Cluster(workspace) -m.compile(loss='mean_squared_error', optimizer=agd, cluster=topo) -m.fit(X_train, alg='bp', nb_epoch=12200, with_test=True) -result = m.evaluate(X_test, test_steps=100, test_freq=1000) - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/mnist_mlp.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/mnist_mlp.py b/tool/python/examples/mnist_mlp.py deleted file mode 100755 index 10cd15e..0000000 --- a/tool/python/examples/mnist_mlp.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import mnist - -# Sample parameter values for Mnist MLP example -pvalues = {'batchsize' : 64, 'shape' : 784, 'random_skip' : 5000, - 'std_value' : 127.5, 'mean_value' : 127.5} -X_train, X_test, workspace = mnist.load_data(**pvalues) - -m = Sequential('mlp', argv=sys.argv) - -''' Weight and Bias are initialized by - uniform distribution with scale=0.05 at default -''' -m.add(Dense(2500, init='uniform', activation='tanh')) -m.add(Dense(2000, init='uniform', activation='tanh')) -m.add(Dense(1500, init='uniform', activation='tanh')) -m.add(Dense(1000, init='uniform', activation='tanh')) -m.add(Dense(500, init='uniform', activation='tanh')) -m.add(Dense(10, init='uniform', activation='softmax')) - -sgd = SGD(lr=0.001, lr_type='step') -topo = Cluster(workspace) -m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo) - -m.fit(X_train, nb_epoch=100, with_test=True) -result = m.evaluate(X_test, batch_size=100, test_steps=10) - -#e.g., display result -#for k, v in sorted(result.items(), key=lambda x: x[0]): -# print k, v http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/mnist_mlp_parameter.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/mnist_mlp_parameter.py b/tool/python/examples/mnist_mlp_parameter.py deleted file mode 100755 index 9080451..0000000 --- a/tool/python/examples/mnist_mlp_parameter.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from singa.datasets import mnist - -# Sample parameter values for Mnist MLP example -pvalues = {'batchsize' : 64, 'shape' : 784, - 'random_skip' : 5000, - 'std_value' : 127.5, 'mean_value' : 127.5} -X_train, X_test, workspace = mnist.load_data(**pvalues) - -m = Sequential('mlp', argv=sys.argv) - -par = Parameter(init='uniform', scale=0.05) -m.add(Dense(2500, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(2000, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(1500, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(1000, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(500, w_param=par, b_param=par, activation='tanh')) -m.add(Dense(10, w_param=par, b_param=par, activation='softmax')) - -sgd = SGD(lr=0.001, lr_type='step') -topo = Cluster(workspace) -m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo) - -m.fit(X_train, nb_epoch=100, with_test=True) -result = m.evaluate(X_test, batch_size=100, test_steps=10) http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/mnist_mlp_test.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/mnist_mlp_test.py b/tool/python/examples/mnist_mlp_test.py deleted file mode 100755 index ee4e4aa..0000000 --- a/tool/python/examples/mnist_mlp_test.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import mnist - -# Sample parameter values for Mnist MLP example -pvalues = {'batchsize' : 64, 'shape' : 784, - 'std_value' : 127.5, 'mean_value' : 127.5} -X_train, X_test, workspace = mnist.load_data(**pvalues) - -m = Sequential('mlp', argv=sys.argv) - -m.add(Dense(2500, init='uniform', activation='tanh')) -m.add(Dense(2000, init='uniform', activation='tanh')) -m.add(Dense(1500, init='uniform', activation='tanh')) -m.add(Dense(1000, init='uniform', activation='tanh')) -m.add(Dense(500, init='uniform', activation='tanh')) -m.add(Dense(10, init='uniform', activation='softmax')) - -sgd = SGD(lr=0.001, lr_type='step') -topo = Cluster(workspace) -m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo) - -''' For doing test only, normally users sets checkpoint path - e.g., assume that checkpoint exists by - m.fit(X_train, nb_epoch=100, checkpoint_freq=100) -''' -path = workspace+'/checkpoint/step100-worker0' -result = m.evaluate(X_test, batch_size=100, test_steps=100, checkpoint_path=path) http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/mnist_rbm1.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/mnist_rbm1.py b/tool/python/examples/mnist_rbm1.py deleted file mode 100755 index 5f22d52..0000000 --- a/tool/python/examples/mnist_rbm1.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import mnist - -rbmid = 1 -pvalues = {'batchsize' : 100, 'shape' : 784, 'std_value' : 255} -X_train, X_test, workspace = mnist.load_data( - workspace = 'examples/rbm/rbm1', - nb_rbm = rbmid, - checkpoint_steps = 6000, - **pvalues) - -m = Energy('rbm'+str(rbmid), sys.argv) - -m.add(RBM(1000, w_std=0.1, b_wd=0)) - -sgd = SGD(lr=0.1, decay=0.0002, momentum=0.8) -topo = Cluster(workspace) -m.compile(optimizer=sgd, cluster=topo) -m.fit(X_train, alg='cd', nb_epoch=6000) -#result = m.evaluate(X_test, test_steps=100, test_freq=500) - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/mnist_rbm2.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/mnist_rbm2.py b/tool/python/examples/mnist_rbm2.py deleted file mode 100755 index 1544f14..0000000 --- a/tool/python/examples/mnist_rbm2.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import mnist - -rbmid = 2 -pvalues = {'batchsize' : 100, 'shape' : 784, 'std_value' : 255} -X_train, X_test, workspace = mnist.load_data( - workspace = 'examples/rbm/rbm2', - nb_rbm = rbmid, - checkpoint_steps = 6000, - **pvalues) - -m = Energy('rbm'+str(rbmid), sys.argv) - -out_dim = [1000, 500] -m.add(RBM(out_dim, w_std=0.1, b_wd=0)) - -sgd = SGD(lr=0.1, decay=0.0002, momentum=0.8) -topo = Cluster(workspace) -m.compile(optimizer=sgd, cluster=topo) -m.fit(X_train, alg='cd', nb_epoch=6000) -#result = m.evaluate(X_test, test_steps=100, test_freq=500) - http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ed9587c0/tool/python/examples/mnist_rbm3.py ---------------------------------------------------------------------- diff --git a/tool/python/examples/mnist_rbm3.py b/tool/python/examples/mnist_rbm3.py deleted file mode 100755 index 3a6348d..0000000 --- a/tool/python/examples/mnist_rbm3.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -#/************************************************************ -#* -#* Licensed to the Apache Software Foundation (ASF) under one -#* or more contributor license agreements. See the NOTICE file -#* distributed with this work for additional information -#* regarding copyright ownership. The ASF licenses this file -#* to you under the Apache License, Version 2.0 (the -#* "License"); you may not use this file except in compliance -#* with the License. You may obtain a copy of the License at -#* -#* http://www.apache.org/licenses/LICENSE-2.0 -#* -#* Unless required by applicable law or agreed to in writing, -#* software distributed under the License is distributed on an -#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#* KIND, either express or implied. See the License for the -#* specific language governing permissions and limitations -#* under the License. -#* -#*************************************************************/ - - -import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__),'..')) -from singa.model import * -from examples.datasets import mnist - -rbmid = 3 -pvalues = {'batchsize' : 100, 'shape' : 784, 'std_value' : 255} -X_train, X_test, workspace = mnist.load_data( - workspace = 'examples/rbm/rbm3', - nb_rbm = rbmid, - checkpoint_steps = 6000, - **pvalues) - -m = Energy('rbm'+str(rbmid), sys.argv) - -out_dim = [1000, 500, 250] -m.add(RBM(out_dim, w_std=0.1, b_wd=0)) - -sgd = SGD(lr=0.1, decay=0.0002, momentum=0.8) -topo = Cluster(workspace) -m.compile(optimizer=sgd, cluster=topo) -m.fit(X_train, alg='cd', nb_epoch=6000) -#result = m.evaluate(X_test, test_steps=100, test_freq=500) -
