[GitHub] [tvm] srkreddy1238 commented on a diff in pull request #13837: [CLML][CODEGEN] CLML native codegen utility

2023-02-02 Thread via GitHub


srkreddy1238 commented on code in PR #13837:
URL: https://github.com/apache/tvm/pull/13837#discussion_r1094213482


##
apps/cpp_clml/CMakeLists.txt:
##
@@ -0,0 +1,59 @@
+cmake_minimum_required(VERSION 3.13)
+
+project(clml_run VERSION 2.0)
+
+if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+  message( FATAL_ERROR "CMAKE_TOOLCHAIN_FILE Not set, forcing exit. Suggested 
value: {ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake." )
+endif(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+
+if(NOT DEFINED ANDROID_ABI)
+  message( FATAL_ERROR "ANDROID_ABI Not set, forcing exit. Suggested value(s): 
arm64-v8a (64), armeabi-v7a (32)" )
+endif(NOT DEFINED ANDROID_ABI)
+
+if(NOT DEFINED CLML_SDK)
+  message( FATAL_ERROR "CLML_SDK Not set, forcing exit." )
+endif(NOT DEFINED CLML_SDK)
+
+if (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY STREQUAL "ONLY")
+  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
+endif()
+
+find_library(CLML_LIBRARIES NAMES libOpenCL.so NO_DEFAULT_PATH PATHS 
${CLML_SDK}/lib ${CLML_SDK}/lib64)

Review Comment:
   CLML doesn't expose any .cmake and using tvm's ```find_opencl``` adds 
additional dependencies.
   I am trying to keep build instructions of this tool very similar to CLML SDK 
sample build.
   
   Also, given a proper download of clml_sdk it's guaranteed to have the OpenCL 
lib.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [tvm] srkreddy1238 commented on a diff in pull request #13837: [CLML][CODEGEN] CLML native codegen utility

2023-01-25 Thread via GitHub


srkreddy1238 commented on code in PR #13837:
URL: https://github.com/apache/tvm/pull/13837#discussion_r1086696357


##
apps/cpp_clml/CMakeLists.txt:
##
@@ -0,0 +1,57 @@
+cmake_minimum_required(VERSION 3.13)
+
+project(clml_run VERSION 2.0)
+
+if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+  message( FATAL_ERROR "CMAKE_TOOLCHAIN_FILE Not set, forcing exit. Suggested 
value: {ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake." )
+endif(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+
+if(NOT DEFINED ANDROID_ABI)
+  message( FATAL_ERROR "ANDROID_ABI Not set, forcing exit. Suggested value(s): 
arm64-v8a (64), armeabi-v7a (32)" )
+endif(NOT DEFINED ANDROID_ABI)
+
+if(NOT DEFINED CLML_SDK)
+  message( FATAL_ERROR "CLML_SDK Not set, forcing exit." )
+endif(NOT DEFINED CLML_SDK)
+
+# CMake/Android variables
+set( ANDROID_STL  c++_static CACHE STRING "Target Android STL") # default
+
+# Source variables
+set( OPENCL_INCLUDE_DIRS  ${CLML_SDK} CACHE PATH "filepath to OpenCL headers")
+set( ANDROID_SOURCE_TREE /path/to/android/au/ CACHE FILEPATH "optional 
filepath to the Android AU Tree, for building examples using ION Buffers") # 
tree required to build ION/DMA Buffer samples
+
+#c++ 11 is required
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
+# set(CMAKE_CXX_FLAGS "-Wall -Werror")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
+#we do not want to pass -fno-exceptions
+if(${CMAKE_CXX_FLAGS} MATCHES "-fno-exceptions")
+  string(REGEX REPLACE "-fno-exceptions" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+endif()
+
+#we do not want to pass -fno-rtti
+if(${CMAKE_CXX_FLAGS} MATCHES "-fno-rtti")
+  string(REGEX REPLACE "-fno-rtti" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+endif()
+
+set(COMMON_SOURCE_FILES
+clml_models.cc
+clml_runner.cc
+clml_runner.h
+main.cc
+../../3rdparty/cnpy/cnpy.cpp
+)
+
+include_directories(
+src
+${OPENCL_INCLUDE_DIRS}
+"../../3rdparty/dmlc-core/include"
+"../../3rdparty/cnpy/"
+)
+
+add_executable(clml_run ${COMMON_SOURCE_FILES})
+target_link_options(clml_run PRIVATE 
-Wl,--unresolved-symbols=ignore-in-shared-libs)
+target_link_libraries(clml_run ${CLML_SDK}/lib64/libOpenCL.so z)

Review Comment:
   Handled with  ```find_library``` 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [tvm] srkreddy1238 commented on a diff in pull request #13837: [CLML][CODEGEN] CLML native codegen utility

2023-01-25 Thread via GitHub


srkreddy1238 commented on code in PR #13837:
URL: https://github.com/apache/tvm/pull/13837#discussion_r1086679292


##
apps/cpp_clml/CMakeLists.txt:
##
@@ -0,0 +1,57 @@
+cmake_minimum_required(VERSION 3.13)
+
+project(clml_run VERSION 2.0)
+
+if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+  message( FATAL_ERROR "CMAKE_TOOLCHAIN_FILE Not set, forcing exit. Suggested 
value: {ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake." )
+endif(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+
+if(NOT DEFINED ANDROID_ABI)
+  message( FATAL_ERROR "ANDROID_ABI Not set, forcing exit. Suggested value(s): 
arm64-v8a (64), armeabi-v7a (32)" )
+endif(NOT DEFINED ANDROID_ABI)
+
+if(NOT DEFINED CLML_SDK)
+  message( FATAL_ERROR "CLML_SDK Not set, forcing exit." )
+endif(NOT DEFINED CLML_SDK)
+
+# CMake/Android variables
+set( ANDROID_STL  c++_static CACHE STRING "Target Android STL") # default
+
+# Source variables
+set( OPENCL_INCLUDE_DIRS  ${CLML_SDK} CACHE PATH "filepath to OpenCL headers")
+set( ANDROID_SOURCE_TREE /path/to/android/au/ CACHE FILEPATH "optional 
filepath to the Android AU Tree, for building examples using ION Buffers") # 
tree required to build ION/DMA Buffer samples
+
+#c++ 11 is required
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
+# set(CMAKE_CXX_FLAGS "-Wall -Werror")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
+#we do not want to pass -fno-exceptions
+if(${CMAKE_CXX_FLAGS} MATCHES "-fno-exceptions")
+  string(REGEX REPLACE "-fno-exceptions" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+endif()
+
+#we do not want to pass -fno-rtti
+if(${CMAKE_CXX_FLAGS} MATCHES "-fno-rtti")
+  string(REGEX REPLACE "-fno-rtti" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+endif()
+
+set(COMMON_SOURCE_FILES
+clml_models.cc
+clml_runner.cc
+clml_runner.h
+main.cc
+../../3rdparty/cnpy/cnpy.cpp
+)
+
+include_directories(
+src
+${OPENCL_INCLUDE_DIRS}
+"../../3rdparty/dmlc-core/include"
+"../../3rdparty/cnpy/"
+)
+
+add_executable(clml_run ${COMMON_SOURCE_FILES})
+target_link_options(clml_run PRIVATE 
-Wl,--unresolved-symbols=ignore-in-shared-libs)
+target_link_libraries(clml_run ${CLML_SDK}/lib64/libOpenCL.so z)

Review Comment:
   Works with with ```find_library```



##
apps/cpp_clml/CMakeLists.txt:
##
@@ -0,0 +1,57 @@
+cmake_minimum_required(VERSION 3.13)
+
+project(clml_run VERSION 2.0)
+
+if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+  message( FATAL_ERROR "CMAKE_TOOLCHAIN_FILE Not set, forcing exit. Suggested 
value: {ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake." )
+endif(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+
+if(NOT DEFINED ANDROID_ABI)
+  message( FATAL_ERROR "ANDROID_ABI Not set, forcing exit. Suggested value(s): 
arm64-v8a (64), armeabi-v7a (32)" )
+endif(NOT DEFINED ANDROID_ABI)
+
+if(NOT DEFINED CLML_SDK)
+  message( FATAL_ERROR "CLML_SDK Not set, forcing exit." )
+endif(NOT DEFINED CLML_SDK)
+
+# CMake/Android variables
+set( ANDROID_STL  c++_static CACHE STRING "Target Android STL") # default
+
+# Source variables
+set( OPENCL_INCLUDE_DIRS  ${CLML_SDK} CACHE PATH "filepath to OpenCL headers")
+set( ANDROID_SOURCE_TREE /path/to/android/au/ CACHE FILEPATH "optional 
filepath to the Android AU Tree, for building examples using ION Buffers") # 
tree required to build ION/DMA Buffer samples
+
+#c++ 11 is required
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
+# set(CMAKE_CXX_FLAGS "-Wall -Werror")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

Review Comment:
   Done



##
apps/cpp_clml/CMakeLists.txt:
##
@@ -0,0 +1,57 @@
+cmake_minimum_required(VERSION 3.13)
+
+project(clml_run VERSION 2.0)
+
+if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+  message( FATAL_ERROR "CMAKE_TOOLCHAIN_FILE Not set, forcing exit. Suggested 
value: {ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake." )
+endif(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+
+if(NOT DEFINED ANDROID_ABI)
+  message( FATAL_ERROR "ANDROID_ABI Not set, forcing exit. Suggested value(s): 
arm64-v8a (64), armeabi-v7a (32)" )
+endif(NOT DEFINED ANDROID_ABI)
+
+if(NOT DEFINED CLML_SDK)
+  message( FATAL_ERROR "CLML_SDK Not set, forcing exit." )
+endif(NOT DEFINED CLML_SDK)
+
+# CMake/Android variables
+set( ANDROID_STL  c++_static CACHE STRING "Target Android STL") # default
+
+# Source variables
+set( OPENCL_INCLUDE_DIRS  ${CLML_SDK} CACHE PATH "filepath to OpenCL headers")
+set( ANDROID_SOURCE_TREE /path/to/android/au/ CACHE FILEPATH "optional 
filepath to the Android AU Tree, for building examples using ION Buffers") # 
tree required to build ION/DMA Buffer samples
+
+#c++ 11 is required
+set(CMAKE_CXX_STANDARD 11)

Review Comment:
   done



##
python/tvm/relay/op/contrib/clml.py:
##
@@ -387,3 +393,769 @@ def __exit__(self, ptype, value, trace):
 self.op.reset_attr(self.attr_key)
 if self.older_attr:
 self.op.set_attr(self.attr_key, self.older_attr)
+
+
+class 

[GitHub] [tvm] srkreddy1238 commented on a diff in pull request #13837: [CLML][CODEGEN] CLML native codegen utility

2023-01-25 Thread via GitHub


srkreddy1238 commented on code in PR #13837:
URL: https://github.com/apache/tvm/pull/13837#discussion_r1086400714


##
python/tvm/relay/op/contrib/clml.py:
##
@@ -387,3 +393,769 @@ def __exit__(self, ptype, value, trace):
 self.op.reset_attr(self.attr_key)
 if self.older_attr:
 self.op.set_attr(self.attr_key, self.older_attr)
+
+
+class CLMLGetSubModuleSrc:
+"""Generates CLML API one CLML sub module out ot global TVM module"""
+
+def __init__(self, cmod):
+"""Initialize
+Parameters
+--
+cmod : Module
+The CLML sub module from TVM module
+"""
+self.cmod = cmod
+self.codegen = None
+self.nodes = None
+self.node_map = {}
+self.input_meta = []
+self.output_meta = []
+self.clml_code = []
+self.sub_module_name = None
+
+self.MakeCLMLTensor = Template(
+"""auto $name = runner.MakeCLMLTensor
+(std::vector({$shape}), "$dtype", $layout);"""
+)
+self.MapInsert = Template("""runner.storage_map.insert({"$nid", 
$tensor_desc});""")
+self.MakeConv2D = Template(
+"""
+// Convolution / Depthwise Convolution
+runner.MakeConv2D($input_tensor,
+   $weight_tensor,
+   $bias_tensor,
+   $output_tensor,
+   std::vector({$padding}),
+   std::vector({$dilation}),
+   std::vector({$strides}),
+   $groups,
+   $mode,
+   $activation,
+   $has_bias,
+   $has_act,
+   "$dtype");"""
+)
+self.MakeConv2DWithBN = Template(
+"""
+// Batchnorm
+runner.MakeConv2DWithBN($input_tensor,
+ $weight_tensor,
+ $bias_tensor,
+ $output_tensor,
+ $bn_scale_tensor,
+ $bn_bias_tensor,
+ $bn_mean_tensor,
+ $bn_var_tensor,
+ std::vector  ({$bn_attrs}),
+ std::vector ({$padding}),
+ std::vector ({$dilation}),
+ std::vector ({$strides}),
+ $groups,
+ $mode,
+ $activation,
+ $has_bias,
+ $has_act,
+ "$dtype");"""
+)
+self.MakeRelu = Template(
+"""
+// Relu / Relu6
+runner.MakeRelu($input_tensor, $output_tensor, $relu_type, "$dtype");
+"""
+)
+self.MakeBN = Template(
+"""
+// Batchnorm
+runner.MakeBatchNorm($input_tensor,
+  $output_tensor,
+  $bn_scale_tensor,
+  $bn_bias_tensor,
+  $bn_mean_tensor,
+  $bn_var_tensor,
+  std::vector ({$bn_attrs}), "$dtype");"""
+)
+self.MakePool2D = Template(
+"""
+// Pool2D
+runner.MakePool2D($input_tensor,
+   $output_tensor,
+   std::vector ({$pool_size}),
+   std::vector ({$strides}),
+   std::vector ({$padding}),
+   "$pool_type", "$dtype");"""
+)
+self.MakeGlobalPool2D = Template(
+"""
+// GlobalPool2D
+runner.MakeGlobalPool2D($input_tensor,
+ $output_tensor,
+ std::vector ({$in_shape}),
+ "$pool_type", "$dtype");"""
+)
+self.MakeReshape = Template(
+"""
+// Reshape
+runner.MakeReshape($input_tensor,
+$output_tensor, "$dtype");"""
+)
+self.MakeConcatenate = Template(
+"""
+// Concatinate
+runner.MakeConcatenate(
+std::vector> 
({$in_list}),
+$output_tensor,
+$axis, "$dtype");"""
+)
+self.MakeDense = Template(
+"""
+// Dense
+runner.MakeDense($input_tensor,
+  $weight_tensor,
+  $output_tensor,
+  $bias_tensor, "$dtype");"""
+)
+self.MakeSoftMax = Template(
+"""
+// Softmax
+runner.MakeSoftMax($input_tensor,
+$output_tensor, "$dtype");"""
+)
+self.MakePad = Template(
+"""
+// Pad
+runner.MakePad($input_tensor,
+$output_tensor,
+"$pad_mode",
+std::vector ({$padding}), "$dtype");"""
+)
+self.MakeBatchFlatten = Template(
+"""
+// BatchFlatten
+runner.MakeBatchFlatten($input_tensor,
+ $output_tensor, "$dtype");"""
+)
+self.MakeClip = Template(
+"""
+// Clip
+runner.MakeClip($input_tensor,
+ $output_tensor,
+ $a_max,
+ $a_min,
+ "$dtype");"""
+)
+self.MakeBinaryOp = Template(
+"""
+// BinaryOp
+