您好,欢迎来到61ic! | [登录] [注册] 忘记密码 | 设为首页 帮助
 . 网站首页 . 业界新闻 . 设计中心 . 移动技术 . TI专栏 . ADI专栏 . FPGA专栏 . 代码工厂 . 官方商城 . 
 . 活动专区 . 新品快递 . 解决方案 . 前沿科技 . TI资源 . ADI资源 . FPGA资源 . 下载中心 . 产品展示 . 
加入收藏
付款方式
联系我们
您现在的位置: 61IC电子在线 >> TI专栏 >> TI C6000 DSP和ARM >> OMAP-L1x处理器 >> 正文
  TI ARM和DSP双核平台的一个编译例程           ★★★ 【字体:
TI ARM和DSP双核平台的一个编译例程
作者:wuyuwei4…    文章来源:wuyuwei45    点击数:    更新时间:2014-2-12    

一个适用于TI ARM与DSP双核平台的makefile。该makefile示意了如何同时编译出ARM平台和DSP平台的执行文件,以便于比较ARM核和DSP核在进行运算时表现出来的性能差异。

makefile

#############################################################################
# Makefile                                                                  #
#                                                                           #
# Builds the emqbit benchmark source for ARM and DSP                        #
#############################################################################
#
#
#############################################################################
#                                                                           #
#   Copyright (C) 2010 Texas Instruments Incorporated                       #
#     http://www.ti.com/                                                    #
#                                                                           #
#############################################################################
#
#
#############################################################################
#                                                                           #
#  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 Texas Instruments Incorporated 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.     #
#                                                                           #
#############################################################################

PROJNAME := matmult

#   ----------------------------------------------------------------------------
#   Name of the ARM GCC cross compiler
#   ----------------------------------------------------------------------------
ARM_TOOLCHAIN_PREFIX  ?= arm-none-linux-gnueabi-
ifdef ARM_TOOLCHAIN_PATH
ARM_CC := $(ARM_TOOLCHAIN_PATH)/bin/$(ARM_TOOLCHAIN_PREFIX)gcc
else
ARM_CC := $(ARM_TOOLCHAIN_PREFIX)gcc
endif

# Pick up any ARM compiler and linker flags from the environment
ARM_CFLAGS = $(CFLAGS)
ARM_CFLAGS += -std=gnu99 \
-Wdeclaration-after-statement -Wall -Wno-trigraphs \
-fno-strict-aliasing -fno-common -fno-omit-frame-pointer \
-c -O3
ARM_LDFLAGS = $(LDFLAGS)
ARM_LDFLAGS+=-lm


#   ----------------------------------------------------------------------------
#   Name of the DSP compiler
#   TI C6RunApp Frontend (if path variable provided, use it, otherwise assume
#   the tools are in the path)
#   ----------------------------------------------------------------------------
C6RUN_TOOLCHAIN_PREFIX=c6runapp-
ifdef C6RUN_TOOLCHAIN_PATH
C6RUN_CC := $(C6RUN_TOOLCHAIN_PATH)/bin/$(C6RUN_TOOLCHAIN_PREFIX)cc
else
C6RUN_CC := $(C6RUN_TOOLCHAIN_PREFIX)cc
endif

DSPLIB_PATH := $(HOME)/C64x+DSPLIB/dsplib_v210

C6RUN_CFLAGS = -c -O3 -I$(DSPLIB_PATH) -DUSE_DSPLIB
C6RUN_LDFLAGS=


#   ----------------------------------------------------------------------------
#   List of source files
#   ----------------------------------------------------------------------------
SRCS := $(PROJNAME).c
ARM_OBJS := $(SRCS:%.c=gpp/%.o)
DSP_OBJS := $(SRCS:%.c=dsp/%.o)

#   ----------------------------------------------------------------------------
#   Makefile targets
#   ----------------------------------------------------------------------------
.PHONY : dsp dsp_clean gpp gpp_clean all clean

all: dsp gpp
clean: dsp_clean gpp_clean

gpp: gpp/.created $(ARM_OBJS)
 $(ARM_CC) $(ARM_LDFLAGS) -o $(PROJNAME)_gpp $(ARM_OBJS)

