• OpenACC Hello World


    ▶ 在 windows 10 上搭建 OpenACC 环境

    ● 安装顺序:Visual Studio(PGI 18.04 不支持 VS 2017,PGI 19.04 已经支持到 VS 2019 啦!);CUDA Toolkite(https://developer.nvidia.com/cuda-downloads);PGI 编译器(https://www.pgroup.com/products/community.htm?*utm*_campaign=CE&utm_source=dev_nvidia_oacc&utm_medium=web_link&utm_term=*get_ce_text*)

    ● PGI 自带的 pgaccinfo.exe 抓取设备信息:

    CUDA Driver Version:           10010
    
    Device Number:                 0
    Device Name:                   GeForce GTX 1070
    Device Revision Number:        6.1
    Global Memory Size:            8589934592
    Number of Multiprocessors:     16
    Concurrent Copy and Execution: Yes
    Total Constant Memory:         65536
    Total Shared Memory per Block: 49152
    Registers per Block:           65536
    Warp Size:                     32
    Maximum Threads per Block:     1024
    Maximum Block Dimensions:      1024, 1024, 64
    Maximum Grid Dimensions:       2147483647 x 65535 x 65535
    Maximum Memory Pitch:          2147483647B
    Texture Alignment:             512B
    Clock Rate:                    1645 MHz
    Execution Timeout:             Yes
    Integrated Device:             No
    Can Map Host Memory:           Yes
    Compute Mode:                  default
    Concurrent Kernels:            Yes
    ECC Enabled:                   No
    Memory Clock Rate:             4004 MHz
    Memory Bus Width:              256 bits
    L2 Cache Size:                 2097152 bytes
    Max Threads Per SMP:           2048
    Async Engines:                 2
    Unified Addressing:            Yes
    Managed Memory:                Yes
    Concurrent Managed Memory:     No
    Preemption Supported:          Yes
    PGI Default Target:            -ta=tesla:cc60

    ● 编写代码

     1 #include <stdio.h>
     2 #include <openacc.h>
     3 
     4 int main()
     5 {
     6 #ifdef _OPENACC
     7     printf("%d device found!
    ", acc_get_num_devices(acc_device_not_host));
     8 #else
     9     printf("OpenACC not support.
    ");
    10 #endif
    11     getchar();
    12     return 0;
    13 }

    ● 直接在 Visual Studio 2015 编译遇到了一些问题,最后是用 PGI 的命令行来进行编译的。添加 openacc.h 的路径(C:Program FilesPGICEwin6418.4include)报错:

    严重性    代码    说明                            项目            文件                                                行
    错误      C1021  无效的预处理器命令“include_next”  OpenACCProject c:program filespgicewin6418.4includesal.h     28    

      <sal.h> 第 28 行  #include_next <sal.h>  ,意思是该 <sal.h> 中没有找到对应的头文件,要求预处理器去包含搜索路径的下一个 <sal.h>。但是 include_next 不是标准 C 的预处理器语句,在 Visual Studio 中无法执行(据说有办法解决,看起来有点麻烦,https://stackoverflow.com/questions/24638855/how-to-use-arduino-with-microsoft-visual-studio-due-to-include-next-precompil)。如果将该头文件中

    1 ...
    2 #if defined __PGI_TOOLS14
    3 #include <sal14.h>
    4 ...

      前面强行添上  #include <sal4.h> (该目录下确实有 <sal14.h> 这个头文件)并删除 #include_next 行,则会引起 vadefs.h 中的相同类型的错误,再把 vadefs.h 中

    1 ...
    2 #if defined __PGI_TOOLS12
    3 #include <vadefs12.h>
    4 ...

      前面强行添上  #include <C:/Program Files/PGICE/win64/18.4/include_acc/OT_14/vadefs.h> ,则没有了 #include_next 错误,但会有链接阶段报错:

    严重性    代码        说明            项目            文件                                                行
    错误      LNK1158    无法运行“rc.exe” OpenACCProject D:CodeOpenACCOpenACCProjectOpenACCProjectLINK  1    

      说到底这是 MS 编译器不支持 OpenACC 的原因,缺少宏 _OPENACC 的定义

    ● 代码在 PGI 的命令行中正确的编译和执行

     1 PGI Community Edition 18.4
     2 Microsoft Windows [版本 10.0.17134.1]
     3 (c) 2018 Microsoft Corporation。保留所有权利。
     4 
     5 C:Userscuan>D:
     6 
     7 D:>cd D:CodeOpenACCOpenACCProjectOpenACCProject
     8 
     9 D:CodeOpenACCOpenACCProjectOpenACCProject>pgcc -o main-no-acc.exe main.c
    10 
    11 D:CodeOpenACCOpenACCProjectOpenACCProject>main-no-acc.exe
    12 OpenACC not support.
    13 
    14 
    15 D:CodeOpenACCOpenACCProjectOpenACCProject>pgcc -acc -o main.exe main.c
    16 
    17 D:CodeOpenACCOpenACCProjectOpenACCProject>main.exe
    18 1 device found!
    19 
    20 
    21 D:CodeOpenACCOpenACCProjectOpenACCProject>

    ▶ 在 Ubuntu16.04LTS 上搭建 OpenACC 环境

    ● 安装顺序:CUDA Toolkite(https://developer.nvidia.com/cuda-downloads);PGI 编译器(https://www.pgroup.com/products/community.htm?*utm*_campaign=CE&utm_source=dev_nvidia_oacc&utm_medium=web_link&utm_term=*get_ce_text*)

    cuan@CUAN:~/pgilinux-2019-194-x86-64$ sudo su
    root@CUAN:/home/cuan/pgilinux-2019-194-x86-64# ./install
    
    Welcome to the PGI Linux installer!
    
    You are installing PGI 2019 version 19.4 for Linux.
    Please note that all Trademarks and Marks are the properties
    of their respective owners.
    
    Press enter to continue...  # 回车
    
    NVIDIA
    
    ...
    
    Do you accept these terms? (accept,decline) # accept
    
    ...
    
    1  Single system install
    2  Network install
    
    Please choose install option: # 1
    
    ...
    
    Installation directory? [/opt/pgi] # /usr/local/pgi
    
    ...
    
    JRE
    
    Press enter to continue... # 回车
    
    ...
    
    Do you accept these terms? (accept,decline) # accept
    
    ...
     
    Do you wish to update/create links in the 2019 directory? (y/n) # y
    
    ...
    
    MPI
    
    ...
    
    Do you want to install Open MPI onto your system? (y/n) # y
    Do you want to enable NVIDIA GPU support in Open MPI? (y/n) # y
    
    ...
    
    License Key Management
    
    ...
    
    Do you wish to obtain permanent license key or configure license service? (y/n) # y
    
    ...
     
    Press enter to continue... # 回车
    
    ...
    
     1  Generate or update a license key for this computer
          ** Option 1 IS NOT AVAILABLE.
             Requires properly configurd curl and internet access.
     2  Configure and start a license service on this computer
     4  I have a functioning license key - what type is it? (beta)
     5  Quit
    
    What do you want to do? # 2
    
    Please enter the location of the license key file.
    For example: /usr/local/pgi/license.dat
    Answer? # /usr/local/pgi/license.dat
    
    Should license services start when the system boots? (y/n) # y
    Master daemon (lmgrd) is not running
    Vendor daemon (pgroud) is not running
    
    The PGI license tool can be re-started by running the script located at:
    
       /usr/local/pgi/linux86-64-llvm/19.4/bin/pgi_license_tool
    
    The license key file is located at /usr/local/pgi/license.dat.
    
    ...

    ● 添加路径到 .bashrc,并执行 source .bashrc

    #for pgi
    export PATH=$PATH:/usr/local/pgi/linux86-64/18.4/bin
    export MANPATH=$MANPATH:/usr/local/pgi/linux86-64/18.4/man
    export LM_LICENSE_FILE=/usr/local/pgi/license.dat
    

    ● 编写代码同上,编译执行:

    cuan@CUAN:~$ pgcc --version
    
    pgcc 18.4-0 64-bit target on x86-64 Linux -tp haswell 
    PGI Compilers and Tools
    Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.
    cuan@CUAN:~$ cd Temp/
    cuan@CUAN:~/Temp$ pgcc -o main-no-acc.exe main.c
    cuan@CUAN:~/Temp$ pgcc -acc -o main.exe main.c
    cuan@CUAN:~/Temp$ ./main-no-acc.exe 
    OpenACC not support.
            
    cuan@CUAN:~/Temp$ ./main.exe 
    1 device found!
    
    cuan@CUAN:~/Temp$ 

    ● 几个坑:

    ■ linux 上要先装了 gcc/g++ 才能安装 pgi, apt-get install build-essential 

    ■ .bashrc 中加入 export 时,等号两边不能有空格

    ■ 误删了 .bashrc,从备份中去找, cp /etc/skel/.bashrc ~/ 

    ■ 在 Win10 WSL 上安装有点问题,核心问题是 Nvidia 的驱动安装不了,而 CUDA SDK 对其有依赖,强行安装 pgi 以后可以正常用 pgcc 编译,但是运行如上的代码时总是显示 0 device found! 它到底有没有调用 CUDA 核进行计算有待进一步探究,暂时折腾不动了

    ■ 删除 cygwin 用的 .bat,就是获得其文件的所有权。参考【https://www.cnblogs.com/litifeng/p/9996909.html】

    1 SET DIRECTORY_NAME="D:cygwin64"
    2 C:windowssystem32TAKEOWN /f %DIRECTORY_NAME% /r /d y
    3 C:windowssystem32ICACLS %DIRECTORY_NAME% /grant administrators:F /t
    4 PAUSE
  • 相关阅读:
    [Leetcode]设计链表
    [Leetcode]最小栈
    复杂JSON反序列化为类对象
    Big Data Solution in Azure: Azure Data Lake
    EF vs ADO.NET
    EF5.0默认不支持DB First了?
    WebService/WCF/WebAPI区别
    AugularJS1.X不升级到2.X
    数据库中锁的问题
    MVC中路由匹配的规则
  • 原文地址:https://www.cnblogs.com/cuancuancuanhao/p/8991334.html
Copyright © 2020-2023  润新知