Commit 8d6c5d78 authored by Leonardo Solis's avatar Leonardo Solis
Browse files

#31, Makefile refers now to official SDAccel files/aws branch rather than locally modified ones

All configurations are done in Makefile, SDAccel files are only referred to, but not touched
parent 43664917
[submodule "SDAccel_Examples"]
path = SDAccel_Examples
url = https://github.com/Xilinx/SDAccel_Examples.git
Subproject commit cd196250dfdd63491080e8c6f3e79fe6d1718997
# Definition of include file locations
OPENCL12_INCLUDE:= $(XILINX_SDX)/runtime/include/1_2
# Library directories
SDA_LIB:=$(XILINX_SDX)/lib/lnx64.o
opencl_CXXFLAGS=-I$(OPENCL12_INCLUDE)
ifeq ($(ARCH),POWER)
OPENCL_LIB:=$(XILINX_SDX)/runtime/lib/ppc64le
opencl_LDFLAGS=-L$(OPENCL_LIB) -lxilinxopencl -llmx6.0
else
OPENCL_LIB:=$(XILINX_SDX)/runtime/lib/x86_64
#opencl_LDFLAGS=-L$(OPENCL_LIB) -L$(SDA_LIB) -lOpenCL -pthread
opencl_LDFLAGS=-L$(OPENCL_LIB) -L$(SDA_LIB) -lxilinxopencl -pthread
endif
/**********
Copyright (c) 2018, Xilinx, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holder 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 HOLDER 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.
**********/
#include <unistd.h>
#include <limits.h>
#include <sys/stat.h>
#include "xcl2.hpp"
namespace xcl {
std::vector<cl::Device> get_devices(const std::string& vendor_name) {
size_t i;
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
cl::Platform platform;
for (i = 0 ; i < platforms.size(); i++){
platform = platforms[i];
std::string platformName = platform.getInfo<CL_PLATFORM_NAME>();
if (platformName == vendor_name){
std::cout << "Found Platform" << std::endl;
std::cout << "Platform Name: " << platformName.c_str() << std::endl;
break;
}
}
if (i == platforms.size()) {
std::cout << "Error: Failed to find Xilinx platform" << std::endl;
exit(EXIT_FAILURE);
}
//Getting ACCELERATOR Devices and selecting 1st such device
std::vector<cl::Device> devices;
platform.getDevices(CL_DEVICE_TYPE_ACCELERATOR, &devices);
return devices;
}
std::vector<cl::Device> get_xil_devices() {
return get_devices("Xilinx");
}
cl::Program::Binaries import_binary_file(std::string xclbin_file_name)
{
std::cout << "INFO: Importing " << xclbin_file_name << std::endl;
if(access(xclbin_file_name.c_str(), R_OK) != 0) {
printf("ERROR: %s xclbin not available please build\n", xclbin_file_name.c_str());
exit(EXIT_FAILURE);
}
//Loading XCL Bin into char buffer
std::cout << "Loading: '" << xclbin_file_name.c_str() << "'\n";
std::ifstream bin_file(xclbin_file_name.c_str(), std::ifstream::binary);
bin_file.seekg (0, bin_file.end);
unsigned nb = bin_file.tellg();
bin_file.seekg (0, bin_file.beg);
char *buf = new char [nb];
bin_file.read(buf, nb);
cl::Program::Binaries bins;
bins.push_back({buf,nb});
return bins;
}
std::string
find_binary_file(const std::string& _device_name, const std::string& xclbin_name)
{
std::cout << "XCLBIN File Name: " << xclbin_name.c_str() << std::endl;
char *xcl_mode = getenv("XCL_EMULATION_MODE");
char *xcl_target = getenv("XCL_TARGET");
std::string mode;
/* Fall back mode if XCL_EMULATION_MODE is not set is "hw" */
if(xcl_mode == NULL) {
mode = "hw";
} else {
/* if xcl_mode is set then check if it's equal to true*/
if(strcmp(xcl_mode,"true") == 0) {
/* if it's true, then check if xcl_target is set */
if(xcl_target == NULL) {
/* default if emulation but not specified is software emulation */
mode = "sw_emu";
} else {
/* otherwise, it's what ever is specified in XCL_TARGET */
mode = xcl_target;
}
} else {
/* if it's not equal to true then it should be whatever
* XCL_EMULATION_MODE is set to */
mode = xcl_mode;
}
}
char *xcl_bindir = getenv("XCL_BINDIR");
// typical locations of directory containing xclbin files
const char *dirs[] = {
xcl_bindir, // $XCL_BINDIR-specified
"xclbin", // command line build
"..", // gui build + run
".", // gui build, run in build directory
NULL
};
const char **search_dirs = dirs;
if (xcl_bindir == NULL) {
search_dirs++;
}
char *device_name = strdup(_device_name.c_str());
if (device_name == NULL) {
printf("Error: Out of Memory\n");
exit(EXIT_FAILURE);
}
// fix up device name to avoid colons and dots.
// xilinx:xil-accel-rd-ku115:4ddr-xpr:3.2 -> xilinx_xil-accel-rd-ku115_4ddr-xpr_3_2
for (char *c = device_name; *c != 0; c++) {
if (*c == ':' || *c == '.') {
*c = '_';
}
}
char *device_name_versionless = strdup(_device_name.c_str());
if (device_name_versionless == NULL) {
printf("Error: Out of Memory\n");
exit(EXIT_FAILURE);
}
unsigned short colons = 0;
bool colon_exist = false;
for (char *c = device_name_versionless; *c != 0; c++) {
if (*c == ':') {
colons++;
*c = '_';
colon_exist = true;
}
/* Zero out version area */
if (colons == 3) {
*c = '\0';
}
}
// versionless support if colon doesn't exist in device_name
if(!colon_exist) {
int len = strlen(device_name_versionless);
device_name_versionless[len - 4] = '\0';
}
const char *aws_file_patterns[] = {
"%1$s/%2$s.%3$s.%4$s.awsxclbin", // <kernel>.<target>.<device>.awsxclbin
"%1$s/%2$s.%3$s.%5$s.awsxclbin", // <kernel>.<target>.<device_versionless>.awsxclbin
"%1$s/binary_container_1.awsxclbin", // default for gui projects
"%1$s/%2$s.awsxclbin", // <kernel>.awsxclbin
NULL
};
const char *file_patterns[] = {
"%1$s/%2$s.%3$s.%4$s.xclbin", // <kernel>.<target>.<device>.xclbin
"%1$s/%2$s.%3$s.%5$s.xclbin", // <kernel>.<target>.<device_versionless>.xclbin
"%1$s/binary_container_1.xclbin", // default for gui projects
"%1$s/%2$s.xclbin", // <kernel>.xclbin
NULL
};
char xclbin_file_name[PATH_MAX];
memset(xclbin_file_name, 0, PATH_MAX);
ino_t aws_ino = 0; // used to avoid errors if an xclbin found via multiple/repeated paths
for (const char **dir = search_dirs; *dir != NULL; dir++) {
struct stat sb;
if (stat(*dir, &sb) == 0 && S_ISDIR(sb.st_mode)) {
for (const char **pattern = aws_file_patterns; *pattern != NULL; pattern++) {
char file_name[PATH_MAX];
memset(file_name, 0, PATH_MAX);
snprintf(file_name, PATH_MAX, *pattern, *dir, xclbin_name.c_str(), mode.c_str(), device_name, device_name_versionless);
if (stat(file_name, &sb) == 0 && S_ISREG(sb.st_mode)) {
char* bindir = strdup(*dir);
if (bindir == NULL) {
printf("Error: Out of Memory\n");
exit(EXIT_FAILURE);
}
if (*xclbin_file_name && sb.st_ino != aws_ino) {
printf("Error: multiple xclbin files discovered:\n %s\n %s\n", file_name, xclbin_file_name);
exit(EXIT_FAILURE);
}
aws_ino = sb.st_ino;
strncpy(xclbin_file_name, file_name, PATH_MAX);
}
}
}
}
ino_t ino = 0; // used to avoid errors if an xclbin found via multiple/repeated paths
// if no awsxclbin found, check for xclbin
if (*xclbin_file_name == '\0') {
for (const char **dir = search_dirs; *dir != NULL; dir++) {
struct stat sb;
if (stat(*dir, &sb) == 0 && S_ISDIR(sb.st_mode)) {
for (const char **pattern = file_patterns; *pattern != NULL; pattern++) {
char file_name[PATH_MAX];
memset(file_name, 0, PATH_MAX);
snprintf(file_name, PATH_MAX, *pattern, *dir, xclbin_name.c_str(), mode.c_str(), device_name, device_name_versionless);
if (stat(file_name, &sb) == 0 && S_ISREG(sb.st_mode)) {
char* bindir = strdup(*dir);
if (bindir == NULL) {
printf("Error: Out of Memory\n");
exit(EXIT_FAILURE);
}
if (*xclbin_file_name && sb.st_ino != ino) {
printf("Error: multiple xclbin files discovered:\n %s\n %s\n", file_name, xclbin_file_name);
exit(EXIT_FAILURE);
}
ino = sb.st_ino;
strncpy(xclbin_file_name, file_name, PATH_MAX);
}
}
}
}
}
// if no xclbin found, preferred path for error message from xcl_import_binary_file()
if (*xclbin_file_name == '\0') {
snprintf(xclbin_file_name, PATH_MAX, file_patterns[0], *search_dirs, xclbin_name.c_str(), mode.c_str(), device_name);
}
free(device_name);
return (xclbin_file_name);
}
bool is_emulation()
{
bool ret =false;
char *xcl_mode = getenv("XCL_EMULATION_MODE");
if (xcl_mode != NULL){
ret = true;
}
return ret;
}
bool is_hw_emulation()
{
bool ret =false;
char *xcl_mode = getenv("XCL_EMULATION_MODE");
if ((xcl_mode != NULL) && !strcmp(xcl_mode, "hw_emu")){
ret = true;
}
return ret;
}
bool is_xpr_device(const char *device_name) {
const char *output = strstr(device_name,"xpr");
if(output==NULL) {
return false;
}
else {
return true;
}
}
};
/**********
Copyright (c) 2018, Xilinx, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holder 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 HOLDER 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.
**********/
#pragma once
#define CL_HPP_CL_1_2_DEFAULT_BUILD
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#define CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY 1
#include <CL/cl2.hpp>
#include <iostream>
#include <fstream>
// When creating a buffer with user pointer (CL_MEM_USE_HOST_PTR), under the hood
// User ptr is used if and only if it is properly aligned (page aligned). When not
// aligned, runtime has no choice but to create its own host side buffer that backs
// user ptr. This in turn implies that all operations that move data to and from
// device incur an extra memcpy to move data to/from runtime's own host buffer
// from/to user pointer. So it is recommended to use this allocator if user wish to
// Create Buffer/Memory Object with CL_MEM_USE_HOST_PTR to align user buffer to the
// page boundary. It will ensure that user buffer will be used when user create
// Buffer/Mem Object with CL_MEM_USE_HOST_PTR.
template <typename T>
struct aligned_allocator
{
using value_type = T;
T* allocate(std::size_t num)
{
void* ptr = nullptr;
if (posix_memalign(&ptr,4096,num*sizeof(T)))
throw std::bad_alloc();
return reinterpret_cast<T*>(ptr);
}
void deallocate(T* p, std::size_t num)
{
free(p);
}
};
namespace xcl {
std::vector<cl::Device> get_xil_devices();
std::vector<cl::Device> get_devices(const std::string& vendor_name);
/* find_xclbin_file
*
*
* Description:
* Find precompiled program (as commonly created by the Xilinx OpenCL
* flow). Using search path below.
*
* Search Path:
* $XCL_BINDIR/<name>.<target>.<device>.xclbin
* $XCL_BINDIR/<name>.<target>.<device_versionless>.xclbin
* $XCL_BINDIR/binary_container_1.xclbin
* $XCL_BINDIR/<name>.xclbin
* xclbin/<name>.<target>.<device>.xclbin
* xclbin/<name>.<target>.<device_versionless>.xclbin
* xclbin/binary_container_1.xclbin
* xclbin/<name>.xclbin
* ../<name>.<target>.<device>.xclbin
* ../<name>.<target>.<device_versionless>.xclbin
* ../binary_container_1.xclbin
* ../<name>.xclbin
* ./<name>.<target>.<device>.xclbin
* ./<name>.<target>.<device_versionless>.xclbin
* ./binary_container_1.xclbin
* ./<name>.xclbin
*
* Inputs:
* _device_name - Targeted Device name
* xclbin_name - base name of the xclbin to import.
*
* Returns:
* An opencl program Binaries object that was created from xclbin_name file.
*/
std::string find_binary_file(const std::string& _device_name, const std::string& xclbin_name);
cl::Program::Binaries import_binary_file(std::string xclbin_file_name);
bool is_emulation () ;
bool is_hw_emulation () ;
bool is_xpr_device (const char *device_name);
}
xcl2_SRCS:=${COMMON_REPO}/libs/xcl2/xcl2.cpp
xcl2_HDRS:=${COMMON_REPO}/libs/xcl2/xcl2.hpp
xcl2_CXXFLAGS:=-I${COMMON_REPO}/libs/xcl2
# By Default report is set to none, so report will be generated
# 'estimate' for estimate report generation
# 'system' for system report generation
REPORT:=none
PROFILE ?= no
OTHER_FLAGS=
ifeq ($(TARGETS), sw_emu)
OTHER_FLAGS=-DSW_EMU
endif
#ifeq ($(TARGETS), hw_emu)
# OTHER_FLAGS=-DSW_EMU
#endif
# Default C++ Compiler Flags and xocc compiler flags
CXXFLAGS:=-Wall -O0 -g -std=c++14 $(OTHER_FLAGS)
# =============================
# Enable Kernels
# =============================
ENABLE_KRNL_GA = YES
ENABLE_KRNL_CONFORM = YES
ENABLE_KRNL_INTERE = YES
ENABLE_KRNL_INTRAE = YES
ENABLE_KRNL_PRNG_BT_USHORT_FLOAT = YES
ENABLE_KRNL_PRNG_GG_UCHAR = YES
ENABLE_KRNL_PRNG_GG_FLOAT = YES
ENABLE_KRNL_PRNG_LS123_USHORT = YES
ENABLE_KRNL_PRNG_LS_FLOAT = YES
ENABLE_KRNL_PRNG_LS2_FLOAT = YES
ENABLE_KRNL_PRNG_LS3_FLOAT = YES
ENABLE_KRNL_PRNG_LS4_FLOAT = YES
ENABLE_KRNL_PRNG_LS5_FLOAT = YES
ENABLE_KRNL_PRNG_LS6_FLOAT = YES
ENABLE_KRNL_PRNG_LS7_FLOAT = YES
ENABLE_KRNL_PRNG_LS8_FLOAT = YES
ENABLE_KRNL_PRNG_LS9_FLOAT = YES
ENABLE_KRNL_LS = YES
ENABLE_KRNL_LS2 = YES
ENABLE_KRNL_LS3 = YES
ENABLE_KRNL_LS4 = YES
ENABLE_KRNL_LS5 = YES
ENABLE_KRNL_LS6 = YES
ENABLE_KRNL_LS7 = YES
ENABLE_KRNL_LS8 = YES
ENABLE_KRNL_LS9 = YES
ENABLE_KRNL_IGL_ARBITER = YES
ifeq ($(ENABLE_KRNL_GA),YES)
KRNL_GA =-DENABLE_KRNL_GA
else
KRNL_GA =
endif
ifeq ($(ENABLE_KRNL_CONFORM),YES)
KRNL_CONFORM =-DENABLE_KRNL_CONFORM
else
KRNL_CONFORM =
endif
ifeq ($(ENABLE_KRNL_INTERE),YES)
KRNL_INTERE =-DENABLE_KRNL_INTERE
else
KRNL_INTERE =
endif
ifeq ($(ENABLE_KRNL_INTRAE),YES)
KRNL_INTRAE =-DENABLE_KRNL_INTRAE
else
KRNL_INTRAE =
endif
ifeq ($(ENABLE_KRNL_PRNG_BT_USHORT_FLOAT),YES)
KRNL_PRNG_BT_USHORT_FLOAT =-DENABLE_KRNL_PRNG_BT_USHORT_FLOAT
else
KRNL_PRNG_BT_USHORT_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_GG_UCHAR),YES)
KRNL_PRNG_GG_UCHAR =-DENABLE_KRNL_PRNG_GG_UCHAR
else
KRNL_PRNG_GG_UCHAR =
endif
ifeq ($(ENABLE_KRNL_PRNG_GG_FLOAT),YES)
KRNL_PRNG_GG_FLOAT =-DENABLE_KRNL_PRNG_GG_FLOAT
else
KRNL_PRNG_GG_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS123_USHORT),YES)
KRNL_PRNG_LS123_USHORT =-DENABLE_KRNL_PRNG_LS123_USHORT
else
KRNL_PRNG_LS123_USHORT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS_FLOAT),YES)
KRNL_PRNG_LS_FLOAT =-DENABLE_KRNL_PRNG_LS_FLOAT
else
KRNL_PRNG_LS_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS2_FLOAT),YES)
KRNL_PRNG_LS2_FLOAT =-DENABLE_KRNL_PRNG_LS2_FLOAT
else
KRNL_PRNG_LS2_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS3_FLOAT),YES)
KRNL_PRNG_LS3_FLOAT =-DENABLE_KRNL_PRNG_LS3_FLOAT
else
KRNL_PRNG_LS3_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS4_FLOAT),YES)
KRNL_PRNG_LS4_FLOAT =-DENABLE_KRNL_PRNG_LS4_FLOAT
else
KRNL_PRNG_LS4_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS5_FLOAT),YES)
KRNL_PRNG_LS5_FLOAT =-DENABLE_KRNL_PRNG_LS5_FLOAT
else
KRNL_PRNG_LS5_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS6_FLOAT),YES)
KRNL_PRNG_LS6_FLOAT =-DENABLE_KRNL_PRNG_LS6_FLOAT
else
KRNL_PRNG_LS6_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS7_FLOAT),YES)
KRNL_PRNG_LS7_FLOAT =-DENABLE_KRNL_PRNG_LS7_FLOAT
else
KRNL_PRNG_LS7_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS8_FLOAT),YES)
KRNL_PRNG_LS8_FLOAT =-DENABLE_KRNL_PRNG_LS8_FLOAT
else
KRNL_PRNG_LS8_FLOAT =
endif
ifeq ($(ENABLE_KRNL_PRNG_LS9_FLOAT),YES)
KRNL_PRNG_LS9_FLOAT =-DENABLE_KRNL_PRNG_LS9_FLOAT
else
KRNL_PRNG_LS9_FLOAT =
endif
ifeq ($(ENABLE_KRNL_LS),YES)
KRNL_LS =-DENABLE_KRNL_LS
else
KRNL_LS =
endif
ifeq ($(ENABLE_KRNL_LS2),YES)
KRNL_LS2 =-DENABLE_KRNL_LS2
else
KRNL_LS2 =
endif
ifeq ($(ENABLE_KRNL_LS3),YES)
KRNL_LS3 =-DENABLE_KRNL_LS3
else
KRNL_LS3 =
endif
ifeq ($(ENABLE_KRNL_LS4),YES)
KRNL_LS4 =-DENABLE_KRNL_LS4
else
KRNL_LS4 =
endif
ifeq ($(ENABLE_KRNL_LS5),YES)
KRNL_LS5 =-DENABLE_KRNL_LS5
else
KRNL_LS5 =
endif
ifeq ($(ENABLE_KRNL_LS6),YES)
KRNL_LS6 =-DENABLE_KRNL_LS6
else
KRNL_LS6 =
endif
ifeq ($(ENABLE_KRNL_LS7),YES)
KRNL_LS7 =-DENABLE_KRNL_LS7
else
KRNL_LS7 =
endif
ifeq ($(ENABLE_KRNL_LS8),YES)
KRNL_LS8 =-DENABLE_KRNL_LS8
else
KRNL_LS8 =
endif
ifeq ($(ENABLE_KRNL_LS9),YES)
KRNL_LS9 =-DENABLE_KRNL_LS9
else
KRNL_LS9 =
endif