gpp/%.o : %.c
 $(ARM_CC) $(ARM_CFLAGS) $(CINCLUDES) -o $@ $<

gpp/.created:
 @mkdir -p gpp
 @touch gpp/.created

gpp_clean:
 @rm -Rf $(PROJNAME)_gpp
 @rm -Rf gpp

dsp: dsp/.created $(DSP_OBJS)
 $(C6RUN_CC) $(C6RUN_LDFLAGS) -o $(PROJNAME)_dsp $(DSP_OBJS) $(DSPLIB_PATH)/dsplib64plus.lib

dsp/%.o : %.c
 $(C6RUN_CC) $(C6RUN_CFLAGS) $(CINCLUDES) -o $@ $<

dsp/.created:
 @mkdir -p dsp
 @touch dsp/.created

dsp_clean:
 @rm -Rf $(PROJNAME)_dsp
 @rm -Rf dsp

源文件:
matmult.c

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#ifdef USE_DSPLIB
  #include "src/DSP_mat_mul/DSP_mat_mul.h"
#endif

// Random matrix fill
void matfill(int size, short *mat)
{
  int i, j;
  for (i = 0; i < size; i++)
  {
    for (j = 0; j < size; j++)
    {
      mat[j+size*i] = (short) (rand() % 100);
    }
  }
}

void printmat(int size, short *mat)
{
}

// Matrix multiply using Fixed point C64x+ DSPLib function
void matmult(int size, int shift, short *A, short *B, short *C)
{
#ifdef USE_DSPLIB
  DSP_mat_mul( A,size,size,
               B,     size,
               C,
               shift );
#else
  int i, j, k;
  int sum;
  for (i = 0; i < size; i++)
  {
    for (j = 0; j < size; j++)
    {
      sum = 0;
      for (k = 0; k < size; k++)
      {
        sum += (A[i*size + k] * B[k*size  + j]);
      }
      C[i*size + j] = sum >> shift;
    }
  }
#endif
}

//square matrices only
int main(int argc, char *argv[])
{
  short *A, *B, *C;
  int matsize, shift;
  time_t t;

  if (argc != 2) exit(-1);

  matsize = atoi(argv[1]);
 
  shift = 0;
  while ((matsize>>shift) > 0)
  {
    ++shift;
  }
   
  srand(time(NULL)); 

  if (matsize == 0) exit(-1);

  // Allocate space for matrices
  A = calloc(matsize*matsize, sizeof(short));
  matfill(matsize, A);

  B = calloc(matsize*matsize, sizeof(short));
  matfill(matsize, B);
 
  C = calloc(matsize*matsize, sizeof(short));
 
  // Perform multiply and time it
  t = time(NULL);
  matmult(matsize, shift, A, B, C);
  t = time(NULL) - t;
  printf("time of multiply: %d seconds\n",(int)t);
 
  // Free allocated spaces
  free(A);
  free(B);
  free(C);
}

运行结果:

root@dm37x-evm:/opt# for i in 100 200 300 400 500 600; do ./matmult_gpp $i; done
time of multiply: 0 seconds                                                    
time of multiply: 0 seconds                                                    
time of multiply: 2 seconds                                                    
time of multiply: 6 seconds                                                    
time of multiply: 18 seconds                                                   
time of multiply: 39 seconds                                                   
root@dm37x-evm:/opt# for i in 100 200 300 400 500 600; do ./matmult_dsp $i; done

time of multiply: 0 seconds                                                    
time of multiply: 0 seconds                                                    
time of multiply: 0 seconds                                                    
time of multiply: 0 seconds                                                    
time of multiply: 1 seconds                                                    
time of multiply: 3 seconds 

可见当数据量大时,DSP表现出来的性能优越性更明显。

文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章: 没有了
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    TMS320C6000 C/C++运行时环境…
    TMS320C64x+ DSP------Using…
    TMS320C6000  DSP系列的视频…
    TMS320C6000™ DSP系列…
    《TMS320C6000系列DSPs的原理…
    TMS320C6000系列二次Bootloa…
    TMS320C6000系列带中断向量表…
    TMS320C6000系列DSP的Flash启…
    TMS320C6000嵌入式系统优化编…
    TMS320C6000与UART的通信
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    站长:61 湘ICP备13001086号-2