Skip to content

Commit

Permalink
feat(SX-AT): update single task
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteBlue committed Jun 13, 2021
1 parent 866679d commit a2bd11d
Show file tree
Hide file tree
Showing 32 changed files with 280 additions and 118 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

option(BUILD_KERNEL_GENERATOR "build sycl kernel generator" OFF)
#option(BUILD_VE "Enable SX-Aurora support" OFF)
option(BUILD_VE "Enable SX-Aurora support" OFF)
#option(BUILD_TESTING "Enable build tests" OFF)


Expand Down Expand Up @@ -37,8 +37,7 @@ endif ()

include_directories(include)

# use pthread
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread")

# add examples
add_subdirectory(examples)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ To build examples, use following commands:

## Enable NEC SX-Aurora TSUBASA (SX-AT) support

@TODO Current SX-AURORA version is under development, please check branch backup.

@TODO Current SX-AURORA new version is under development, please check branch backup.

We also need a `sycl-kernel-generator` to generate kernel codes, which is a module of neoSYCL project.

Expand Down
14 changes: 1 addition & 13 deletions include/neoSYCL/extensions/nec/ve_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,11 @@

#include "ve_offload.h"

namespace neosycl::sycl::nec {
namespace neosycl::sycl::extensions {

const int DEFAULT_VE_NODE = 0;
const string_class DEFAULT_VE_LIB = "./kernel.so";

class VEException : public SYCLException {
private:
string_class msg;

public:
VEException(string_class msg) : msg(std::move(msg)) {}

const char *what() const noexcept override {
return msg.c_str();
}

};

struct VEProc {
struct veo_proc_handle *ve_proc;
Expand Down
171 changes: 171 additions & 0 deletions include/neoSYCL/extensions/nec/ve_task_handler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#ifndef NEOSYCL_INCLUDE_NEOSYCL_EXTENSIONS_NEC_VE_TASK_HANDLER_HPP
#define NEOSYCL_INCLUDE_NEOSYCL_EXTENSIONS_NEC_VE_TASK_HANDLER_HPP

#include "neoSYCL/extensions/nec/ve_info.hpp"
#include "neoSYCL/sycl/detail/kernel_arg.hpp"
#include "ve_offload.h"

namespace neosycl::sycl::extensions {

struct task_handler_ve : public detail::task_handler {

public:

task_handler_ve(const VEProc &proc) : proc(proc) {
ctx = ctx_create(proc);
}

VEContext ctx_create(VEProc proc) {
struct veo_thr_ctxt *ctx = veo_context_open(proc.ve_proc);
DEBUG_INFO("[VEContext] create ve context: {:#x}", (size_t) ctx);
return VEContext{ctx};
}

void free_ctx(VEContext ctx) {
DEBUG_INFO("[VEContext] release ve ctx: {:#x}", (size_t) ctx.ve_ctx);
int rt = veo_context_close(ctx.ve_ctx);
if (rt != veo_command_state::VEO_COMMAND_OK) {
DEBUG_INFO("[VEContext] release ve ctx: {:#x} failed, return code: {}", (size_t) ctx.ve_ctx, rt);
PRINT_ERR("[VEContext] release ve ctx failed");
}
}

struct veo_args *create_ve_args() {
struct veo_args *argp = veo_args_alloc();
if (!argp) {
throw exception("ve args return nullptr");
}
return argp;
}

vector_class<uint64_t> copy_in(struct veo_args *argp, shared_ptr_class<detail::kernel> k, VEProc proc) {
vector_class<uint64_t> ve_addr_list;

for (int i = 0; i < k->args.size(); i++) {
detail::KernelArg arg = k->args[i];
size_t size_in_byte = arg.container->get_size();

uint64_t ve_addr_int;
int rt = veo_alloc_mem(proc.ve_proc, &ve_addr_int, size_in_byte);
if (rt != veo_command_state::VEO_COMMAND_OK) {
DEBUG_INFO("[VEProc] allocate VE memory size: {} failed, return code: {}", size_in_byte, rt);
PRINT_ERR("[VEProc] allocate VE memory failed");
throw exception("VE allocate return error");
}
ve_addr_list.push_back(ve_addr_int);

DEBUG_INFO("[VEKernel] allocate ve memory, size: {}, ve address: {:#x}",
size_in_byte,
ve_addr_int
);

if (arg.mode != access::mode::write) {
DEBUG_INFO("[VEKernel] do copy to ve memory for arg, device address: {:#x}, size: {}, host address: {:#x}",
(size_t) ve_addr_int,
size_in_byte,
(size_t) arg.container->get_raw_ptr()
);
rt = veo_write_mem(proc.ve_proc, ve_addr_int, arg.container->get_raw_ptr(), size_in_byte);
if (rt != veo_command_state::VEO_COMMAND_OK) {
DEBUG_INFO("[VEProc] copy to ve memory failed, size: {}, return code: {}", size_in_byte, rt);
PRINT_ERR("[VEProc] copy to ve memory failed");
throw exception("VE copy return error");
}
}
veo_args_set_i64(argp, i, ve_addr_int);
}
return ve_addr_list;
}

void copy_out(vector_class<uint64_t> ve_addr_list, shared_ptr_class<detail::kernel> k, VEProc proc) {
for (int i = 0; i < k->args.size(); i++) {
detail::KernelArg arg = k->args[i];
size_t size_in_byte = arg.container->get_size();
uint64_t device_ptr = ve_addr_list[i];
if (arg.mode != access::mode::read) {
DEBUG_INFO("[VEKernel] copy from ve memory, device address: {:#x}, size: {}, host address: {:#x}",
(size_t) device_ptr,
size_in_byte,
(size_t) arg.container->get_raw_ptr()
);
// do copy
int rt = veo_read_mem(proc.ve_proc, arg.container->get_raw_ptr(), device_ptr, size_in_byte);
if (rt != veo_command_state::VEO_COMMAND_OK) {
DEBUG_INFO("[VEProc] copy from ve memory failed, size: {}, return code: {}", size_in_byte, rt);
PRINT_ERR("[VEProc] copy from ve memory failed");
throw exception("VE copy return error");
}
}
int rt = veo_free_mem(proc.ve_proc, device_ptr);
if (rt != veo_command_state::VEO_COMMAND_OK) {
DEBUG_INFO("[VEProc] free ve memory failed, size: {}, return code: {}", size_in_byte, rt);
PRINT_ERR("[VEProc] free ve memory failed");
throw exception("VE free memory return error");
}
}
}

void single_task(shared_ptr_class<detail::kernel> k, const std::function<void(void)> &func) override {
for (const detail::KernelArg &arg:k->args) {
arg.acquire_access();
}
DEBUG_INFO("execute single %d kernel, name: %s\n", type(), k->name.c_str());

DEBUG_INFO("[VEKernel] single task: {}", k->name.c_str());

veo_args *argp = create_ve_args();
DEBUG_INFO("[VEKernel] create ve args: {:#x}", (size_t) argp);

try {

vector_class<uint64_t> ve_addr_list = copy_in(argp, k, proc);
DEBUG_INFO("[VEKernel] invoke ve func: {}", k->name.c_str());
uint64_t id = veo_call_async_by_name(ctx.ve_ctx, proc.handle, k->name.c_str(), argp);
uint64_t ret_val;
veo_call_wait_result(ctx.ve_ctx, id, &ret_val);
DEBUG_INFO("[VEKernel] ve func finished, id: {}, ret val: {}", id, ret_val);
copy_out(ve_addr_list, k, proc);

} catch (exception &e) {
std::cerr << "[VEKernel] kernel invoke failed, error message: " << e.what() << std::endl;
}

veo_args_free(argp);

for (const detail::KernelArg &arg:k->args) {
arg.release_access();
}
}

void parallel_for_1d(shared_ptr_class<detail::kernel> k,
range<1> r,
const std::function<void(id<1>)> &func,
id<1> offset) override {
throw exception("not implemented");
};

void parallel_for_2d(shared_ptr_class<detail::kernel> k,
range<2> r,
const std::function<void(id<2>)> &func,
id<2> offset) override {
throw exception("not implemented");
};

void parallel_for_3d(shared_ptr_class<detail::kernel> k,
range<3> r,
const std::function<void(id<3>)> &func,
id<3> offset) override {
throw exception("not implemented");
};

detail::SUPPORT_PLATFORM_TYPE type() override {
return detail::SX_AURORA;
}

private:
VEContext ctx;
VEProc proc;
};

}
#endif //NEOSYCL_INCLUDE_NEOSYCL_EXTENSIONS_NEC_VE_TASK_HANDLER_HPP
11 changes: 0 additions & 11 deletions include/neoSYCL/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@
#include "sycl/queue.hpp"
#include "sycl/handler.hpp"

#ifdef BUILD_VE
#include "neoSYCL/sycl/nec/ve_device.hpp"
#include "neoSYCL/sycl/nec/ve_queue.hpp"
#include "neoSYCL/sycl/nec/ve_task.hpp"
#include "neoSYCL/sycl/nec/ve_kernel.hpp"
#endif

#ifdef BUILD_FPGA

#endif

namespace neosycl {

using namespace neosycl::sycl;
Expand Down
10 changes: 5 additions & 5 deletions include/neoSYCL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef NEOSYCL_INCLUDE_NEOSYCL_SYCL_ACCESSOR_HPP
#define NEOSYCL_INCLUDE_NEOSYCL_SYCL_ACCESSOR_HPP

#include "id.hpp"
#include "property_list.hpp"
#include "handler.hpp"
#include "detail/container/data_container.hpp"
#include "detail/container/data_container_nd.hpp"
#include "neoSYCL/sycl/id.hpp"
#include "neoSYCL/sycl/property_list.hpp"
#include "neoSYCL/sycl/handler.hpp"
#include "neoSYCL/sycl/detail/container/data_container.hpp"
#include "neoSYCL/sycl/detail/container/data_container_nd.hpp"

namespace neosycl::sycl {

Expand Down
20 changes: 10 additions & 10 deletions include/neoSYCL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef CUSTOM_SYCL_INCLUDE_SYCL_BUFFER_HPP_
#define CUSTOM_SYCL_INCLUDE_SYCL_BUFFER_HPP_

#include "types.hpp"
#include "range.hpp"
#include "access.hpp"
#include "accessor.hpp"
#include "allocator.hpp"
#include "handler.hpp"
#include "context.hpp"
#include "property_list.hpp"
#include "detail/container/data_container.hpp"
#include "detail/container/data_container_nd.hpp"
#include "neoSYCL/sycl/types.hpp"
#include "neoSYCL/sycl/range.hpp"
#include "neoSYCL/sycl/access.hpp"
#include "neoSYCL/sycl/accessor.hpp"
#include "neoSYCL/sycl/allocator.hpp"
#include "neoSYCL/sycl/handler.hpp"
#include "neoSYCL/sycl/context.hpp"
#include "neoSYCL/sycl/property_list.hpp"
#include "neoSYCL/sycl/detail/container/data_container.hpp"
#include "neoSYCL/sycl/detail/container/data_container_nd.hpp"

namespace neosycl::sycl {

Expand Down
6 changes: 3 additions & 3 deletions include/neoSYCL/sycl/context.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef CUSTOM_SYCL_INCLUDE_SYCL_CONTEXT_HPP_
#define CUSTOM_SYCL_INCLUDE_SYCL_CONTEXT_HPP_

#include "exception.hpp"
#include "info/context.hpp"
#include "property_list.hpp"
#include "neoSYCL/sycl/exception.hpp"
#include "neoSYCL/sycl/info/context.hpp"
#include "neoSYCL/sycl/property_list.hpp"

namespace neosycl::sycl {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define SYCL_INCLUDE_CL_SYCL_BUFFER_DATA_CONTAINER_ND_HPP_

#include <shared_mutex>
#include "array_nd.hpp"
#include "neoSYCL/sycl/detail/container/array_nd.hpp"

namespace neosycl::sycl::detail::container {

Expand Down
2 changes: 1 addition & 1 deletion include/neoSYCL/sycl/detail/device_info.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef NEOSYCL_INCLUDE_NEOSYCL_SYCL_DETAIL_DEVICE_INFO_HPP
#define NEOSYCL_INCLUDE_NEOSYCL_SYCL_DETAIL_DEVICE_INFO_HPP

#include "device_type.hpp"
#include "neoSYCL/sycl/detail/device_type.hpp"

namespace neosycl::sycl::detail {

Expand Down
3 changes: 2 additions & 1 deletion include/neoSYCL/sycl/detail/device_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
namespace neosycl::sycl::detail {

enum SUPPORT_PLATFORM_TYPE : int {
CPU
CPU,
SX_AURORA
};

}
Expand Down
2 changes: 1 addition & 1 deletion include/neoSYCL/sycl/detail/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define SYCL_INCLUDE_CL_SYCL_KERNEL_KERNEL_HPP_

#include <utility>
#include "kernel_arg.hpp"
#include "neoSYCL/sycl/detail/kernel_arg.hpp"

namespace neosycl::sycl::detail {

Expand Down
4 changes: 2 additions & 2 deletions include/neoSYCL/sycl/detail/kernel_arg.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef SYCL_INCLUDE_CL_SYCL_KERNEL_KERNEL_ARG_HPP_
#define SYCL_INCLUDE_CL_SYCL_KERNEL_KERNEL_ARG_HPP_

#include "container/data_container.hpp"
#include "../access.hpp"
#include "neoSYCL/sycl/detail/container/data_container.hpp"
#include "neoSYCL/sycl/access.hpp"

namespace neosycl::sycl::detail {

Expand Down
4 changes: 2 additions & 2 deletions include/neoSYCL/sycl/detail/platform_info.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef NEOSYCL_INCLUDE_NEOSYCL_SYCL_DETAIL_PLATFORM_INFO_HPP
#define NEOSYCL_INCLUDE_NEOSYCL_SYCL_DETAIL_PLATFORM_INFO_HPP

#include "device_info.hpp"
#include "device_type.hpp"
#include "neoSYCL/sycl/detail/device_info.hpp"
#include "neoSYCL/sycl/detail/device_type.hpp"

namespace neosycl::sycl::detail {

Expand Down
14 changes: 11 additions & 3 deletions include/neoSYCL/sycl/detail/registered_platforms.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#ifndef NEOSYCL_INCLUDE_NEOSYCL_SYCL_DETAIL_REGISTERED_PLATFORMS_H
#define NEOSYCL_INCLUDE_NEOSYCL_SYCL_DETAIL_REGISTERED_PLATFORMS_H

#include "platform_info.hpp"
#include "task_handler.hpp"
#include "neoSYCL/sycl/detail/platform_info.hpp"
#include "neoSYCL/sycl/detail/task_handler.hpp"
#include <map>

#ifdef BUILD_VE
#include "neoSYCL/extensions/nec/ve_task_handler.hpp"
#endif

namespace neosycl::sycl::detail {

static shared_ptr_class<platform_info> REGISTERED_PLATFORMS[] = {
shared_ptr_class<platform_info>(new default_platform_info())
};

static std::map<SUPPORT_PLATFORM_TYPE, shared_ptr_class<task_handler>> PLATFORM_HANDLER_MAP = {
{SUPPORT_PLATFORM_TYPE::CPU, shared_ptr_class<task_handler>(new task_handler_cpu())}
{SUPPORT_PLATFORM_TYPE::CPU, shared_ptr_class<task_handler>(new task_handler_cpu())},

#ifdef DBUILD_VE
{SUPPORT_PLATFORM_TYPE::SX_AURORA, shared_ptr_class<task_handler>(new task_handler_cpu())}
#endif
};

}
Expand Down
2 changes: 1 addition & 1 deletion include/neoSYCL/sycl/detail/task_handler.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef NEOSYCL_INCLUDE_NEOSYCL_SYCL_TASK_HANDLER_HPP
#define NEOSYCL_INCLUDE_NEOSYCL_SYCL_TASK_HANDLER_HPP

#include "kernel.hpp"
#include "neoSYCL/sycl/detail/kernel.hpp"

namespace neosycl::sycl::detail {

Expand Down
Loading

0 comments on commit a2bd11d

Please sign in to comment.