You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/02/10 23:34:45 UTC

[GitHub] [tvm] kparzysz-quic commented on a change in pull request #10217: Adding support for Hexagon User DMA Engine

kparzysz-quic commented on a change in pull request #10217:
URL: https://github.com/apache/tvm/pull/10217#discussion_r804218964



##########
File path: src/runtime/hexagon/hexagon/hexagon_user_dma_descriptors.h
##########
@@ -0,0 +1,310 @@
+/*
+ * 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.
+ */
+
+#ifndef TVM_RUNTIME_HEXAGON_HEXAGON_HEXAGON_USER_DMA_DESCRIPTORS_H_
+#define TVM_RUNTIME_HEXAGON_HEXAGON_HEXAGON_USER_DMA_DESCRIPTORS_H_
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+// NOTE: Using 2D descriptor size even for 1D descriptors
+#define DMA_DESC_2D_SIZE 32
+
+// TODO(Straw): DMA Status [0][3:0]?
+
+// desc[0][31:4]
+// Descriptors addresses must be (minimum) 16 byte aligned
+// -> Lower 4 bits masked to clear DMA Status
+// -> But, descriptor address is not shifted
+#define DESC_NEXT_MASK 0xFFFFFFF0
+#define DESC_NEXT_SHIFT 0
+
+// desc[1][23:0]
+#define DESC_LENGTH_MASK 0x00FFFFFF
+#define DESC_LENGTH_SHIFT 0
+
+// desc[1][25:24]
+#define DESC_DESCTYPE_MASK 0x03000000
+#define DESC_DESCTYPE_SHIFT 24
+#define DESC_DESCTYPE_1D 0
+#define DESC_DESCTYPE_2D 1
+
+// TODO(Straw): Definition?  Not in the spec.
+// desc[1][26]
+#define DESC_DSTCOMP_MASK 0x04000000
+#define DESC_DSTCOMP_SHIFT 26
+// desc[1][27]
+#define DESC_SRCCOMP_MASK 0x08000000
+#define DESC_SRCCOMP_SHIFT 27
+#define DESC_COMP_NONE 0
+#define DESC_COMP_DLBC 1
+
+// desc[1][28]
+#define DESC_BYPASSDST_MASK 0x10000000
+#define DESC_BYPASSDST_SHIFT 28
+// desc[1][29]
+#define DESC_BYPASSSRC_MASK 0x20000000
+#define DESC_BYPASSSRC_SHIFT 29
+#define DESC_BYPASS_OFF 0
+#define DESC_BYPASS_ON 1
+
+// desc[1][30]
+#define DESC_ORDER_MASK 0x40000000
+#define DESC_ORDER_SHIFT 30
+#define DESC_ORDER_NOORDER 0
+#define DESC_ORDER_ORDER 1
+
+// desc[1][31]
+#define DESC_DSTATE_MASK 0x80000000
+#define DESC_DSTATE_SHIFT 31
+#define DESC_DSTATE_INCOMPLETE 0
+#define DESC_DSTATE_COMPLETE 1
+
+// desc[2]
+#define DESC_SRC_MASK 0xFFFFFFFF
+#define DESC_SRC_SHIFT 0
+
+// desc[3]
+#define DESC_DST_MASK 0xFFFFFFFF
+#define DESC_DST_SHIFT 0
+
+// desc[4][25:24]
+#define DESC_CACHEALLOC_MASK 0x03000000
+#define DESC_CACHEALLOC_SHIFT 24
+#define DESC_CACHEALLOC_NONE 0
+#define DESC_CACHEALLOC_WRITEONLY 1
+#define DESC_CACHEALLOC_READONLY 2
+#define DESC_CACHEALLOC_READWRITE 3
+
+// TODO(Straw): Definition?  Not in the spec.
+// desc[4][31:28]
+#define DESC_PADDING_MASK 0xF0000000
+#define DESC_PADDING_SHIFT 28
+
+// desc[5][15:0]
+#define DESC_ROIWIDTH_MASK 0x0000FFFF
+#define DESC_ROIWIDTH_SHIFT 0
+
+// desc[5][31:16]
+#define DESC_ROIHEIGHT_MASK 0xFFFF0000
+#define DESC_ROIHEIGHT_SHIFT 16
+
+// desc[6][15:0]
+#define DESC_SRCSTRIDE_MASK 0x0000FFFF
+#define DESC_SRCSTRIDE_SHIFT 0
+
+// desc[6][31:16]
+#define DESC_DSTSTRIDE_MASK 0xFFFF0000
+#define DESC_DSTSTRIDE_SHIFT 16
+
+// desc[7][15:0]
+#define DESC_SRCWIDTHOFFSET_MASK 0x0000FFFF
+#define DESC_SRCWIDTHOFFSET_SHIFT 0
+
+// desc[7][31:16]
+#define DESC_DSTWIDTHOFFSET_MASK 0xFFFF0000
+#define DESC_DSTWIDTHOFFSET_SHIFT 16
+
+#define DMA_SUCCESS 0
+#define DMA_FAILURE -1
+#define DMA_NULL_PTR 0
+
+/**************************/
+/* 1D (linear) descriptor */
+/**************************/
+typedef struct _dma_desc_1d_t {

Review comment:
       This is a C++ header, (1) please don't use `typedef` at all (use `using` instead), and (2) don't use either with classes.

##########
File path: src/runtime/hexagon/hexagon/hexagon_user_dma.cc
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+
+#include <algorithm>
+
+#include "hexagon_common.h"
+#include "hexagon_user_dma_descriptors.h"
+#include "hexagon_user_dma_instructions.h"
+#include "hexagon_user_dma_registers.h"
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+int hexagon_user_dma_1d_sync(void* dst, void* src, uint32_t length) {
+#if defined(__hexagon__)
+  // not thread safe
+  static int config_dma = 0;

Review comment:
       Extract the DMA config code below into a separate function returning int, and change this declaration to `static int config_dma = initialization_function();`  This will make it thread-safe.

##########
File path: src/runtime/hexagon/hexagon/hexagon_user_dma_instructions.h
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#ifndef TVM_RUNTIME_HEXAGON_HEXAGON_HEXAGON_USER_DMA_INSTRUCTIONS_H_
+#define TVM_RUNTIME_HEXAGON_HEXAGON_HEXAGON_USER_DMA_INSTRUCTIONS_H_
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+inline unsigned int dmpause() {
+  unsigned int dm0 = 0;
+  asm volatile(" %0 = dmpause" : "=r"(dm0));
+  return dm0;
+}
+
+inline void dmstart(void* next) { asm volatile(" dmstart(%0)" : : "r"(next)); }
+
+inline unsigned int dmpoll() {
+  unsigned int dm0 = 0;
+  asm volatile(" %0 = dmpoll" : "=r"(dm0));
+  return dm0;
+}
+
+inline unsigned int dmwait() {
+  unsigned int dm0 = 0;
+  asm volatile(" %0 = dmwait" : "=r"(dm0));
+  return dm0;
+}
+
+inline void dmresume(unsigned int dm0) { asm volatile(" dmresume(%0)" : : "r"(dm0)); }
+
+static inline unsigned int dmsyncht() {

Review comment:
       Why are some functions here `inline` while others are `static inline`?




-- 
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-unsubscribe@tvm.apache.org

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