From 3c36bf5decd7a4b0fdef0f85e693f76be53836b6 Mon Sep 17 00:00:00 2001 From: Sang Ik Lee Date: Wed, 22 Jul 2020 16:46:04 -0700 Subject: [PATCH 1/7] Add notes. --- design_doc/graph.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 design_doc/graph.txt diff --git a/design_doc/graph.txt b/design_doc/graph.txt new file mode 100644 index 00000000000..036e4210ceb --- /dev/null +++ b/design_doc/graph.txt @@ -0,0 +1,31 @@ +Device: abstraction for a entity that has storage and compute capability +A default device must exist. + +Value: an entity that is device independent + +Node: node is an entity that can have zero or more runtime inputs and produces zero or 1 runtime output (that may feed in to many nodes.) +Node can have static attributes. +Node does not need to bind inputs or outputs at construction time. Static atrributes need to be given at construction. +Every node must provide an eval method, given a defice and ordered input value(s), produces output value. + + +Output (def-use chain): captures a single output value from a node and connects it to input(s) of one or more nodes. + +Input (use-def chain): captures a single input value that is produced from a node. + +Op: Op is a collection of connected nodes (or pattern of nodes) +Op has inputs and output(s) +Op must provide an ordered mapping of its inputs and outputs to internal node's inputs and outputs. +Op is a graph builder pattern +Device may provide a specialized eval method for an Op. If not, a fallback that calls eval methods of internal nodes is provided. + + +Op(Pattern) Matching: + +Graph execution: +- Define as go (eager) +- Frozen graph +- Asynchronous +- Lazy +- Multi device +- Hetro device From 8c7b5c97f33e8f2885c93fde9176504b24bb365d Mon Sep 17 00:00:00 2001 From: Sang Ik Lee Date: Mon, 27 Jul 2020 09:43:46 -0700 Subject: [PATCH 2/7] Temp. --- design_doc/graph.txt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/design_doc/graph.txt b/design_doc/graph.txt index 036e4210ceb..60c5cf1b03d 100644 --- a/design_doc/graph.txt +++ b/design_doc/graph.txt @@ -1,12 +1,26 @@ Device: abstraction for a entity that has storage and compute capability A default device must exist. +Every device must provide a to_host method that moves value from device to host and a from_host method that moves a value from host to device. Value: an entity that is device independent +Value is opaque and can only be accessed with to_plain method +This enables lazy evaluation as Value can actually be a built up higher other function that produces an entity. + +Node: node is an entity that can have zero or more runtime inputs and produces 1 or 2 runtime output (that may feed in to many nodes.) +First output is a special output (Output 0) that represents signal +Node are like math functions except that zero input is allowed and has a special output in addition to zero or more output. -Node: node is an entity that can have zero or more runtime inputs and produces zero or 1 runtime output (that may feed in to many nodes.) Node can have static attributes. Node does not need to bind inputs or outputs at construction time. Static atrributes need to be given at construction. -Every node must provide an eval method, given a defice and ordered input value(s), produces output value. +Every node must provide an eval method, given ordered host input value(s), produces host output value. +Devices can provide an eval method for nodes. +Every node must provide an memory_estimate() and compute_estimate() method +Every node must provide an infer output shape method +Every node must provide an forward method + +"Nodes are device independent" +"Values live on device" +"Graph describes computation(flow) in an abstract way." Output (def-use chain): captures a single output value from a node and connects it to input(s) of one or more nodes. From 7aa00e23316e6d118688fba03fa1dba5a92b8dcf Mon Sep 17 00:00:00 2001 From: Sang Ik Lee Date: Wed, 26 Aug 2020 16:24:55 -0700 Subject: [PATCH 3/7] Create xgraph folder. --- .../xgraph/design_doc}/graph.txt | 0 contrib/xgraph/design_doc/oplist.txt | 179 ++++++++++++++++++ 2 files changed, 179 insertions(+) rename {design_doc => contrib/xgraph/design_doc}/graph.txt (100%) create mode 100644 contrib/xgraph/design_doc/oplist.txt diff --git a/design_doc/graph.txt b/contrib/xgraph/design_doc/graph.txt similarity index 100% rename from design_doc/graph.txt rename to contrib/xgraph/design_doc/graph.txt diff --git a/contrib/xgraph/design_doc/oplist.txt b/contrib/xgraph/design_doc/oplist.txt new file mode 100644 index 00000000000..728e303ef63 --- /dev/null +++ b/contrib/xgraph/design_doc/oplist.txt @@ -0,0 +1,179 @@ +10/28/2019 +// Unary operations +abs.hpp +cos.hpp +cosh.hpp +acos.hpp +sin.hpp +asin.hpp +atan.hpp +erf.hpp +log.hpp +exp.hpp +sigmoid.hpp +sinh.hpp +softmax.hpp +sqrt.hpp +tan.hpp +tanh.hpp +negative.hpp +floor.hpp +not.hpp +sign.hpp + +// Binary comparison +greater.hpp +greater_eq.hpp +less.hpp +less_eq.hpp +not_equal.hpp +equal.hpp + +// Binary logical +and.hpp +xor.hpp +or.hpp + +// Binary elementwise arithmetic +add.hpp +divide.hpp +multiply.hpp +subtract.hpp + +// Binary single Window operation +convolution.hpp +// Unary single Window operation +avg_pool.hpp +max_pool.hpp + +out_height = floor((height+padding_below[h]+padding_above[h]-pool_size[h])/strides[h])+1 +out_width = floor((width+padding_below[w]+padding_above[w]-pool_size[w])/strides[w])+1 +When ceil_mode is True, ceil will be used instead of floor in this equation. + +out_height = floor((height+padding_below[h]+padding_above[h]-dilation[h]*(kernel_size[h]-1)-1)/strides[h])+1 +out_width = floor((width+padding_below[w]+padding_above[w]-dilation[w]*(kernel_size[w]-1)-1)/strides[w])+1 + +// Binary dual Window operation +dot.hpp +fused/matmul.hpp +fused/gemm.hpp + +all.hpp +allreduce.hpp +any.hpp +argmax.hpp +argmin.hpp +batch_norm.hpp +broadcast.hpp +broadcast_distributed.hpp +ceiling.hpp +concat.hpp +constant.hpp +convert.hpp +dequantize.hpp +embedding_lookup.hpp +experimental/batch_mat_mul.hpp +experimental/compiled_kernel.hpp +experimental/dyn_broadcast.hpp +experimental/dyn_pad.hpp +experimental/dyn_replace_slice.hpp +experimental/dyn_reshape.hpp +experimental/dyn_slice.hpp +experimental/generate_mask.hpp +experimental/layers/ctc_greedy_decoder.hpp +experimental/layers/detection_output.hpp +experimental/layers/interpolate.hpp +experimental/layers/prior_box.hpp +experimental/layers/prior_box_clustered.hpp +experimental/layers/proposal.hpp +experimental/layers/psroi_pooling.hpp +experimental/layers/region_yolo.hpp +experimental/layers/reorg_yolo.hpp +experimental/layers/roi_pooling.hpp +experimental/quantized_conv_bias.hpp +experimental/quantized_conv_relu.hpp +experimental/quantized_dot_bias.hpp +experimental/random_uniform.hpp +experimental/range.hpp +experimental/shape_of.hpp +experimental/tile.hpp +experimental/transpose.hpp +fused/clamp.hpp +fused/conv_fused.hpp +fused/depth_to_space.hpp +fused/elu.hpp +fused/fake_quantize.hpp +fused/gelu.hpp +fused/grn.hpp +fused/group_conv.hpp +fused/group_conv_transpose.hpp +fused/gru_cell.hpp +fused/hard_sigmoid.hpp +fused/layer_norm.hpp +fused/lstm_cell.hpp +fused/lstm_sequence.hpp +fused/mvn.hpp +fused/normalize_l2.hpp +fused/partial_slice.hpp +fused/prelu.hpp +fused/rnn_cell.hpp +fused/scale_shift.hpp +fused/shuffle_channels.hpp +fused/softmax_crossentropy.hpp +fused/space_to_depth.hpp +fused/split.hpp +fused/squared_difference.hpp +fused/squeeze.hpp +fused/unsqueeze.hpp +fused_op_tbl.hpp +gather.hpp +gather_nd.hpp +get_output_element.hpp +lrn.hpp +max.hpp +maximum.hpp +min.hpp +minimum.hpp +one_hot.hpp +op.hpp +op_tbl.hpp +pad.hpp +parameter.hpp +passthrough.hpp +power.hpp +product.hpp +quantize.hpp +quantized_convolution.hpp +quantized_dot.hpp +recv.hpp +reduce_mean.hpp +reduce_prod.hpp +reduce_sum.hpp +relu.hpp +replace_slice.hpp +reshape.hpp +result.hpp +reverse.hpp +reverse_sequence.hpp +scatter_add.hpp +scatter_nd_add.hpp +select.hpp +send.hpp +slice.hpp +stop_gradient.hpp +sum.hpp +topk.hpp +util/activation_functions.hpp +util/arithmetic_reduction.hpp +util/arithmetic_reductions_keep_dims.hpp +util/attr_types.hpp +util/binary_elementwise_arithmetic.hpp +util/binary_elementwise_comparison.hpp +util/binary_elementwise_logical.hpp +util/broadcasting.hpp +util/fused_op.hpp +util/index_reduction.hpp +util/logical_reduction.hpp +util/op_annotations.hpp +util/rnn_cell_base.hpp +util/unary_elementwise_arithmetic.hpp From 230065fc930ec5093c530c34ff7b504d177f5f87 Mon Sep 17 00:00:00 2001 From: Sang Ik Lee Date: Wed, 26 Aug 2020 17:05:52 -0700 Subject: [PATCH 4/7] Add dummy cmake list file. --- contrib/xgraph/CMakeLists.txt | 310 +++++++++++++++++++++++++++++ contrib/xgraph/src/CMakeLists.txt | 17 ++ contrib/xgraph/test/CMakeLists.txt | 17 ++ 3 files changed, 344 insertions(+) create mode 100644 contrib/xgraph/CMakeLists.txt create mode 100644 contrib/xgraph/src/CMakeLists.txt create mode 100644 contrib/xgraph/test/CMakeLists.txt diff --git a/contrib/xgraph/CMakeLists.txt b/contrib/xgraph/CMakeLists.txt new file mode 100644 index 00000000000..b17fa9652cb --- /dev/null +++ b/contrib/xgraph/CMakeLists.txt @@ -0,0 +1,310 @@ +# ****************************************************************************** +# Copyright 2017-2020 Intel Corporation +# +# Licensed 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. +# ****************************************************************************** + +cmake_minimum_required (VERSION 3.18) + +message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") + +# set directory where the custom finders live +set(NGRAPH_BASE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${NGRAPH_BASE_DIR}/cmake/Modules/") +get_property(XGRAPH_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(NOT XGRAPH_GENERATOR_IS_MULTI_CONFIG) + if (CMAKE_BUILD_TYPE) + set(RELEASE_TYPES Debug Release RelWithDebInfo MinSizeRel) + list(FIND RELEASE_TYPES ${CMAKE_BUILD_TYPE} INDEX_FOUND) + if (${INDEX_FOUND} EQUAL -1) + message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of Debug, Release, RelWithDebInfo, or MinSizeRel") + endif() + endif() +endif() + +if (UNIX AND NOT APPLE) + set(LINUX TRUE) +endif() + +# Enable _ROOT for CMake 3.12+ +cmake_policy(SET CMP0074 NEW) + +if (APPLE) + # Enable MACOS_RPATH by default. + cmake_policy(SET CMP0042 NEW) + # Enable CMAKE__COMPILER_ID AppleClang + cmake_policy(SET CMP0025 NEW) + # APPLE: Set CMAKE_OSX_SYSROOT if not set already. + cmake_policy(SET CMP0074 NEW) + execute_process(COMMAND sw_vers -productVersion + OUTPUT_VARIABLE OSX_FULL_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + + string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*$" "\\1" + OSX_SHORT_VERSION "${OSX_FULL_VERSION}") + + message(STATUS "Detected: OSX ${OSX_SHORT_VERSION}") + + if (CMAKE_OSX_SYSROOT) + message(STATUS "Using CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT}") + else() + execute_process(COMMAND xcode-select -p + OUTPUT_VARIABLE APPLE_DEV_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if("${APPLE_DEV_DIR}" STREQUAL "/Library/Developer/CommandLineTools") + # Command line tools only + set(XCODE_ISYSROOT ${APPLE_DEV_DIR}/SDKs/MacOSX.sdk) + message(STATUS "Trying command line tool sdk at ${XCODE_ISYSROOT}.") + if(NOT EXISTS ${XCODE_ISYSROOT}) + message(FATAL_ERROR "Cannot find macos sdk.") + endif() + else() + # Xcode is installed + set(XCODE_ISYSROOT ${APPLE_DEV_DIR}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${OSX_SHORT_VERSION}.sdk) + message(STATUS "Trying Xcode sdk at ${XCODE_ISYSROOT}.") + if(NOT EXISTS ${XCODE_ISYSROOT}) + set(XCODE_ISYSROOT ${APPLE_DEV_DIR}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk) + if(NOT EXISTS ${XCODE_ISYSROOT}) + message(FATAL_ERROR "Cannot find macos sdk.") + endif() + endif() + endif() + message(STATUS "Setting CMAKE_OSX_SYSROOT for macos ${OSX_SHORT_VERSION} to ${XCODE_ISYSROOT}") + set(CMAKE_OSX_SYSROOT ${XCODE_ISYSROOT}) + endif() +endif() + +project (xgraph) + +# Tells if ngraph source tree is embedded in some other project +# TRUE if embedded in source tree +# FALSE if used standalone or as an external project +if(NOT ("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")) + set(XGRAPH_IS_EMBEDDED TRUE) +else() + set(XGRAPH_IS_EMBEDDED FALSE) +endif() + +if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + message(FATAL_ERROR "In-source builds are not allowed.") +endif() + +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/local" CACHE PATH "..." FORCE) +endif() + +set(XGRAPH_CXX_STANDARD 17) +if(CMAKE_CXX_STANDARD) + if(CMAKE_CXX_STANDARD VERSIONLESS XGRAPH_CXX_STANDARD) + message(FATAL_ERROR "CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD} is lower than ${XGRAPH_CXX_STANDARD}.") + endif() +endif() +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Create compilation database compile_commands.json +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# Setup CMAKE_ARGS to be forwarded to External Projects +set(XGRAPH_FORWARD_CMAKE_ARGS + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} + -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} + -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} + -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=${CMAKE_EXPORT_COMPILE_COMMANDS} + -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=${CMAKE_POSITION_INDEPENDENT_CODE} + ) + +if (CMAKE_OSX_SYSROOT) + set(XGRAPH_FORWARD_CMAKE_ARGS + ${NGRAPH_FORWARD_CMAKE_ARGS} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + ) +endif() + +if (NOT XGRAPH_GENERATOR_IS_MULTI_CONFIG) + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type" FORCE) + endif() + + set(XGRAPH_FORWARD_CMAKE_ARGS + ${XGRAPH_FORWARD_CMAKE_ARGS} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + ) +endif() +message(STATUS "XGRAPH_FORWARD_CMAKE_ARGS ${XGRAPH_FORWARD_CMAKE_ARGS}") + +#----------------------------------------------------------------------------------------------- +# Installation logic... +#----------------------------------------------------------------------------------------------- + +if (LINUX) + include(GNUInstallDirs) +else() + set(CMAKE_INSTALL_BINDIR "bin") + set(CMAKE_INSTALL_INCLUDEDIR "include") + set(CMAKE_INSTALL_DOCDIR "doc") + set(CMAKE_INSTALL_LIBDIR "lib") +endif() + +message(STATUS "Installation directory: ${CMAKE_INSTALL_PREFIX}") + +# Destinations +if (LINUX) + if (DEFINED XGRAPH_RPATH) + set(CMAKE_BUILD_RPATH "$ORIGIN:${NGRAPH_RPATH}") + set(CMAKE_INSTALL_RPATH "$ORIGIN:${NGRAPH_RPATH}") + else() + set(CMAKE_BUILD_RPATH "$ORIGIN") + set(CMAKE_INSTALL_RPATH "$ORIGIN") + endif() +endif() + +#----------------------------------------------------------------------------------------------- +# External projects install directory +#----------------------------------------------------------------------------------------------- + +if (NOT XGRAPH_BUILD_BASE_DIR) + set(XGRAPH_BUILD_BASE_DIR ${PROJECT_BINARY_DIR}) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${XGRAPH_BUILD_BASE_DIR}) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${NGRAPH_BUILD_DIR}) + set(CMAKE_PDB_OUTPUT_DIRECTORY ${NGRAPH_BUILD_DIR}) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${NGRAPH_BUILD_DIR}) +endif() + +#----------------------------------------------------------------------------------------------- +# Compile Flags for xGraph... +#----------------------------------------------------------------------------------------------- + +# Since UNIX support Bash we can use a Bash script to do the clang-format functions +# This is much faster than the cmake method +set(FORMAT_DIRS + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/test +) +if (UNIX) + add_custom_target(style-check + COMMAND + ${NGRAPH_BASE_DIR}/maint/check-code-format.sh ${FORMAT_DIRS} + ) + add_custom_target(style-apply + COMMAND + ${NGRAPH_BASE_DIR}/maint/apply-code-format.sh ${FORMAT_DIRS} + ) + add_custom_target(style + COMMAND + ${NGRAPH_BASE_DIR}/maint/apply-code-format.sh ${FORMAT_DIRS} + ) +else() + add_custom_target(style-check + COMMAND ${CMAKE_COMMAND} + -DNGRAPH_SOURCE_DIR="${PROJECT_SOURCE_DIR}" + -P ${NGRAPH_BASE_DIR}/cmake/Modules/style_check.cmake + ) + + add_custom_target(style-apply + COMMAND ${CMAKE_COMMAND} + -DNGRAPH_SOURCE_DIR="${PROJECT_SOURCE_DIR}" + -P ${NGRAPH_BASE_DIR}/cmake/Modules/style_apply.cmake + ) + + add_custom_target(style + COMMAND ${CMAKE_COMMAND} + -DNGRAPH_SOURCE_DIR="${PROJECT_SOURCE_DIR}" + -P ${NGRAPH_BASE_DIR}/cmake/Modules/style_apply.cmake + ) +endif() + +add_custom_target(fix-mode + COMMAND ${CMAKE_COMMAND} + -DNGRAPH_SOURCE_DIR="${PROJECT_SOURCE_DIR}" + -P ${NGRAPH_BBSE_DIR}/cmake/Modules/fix_mode.cmake +) + +#----------------------------------------------------------------------------------------------- +# enable or disable output from XGRAPH_DEBUG statements +#----------------------------------------------------------------------------------------------- +if(XGRAPH_DEBUG_ENABLE) + add_definitions(-DXGRAPH_DEBUG_ENABLE) +endif() + +#----------------------------------------------------------------------------------------------- +# enable or disable deprecation warnings for old APIs +#----------------------------------------------------------------------------------------------- +if(XGRAPH_DEPRECATED_ENABLE) + add_definitions(-DXGRAPH_DEPRECATED_ENABLE) +endif() + +add_definitions(-DPROJECT_ROOT_DIR="${PROJECT_SOURCE_DIR}") + +#----------------------------------------------------------------------------------------------- +# Print Global Options +#----------------------------------------------------------------------------------------------- +get_directory_property(XGRAPH_COMPILE_OPTIONS COMPILE_OPTIONS) +message(STATUS "Compile Flags: ${NGRAPH_COMPILE_OPTIONS}") +message(STATUS "Shared Link Flags: ${CMAKE_SHARED_LINKER_FLAGS}") +message(STATUS "CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}") +message(STATUS "CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}") +message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") +message(STATUS "CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL}") + +#----------------------------------------------------------------------------------------------- +# xGraph source tree +#----------------------------------------------------------------------------------------------- + +add_subdirectory(src) + +add_subdirectory(test) + +#----------------------------------------------------------------------------------------------- +# Export Config and Install +#----------------------------------------------------------------------------------------------- + +# Not supported for now. +return() + +include(CMakePackageConfigHelpers) + +export(TARGETS xgraph NAMESPACE xgraph:: FILE "${PROJECT_BINARY_DIR}/xgraphTargets.cmake") + +install(EXPORT xgraphTargets + FILE xgraphTargets.cmake + NAMESPACE xgraph:: + DESTINATION ${NGRAPH_COMPONENT_PREFIX}cmake + COMPONENT xgraph) + +configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/share/xgraphConfig.cmake.in + ${PROJECT_BINARY_DIR}/ngraphConfig.cmake + INSTALL_DESTINATION cmake) + +write_basic_package_version_file(${PROJECT_BINARY_DIR}/xgraphConfigVersion.cmake + VERSION ${XGRAPH_VERSION} + COMPATIBILITY SameMajorVersion) + +install(FILES ${PROJECT_BINARY_DIR}/ngraphConfig.cmake + ${PROJECT_BINARY_DIR}/ngraphConfigVersion.cmake + DESTINATION ${NGRAPH_COMPONENT_PREFIX}cmake + COMPONENT xgraph) + +install(DIRECTORY + ${PROJECT_SOURCE_DIR}/licenses + DESTINATION "${NGRAPH_COMPONENT_PREFIX}." + COMPONENT xgraph +) + +install(FILES ${PROJECT_SOURCE_DIR}/LICENSE DESTINATION "${XGRAPH_COMPONENT_PREFIX}." COMPONENT xgraph) +install(FILES ${PROJECT_BINARY_DIR}/VERSION DESTINATION "${XGRAPH_COMPONENT_PREFIX}." COMPONENT xgraph) diff --git a/contrib/xgraph/src/CMakeLists.txt b/contrib/xgraph/src/CMakeLists.txt new file mode 100644 index 00000000000..c17a2425882 --- /dev/null +++ b/contrib/xgraph/src/CMakeLists.txt @@ -0,0 +1,17 @@ +# ****************************************************************************** +# Copyright 2017-2020 Intel Corporation +# +# Licensed 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. +# ****************************************************************************** + +return() diff --git a/contrib/xgraph/test/CMakeLists.txt b/contrib/xgraph/test/CMakeLists.txt new file mode 100644 index 00000000000..c17a2425882 --- /dev/null +++ b/contrib/xgraph/test/CMakeLists.txt @@ -0,0 +1,17 @@ +# ****************************************************************************** +# Copyright 2017-2020 Intel Corporation +# +# Licensed 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. +# ****************************************************************************** + +return() From ae15070a66e620868615545e831ca9f09461775f Mon Sep 17 00:00:00 2001 From: Sang Ik Lee Date: Wed, 26 Aug 2020 17:21:44 -0700 Subject: [PATCH 5/7] Rename project to gfx (Graph for X(Ten)-sor) --- contrib/{xgraph => gfx}/CMakeLists.txt | 72 +++++++++---------- contrib/{xgraph => gfx}/design_doc/graph.txt | 0 contrib/{xgraph => gfx}/design_doc/oplist.txt | 0 contrib/{xgraph => gfx}/src/CMakeLists.txt | 0 contrib/{xgraph => gfx}/test/CMakeLists.txt | 0 5 files changed, 36 insertions(+), 36 deletions(-) rename contrib/{xgraph => gfx}/CMakeLists.txt (85%) rename contrib/{xgraph => gfx}/design_doc/graph.txt (100%) rename contrib/{xgraph => gfx}/design_doc/oplist.txt (100%) rename contrib/{xgraph => gfx}/src/CMakeLists.txt (100%) rename contrib/{xgraph => gfx}/test/CMakeLists.txt (100%) diff --git a/contrib/xgraph/CMakeLists.txt b/contrib/gfx/CMakeLists.txt similarity index 85% rename from contrib/xgraph/CMakeLists.txt rename to contrib/gfx/CMakeLists.txt index b17fa9652cb..4c28926e72b 100644 --- a/contrib/xgraph/CMakeLists.txt +++ b/contrib/gfx/CMakeLists.txt @@ -21,8 +21,8 @@ message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") # set directory where the custom finders live set(NGRAPH_BASE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${NGRAPH_BASE_DIR}/cmake/Modules/") -get_property(XGRAPH_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -if(NOT XGRAPH_GENERATOR_IS_MULTI_CONFIG) +get_property(GFX_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(NOT GFX_GENERATOR_IS_MULTI_CONFIG) if (CMAKE_BUILD_TYPE) set(RELEASE_TYPES Debug Release RelWithDebInfo MinSizeRel) list(FIND RELEASE_TYPES ${CMAKE_BUILD_TYPE} INDEX_FOUND) @@ -85,15 +85,15 @@ if (APPLE) endif() endif() -project (xgraph) +project (gfx LANGUAGES CXX VERSION 10.0.0) # Tells if ngraph source tree is embedded in some other project # TRUE if embedded in source tree # FALSE if used standalone or as an external project if(NOT ("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")) - set(XGRAPH_IS_EMBEDDED TRUE) + set(GFX_IS_EMBEDDED TRUE) else() - set(XGRAPH_IS_EMBEDDED FALSE) + set(GFX_IS_EMBEDDED FALSE) endif() if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) @@ -104,10 +104,10 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/local" CACHE PATH "..." FORCE) endif() -set(XGRAPH_CXX_STANDARD 17) +set(GFX_CXX_STANDARD 17) if(CMAKE_CXX_STANDARD) - if(CMAKE_CXX_STANDARD VERSIONLESS XGRAPH_CXX_STANDARD) - message(FATAL_ERROR "CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD} is lower than ${XGRAPH_CXX_STANDARD}.") + if(CMAKE_CXX_STANDARD VERSIONLESS GFX_CXX_STANDARD) + message(FATAL_ERROR "CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD} is lower than ${GFX_CXX_STANDARD}.") endif() endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -119,7 +119,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Setup CMAKE_ARGS to be forwarded to External Projects -set(XGRAPH_FORWARD_CMAKE_ARGS +set(GFX_FORWARD_CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} @@ -130,23 +130,23 @@ set(XGRAPH_FORWARD_CMAKE_ARGS ) if (CMAKE_OSX_SYSROOT) - set(XGRAPH_FORWARD_CMAKE_ARGS + set(GFX_FORWARD_CMAKE_ARGS ${NGRAPH_FORWARD_CMAKE_ARGS} -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} ) endif() -if (NOT XGRAPH_GENERATOR_IS_MULTI_CONFIG) +if (NOT GFX_GENERATOR_IS_MULTI_CONFIG) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type" FORCE) endif() - set(XGRAPH_FORWARD_CMAKE_ARGS - ${XGRAPH_FORWARD_CMAKE_ARGS} + set(GFX_FORWARD_CMAKE_ARGS + ${GFX_FORWARD_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ) endif() -message(STATUS "XGRAPH_FORWARD_CMAKE_ARGS ${XGRAPH_FORWARD_CMAKE_ARGS}") +message(STATUS "GFX_FORWARD_CMAKE_ARGS ${GFX_FORWARD_CMAKE_ARGS}") #----------------------------------------------------------------------------------------------- # Installation logic... @@ -165,7 +165,7 @@ message(STATUS "Installation directory: ${CMAKE_INSTALL_PREFIX}") # Destinations if (LINUX) - if (DEFINED XGRAPH_RPATH) + if (DEFINED GFX_RPATH) set(CMAKE_BUILD_RPATH "$ORIGIN:${NGRAPH_RPATH}") set(CMAKE_INSTALL_RPATH "$ORIGIN:${NGRAPH_RPATH}") else() @@ -178,9 +178,9 @@ endif() # External projects install directory #----------------------------------------------------------------------------------------------- -if (NOT XGRAPH_BUILD_BASE_DIR) - set(XGRAPH_BUILD_BASE_DIR ${PROJECT_BINARY_DIR}) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${XGRAPH_BUILD_BASE_DIR}) +if (NOT GFX_BUILD_BASE_DIR) + set(GFX_BUILD_BASE_DIR ${PROJECT_BINARY_DIR}) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${GFX_BUILD_BASE_DIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${NGRAPH_BUILD_DIR}) set(CMAKE_PDB_OUTPUT_DIRECTORY ${NGRAPH_BUILD_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${NGRAPH_BUILD_DIR}) @@ -236,17 +236,17 @@ add_custom_target(fix-mode ) #----------------------------------------------------------------------------------------------- -# enable or disable output from XGRAPH_DEBUG statements +# enable or disable output from GFX_DEBUG statements #----------------------------------------------------------------------------------------------- -if(XGRAPH_DEBUG_ENABLE) - add_definitions(-DXGRAPH_DEBUG_ENABLE) +if(GFX_DEBUG_ENABLE) + add_definitions(-DGFX_DEBUG_ENABLE) endif() #----------------------------------------------------------------------------------------------- # enable or disable deprecation warnings for old APIs #----------------------------------------------------------------------------------------------- -if(XGRAPH_DEPRECATED_ENABLE) - add_definitions(-DXGRAPH_DEPRECATED_ENABLE) +if(GFX_DEPRECATED_ENABLE) + add_definitions(-DGFX_DEPRECATED_ENABLE) endif() add_definitions(-DPROJECT_ROOT_DIR="${PROJECT_SOURCE_DIR}") @@ -254,7 +254,7 @@ add_definitions(-DPROJECT_ROOT_DIR="${PROJECT_SOURCE_DIR}") #----------------------------------------------------------------------------------------------- # Print Global Options #----------------------------------------------------------------------------------------------- -get_directory_property(XGRAPH_COMPILE_OPTIONS COMPILE_OPTIONS) +get_directory_property(GFX_COMPILE_OPTIONS COMPILE_OPTIONS) message(STATUS "Compile Flags: ${NGRAPH_COMPILE_OPTIONS}") message(STATUS "Shared Link Flags: ${CMAKE_SHARED_LINKER_FLAGS}") message(STATUS "CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}") @@ -279,32 +279,32 @@ return() include(CMakePackageConfigHelpers) -export(TARGETS xgraph NAMESPACE xgraph:: FILE "${PROJECT_BINARY_DIR}/xgraphTargets.cmake") +export(TARGETS gfx NAMESPACE gfx:: FILE "${PROJECT_BINARY_DIR}/gfxTargets.cmake") -install(EXPORT xgraphTargets - FILE xgraphTargets.cmake - NAMESPACE xgraph:: +install(EXPORT gfxTargets + FILE gfxTargets.cmake + NAMESPACE gfx:: DESTINATION ${NGRAPH_COMPONENT_PREFIX}cmake - COMPONENT xgraph) + COMPONENT gfx) -configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/share/xgraphConfig.cmake.in +configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/share/gfxConfig.cmake.in ${PROJECT_BINARY_DIR}/ngraphConfig.cmake INSTALL_DESTINATION cmake) -write_basic_package_version_file(${PROJECT_BINARY_DIR}/xgraphConfigVersion.cmake - VERSION ${XGRAPH_VERSION} +write_basic_package_version_file(${PROJECT_BINARY_DIR}/gfxConfigVersion.cmake + VERSION ${GFX_VERSION} COMPATIBILITY SameMajorVersion) install(FILES ${PROJECT_BINARY_DIR}/ngraphConfig.cmake ${PROJECT_BINARY_DIR}/ngraphConfigVersion.cmake DESTINATION ${NGRAPH_COMPONENT_PREFIX}cmake - COMPONENT xgraph) + COMPONENT gfx) install(DIRECTORY ${PROJECT_SOURCE_DIR}/licenses DESTINATION "${NGRAPH_COMPONENT_PREFIX}." - COMPONENT xgraph + COMPONENT gfx ) -install(FILES ${PROJECT_SOURCE_DIR}/LICENSE DESTINATION "${XGRAPH_COMPONENT_PREFIX}." COMPONENT xgraph) -install(FILES ${PROJECT_BINARY_DIR}/VERSION DESTINATION "${XGRAPH_COMPONENT_PREFIX}." COMPONENT xgraph) +install(FILES ${PROJECT_SOURCE_DIR}/LICENSE DESTINATION "${GFX_COMPONENT_PREFIX}." COMPONENT gfx) +install(FILES ${PROJECT_BINARY_DIR}/VERSION DESTINATION "${GFX_COMPONENT_PREFIX}." COMPONENT gfx) diff --git a/contrib/xgraph/design_doc/graph.txt b/contrib/gfx/design_doc/graph.txt similarity index 100% rename from contrib/xgraph/design_doc/graph.txt rename to contrib/gfx/design_doc/graph.txt diff --git a/contrib/xgraph/design_doc/oplist.txt b/contrib/gfx/design_doc/oplist.txt similarity index 100% rename from contrib/xgraph/design_doc/oplist.txt rename to contrib/gfx/design_doc/oplist.txt diff --git a/contrib/xgraph/src/CMakeLists.txt b/contrib/gfx/src/CMakeLists.txt similarity index 100% rename from contrib/xgraph/src/CMakeLists.txt rename to contrib/gfx/src/CMakeLists.txt diff --git a/contrib/xgraph/test/CMakeLists.txt b/contrib/gfx/test/CMakeLists.txt similarity index 100% rename from contrib/xgraph/test/CMakeLists.txt rename to contrib/gfx/test/CMakeLists.txt From 0da3c03fff663b2d1b594ad2b5f4ebdb27023376 Mon Sep 17 00:00:00 2001 From: Sang Ik Lee Date: Wed, 2 Sep 2020 20:16:53 -0700 Subject: [PATCH 6/7] Temp. --- contrib/gfx/design_doc/graph.txt | 55 +++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/contrib/gfx/design_doc/graph.txt b/contrib/gfx/design_doc/graph.txt index 60c5cf1b03d..9c41097fe20 100644 --- a/contrib/gfx/design_doc/graph.txt +++ b/contrib/gfx/design_doc/graph.txt @@ -1,13 +1,33 @@ -Device: abstraction for a entity that has storage and compute capability +What is represented by GFX? +Roughly mathematical equations and functions expressed by flow graph of primitives. +Primitives maybe type insensitive but some are tied to a catagory of types (For example, boolean). +Different level of device independent abstractions can be represented with the following. +Analysis, transformation and optimization can happen at different level of abstraction. +Level 0: Unbounded primitives with static attributes +Level 1: Input Tensor shape and element type (not for every node) can be applied to make the flow graph more specific. +Still there is no concept of variables or memory yet and targeting an abbstract device. +Level 2: Shape and element types are inferred for all nodes (if they are not value dependent). +Device specific abstraction can branch off from any of the above levels. + + + +Device +Definition: abstraction for a entity that has storage and compute capability A default device must exist. Every device must provide a to_host method that moves value from device to host and a from_host method that moves a value from host to device. -Value: an entity that is device independent + +Value +Definition: an entity that is device independent Value is opaque and can only be accessed with to_plain method -This enables lazy evaluation as Value can actually be a built up higher other function that produces an entity. +This enables lazy evaluation as Value can actually be a built up as a higher order function that produces an entity. +Value is wrapper that is applied to node and binds inputs to the node. +Value : Tensor +Value : (Value)* -> Node -Node: node is an entity that can have zero or more runtime inputs and produces 1 or 2 runtime output (that may feed in to many nodes.) -First output is a special output (Output 0) that represents signal +Node +Definition: node is an entity that can have zero or more runtime inputs and produces 1 or 2 runtime output (that may feed in to many nodes.) +First output is a special output (Output 0) that represents signal for state change. Node are like math functions except that zero input is allowed and has a special output in addition to zero or more output. Node can have static attributes. @@ -43,3 +63,28 @@ Graph execution: - Lazy - Multi device - Hetro device + +Shape: +How does output shape of value change? +Padding - changes dim by counts (add subtract) +Windowed operation - Decides rank and dim through output iterator +Reduction - - Changes dim by factors (multiply) +Contraction - Inner product, changes rank +Select - Changes rank and dim + +How does input shape of value change? +Auto broadcasting - tensor data does not need to change. rank, dim and stride needs to be updated. + +Shape inference: +1. input shape inference: needed for auto broadcasting (done by either stride/rank update or physical broadcast). +2. output shape inference: needed for output (device) memory allocation. + +Eager Evaluation(Simple Interpreter): +Simple kernels - Does not handle complex stride, physical broadcast is needed, blocked format is not supported. +Input shape infererence, output shape inference, dispatch kernel. + +Lazy Evaluation +Input shape inference, output shape inference, forward futures. +Futures eval (explicit read/write request) triggers memory allocation and actual execution. + +Device memory allocation From 348a5868fd7f31c2912a3c25086dce7bd35aca9c Mon Sep 17 00:00:00 2001 From: Sang Ik Lee Date: Mon, 14 Sep 2020 11:04:34 -0700 Subject: [PATCH 7/7] update. --- contrib/gfx/design_doc/cpu_backend.txt | 6 +++++ contrib/gfx/design_doc/graph.txt | 31 +++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 contrib/gfx/design_doc/cpu_backend.txt diff --git a/contrib/gfx/design_doc/cpu_backend.txt b/contrib/gfx/design_doc/cpu_backend.txt new file mode 100644 index 00000000000..2250c6efe58 --- /dev/null +++ b/contrib/gfx/design_doc/cpu_backend.txt @@ -0,0 +1,6 @@ +Execution model: +Multi-Thread + Vectorization +Don't use OpenMP +Parallel For +Process affinity support +Data parallelism across NUMA diff --git a/contrib/gfx/design_doc/graph.txt b/contrib/gfx/design_doc/graph.txt index 9c41097fe20..cf46b6ca944 100644 --- a/contrib/gfx/design_doc/graph.txt +++ b/contrib/gfx/design_doc/graph.txt @@ -1,20 +1,41 @@ +What is GFX? +(Intentionally?) Ambigous acronym for now +Graph for X(Ten)-sor +Graph for XPU +Graph for Xe-graphics +Graph for X (Unknown hardware) +GFX is design from scratch that applies learnings from nGraph and addresses its shortfalls. + +Common mistakes +Model is declared (not in eager or imperative interpreted language) +Shapes are declared in the model (Not all frameworks are simple interpreter reading from descrptions files - or a self hosting runtime. In fact the most popular ones today are just libraries hosted in host language with dynamic types.) +Framework provides a way to capture model. That is not true unless. 1) host language/runtime creates an AST/trace for you, 2) FW library has a way to capture trace or freeze model (with python decorators) 3) backend somehow does lazy evaluation (maybe not too different from 1) +Lacking device capability checking. Not providing fallbacks for all shapes. Most ops are support limited shapes and to make it worse what shapes are supported depends on the backend. +No way to construct a shapeless/unbounded graph +No dynamic shape eager evaluation method provided. +One size fits all single solution - importer, optimizer, backend, runtime all lumped together. LLVM like reusable library would be much better. +Need holder/proxy ops for unknown or unsupported ops to capture data and control dependencies. + +Resnet-50 + What is represented by GFX? Roughly mathematical equations and functions expressed by flow graph of primitives. Primitives maybe type insensitive but some are tied to a catagory of types (For example, boolean). Different level of device independent abstractions can be represented with the following. Analysis, transformation and optimization can happen at different level of abstraction. -Level 0: Unbounded primitives with static attributes -Level 1: Input Tensor shape and element type (not for every node) can be applied to make the flow graph more specific. +Level 0: Unbounded primitives with static attributes - math function API in dynamic typed language +Level 1: Input Tensor shape and element type (not for every node) can be applied to make the flow graph more specific. - like math library API in C Still there is no concept of variables or memory yet and targeting an abbstract device. -Level 2: Shape and element types are inferred for all nodes (if they are not value dependent). +Level 2: Shape and element types are inferred for all nodes (if they are not value dependent). - like individual API in C Device specific abstraction can branch off from any of the above levels. - +So far the representation is not tied to a specific device. Device Definition: abstraction for a entity that has storage and compute capability A default device must exist. -Every device must provide a to_host method that moves value from device to host and a from_host method that moves a value from host to device. +Every device must provide explicit API for data movement. +A to_host method that moves value from device to host and a from_host method that moves a value from host to device. Value