CMakeLists.txt 2.6 KB
Newer Older
L
Luo Tao 已提交
1 2
file(GLOB GENERAL_OPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*_op.cc")
string(REPLACE ".cc" "" GENERAL_OPS "${GENERAL_OPS}")
Y
Yu Yang 已提交
3 4 5 6
function(op_library TARGET)
    # op_library is a function to create op library. The interface is same as
    # cc_library. But it handle split GPU/CPU code and link some common library
    # for ops.
L
Luo Tao 已提交
7
    set(OP_LIBRARY ${TARGET} ${OP_LIBRARY} PARENT_SCOPE)
Y
Yu Yang 已提交
8 9
    set(cc_srcs)
    set(cu_srcs)
Y
Yu Yang 已提交
10
    set(op_common_deps operator op_registry)
Y
Yu Yang 已提交
11 12 13 14 15 16
    set(options "")
    set(oneValueArgs "")
    set(multiValueArgs SRCS DEPS)
    cmake_parse_arguments(op_library "${options}" "${oneValueArgs}"
            "${multiValueArgs}" ${ARGN})

17 18 19 20
    list(LENGTH op_library_SRCS op_library_SRCS_len)
    if (${op_library_SRCS_len} EQUAL 0)
        if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.cc)
            list(APPEND cc_srcs ${TARGET}.cc)
Y
Yu Yang 已提交
21
        endif()
22
        if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.cu)
23
            list(APPEND cu_srcs ${TARGET}.cu)
24 25 26 27 28 29 30 31 32 33 34 35
        endif()
    else()
        foreach(src ${op_library_SRCS})
            if (${src} MATCHES ".*\\.cu$")
                list(APPEND cu_srcs ${src})
            elseif(${src} MATCHES ".*\\.cc$")
                list(APPEND cc_srcs ${src})
            else()
                message(FATAL_ERROR "${TARGET} Source file ${src} should only be .cc or .cu")
            endif()
        endforeach()
    endif()
Y
Yu Yang 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

    list(LENGTH cc_srcs cc_srcs_len)
    if (${cc_srcs_len} EQUAL 0)
        message(FATAL_ERROR "The op library ${TARGET} should contains at least one .cc file")
    endif()

    if (WITH_GPU)
        nv_library(${TARGET} SRCS ${cc_srcs} ${cu_srcs} DEPS ${op_library_DEPS}
                ${op_common_deps})
    else()
        cc_library(${TARGET} SRCS ${cc_srcs} DEPS ${op_library_DEPS}
                ${op_common_deps})
    endif()
endfunction()

Q
qijun 已提交
51
add_subdirectory(math)
52

53 54 55 56 57
set(DEPS_OPS
    identity_op
    minus_op
    mul_op
    recurrent_op
Z
cond op  
zchen0211 已提交
58
    cond_op
59
    scale_op)
60 61 62
op_library(identity_op DEPS scale_op)
op_library(minus_op DEPS scale_op)
op_library(mul_op DEPS math_function)
63
op_library(recurrent_op SRCS recurrent_op.cc rnn/recurrent_op_utils.cc
L
Luo Tao 已提交
64
  DEPS framework_proto tensor operator net_op)
Z
cond op  
zchen0211 已提交
65
op_library(cond_op SRCS cond_op.cc DEPS framework_proto tensor operator net_op)
66
op_library(scale_op DEPS net_op)
67

68
list(REMOVE_ITEM GENERAL_OPS ${DEPS_OPS})
L
Luo Tao 已提交
69
foreach(src ${GENERAL_OPS})
70
    op_library(${src})
L
Luo Tao 已提交
71 72 73 74
endforeach()

set(GLOB_OP_LIB ${OP_LIBRARY} CACHE INTERNAL "Global OP library")

75 76 77
cc_test(gather_test SRCS gather_test.cc DEPS tensor)
cc_test(net_op_test SRCS net_op_test.cc DEPS net_op)
cc_test(scatter_test SRCS scatter_test.cc DEPS tensor)