-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d6bb48
commit 918da5b
Showing
10 changed files
with
153 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef HASTY_IMPL_OPENCL_KERNEL_HPP | ||
#define HASTY_IMPL_OPENCL_KERNEL_HPP | ||
#ifdef HASTY_IMPL_HAS_OPENCL | ||
|
||
#include <iostream> | ||
|
||
#include "./opencl.hpp" | ||
#include "./opencl_error_types.h" | ||
#include "./opencl_errors.hpp" | ||
#include "./opencl_global.hpp" | ||
#include "./opencl_memory_impl.h" | ||
|
||
OpenCLErrorCode opencl_add_kernel(const std::string &kernelSource); | ||
|
||
template<size_t... I, typename... Args> | ||
void setKernelArgs(cl::Kernel &kernel, const std::tuple<Args...> &args, | ||
std::index_sequence<I...>, size_t offset = 0) { | ||
((kernel.setArg(I + offset, std::get<I>(args))), ...); | ||
} | ||
|
||
template<typename... Args> | ||
OpenCLErrorCode | ||
opencl_run_contiguous_linear_kernel(const std::string &kernelName, size_t numElements, | ||
Args... args) { | ||
// std::cout << "Running kernel " << kernelName << " with " << numElements << " elements\n"; | ||
cl::Kernel kernel(global::openCLProgram, kernelName.c_str()); | ||
setKernelArgs(kernel, std::make_tuple(args...), std::make_index_sequence<sizeof...(Args)>()); | ||
cl::NDRange range(numElements); | ||
return get_opencl_error_code(global::openCLQueue.enqueueNDRangeKernel(kernel, cl::NullRange, range, cl::NullRange)); | ||
} | ||
|
||
#endif // HASTY_IMPL_HAS_OPENCL | ||
#endif //HASTY_IMPL_OPENCL_KERNEL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef HASTY_IMPL_OPENCL_KERNEL_IMPL_H | ||
#define HASTY_IMPL_OPENCL_KERNEL_IMPL_H | ||
#ifdef HASTY_IMPL_HAS_OPENCL | ||
|
||
#include "./opencl_error_types.h" | ||
#include "./opencl_memory_impl.h" | ||
|
||
enum OpenCLErrorCode opencl_add_kernel_ffi(const char *kernelSource); | ||
|
||
enum OpenCLErrorCode | ||
opencl_run_contiguous_linear_kernel_3_ffi(const char *kernelName, uint64_t numElements, void *buf0, void *buf1, | ||
void *buf2); | ||
|
||
#endif // HASTY_IMPL_HAS_OPENCL | ||
#endif //HASTY_IMPL_OPENCL_KERNEL_IMPL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifdef HASTY_IMPL_HAS_OPENCL | ||
|
||
#include <vector> | ||
#include <iostream> | ||
#include <hasty_opencl.h> | ||
#include <opencl/opencl.hpp> | ||
#include <opencl/opencl_errors.hpp> | ||
#include <opencl/opencl_global.hpp> | ||
#include <opencl/opencl_kernel.hpp> | ||
#include <clblast.h> | ||
|
||
OpenCLErrorCode opencl_add_kernel(const std::string &kernelSource) { | ||
global::openCLSources.push_back({kernelSource.c_str(), kernelSource.length()}); | ||
global::openCLProgram = cl::Program(global::openCLContext, global::openCLSources); | ||
return get_opencl_error_code(global::openCLProgram.build()); | ||
} | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
enum OpenCLErrorCode opencl_add_kernel_ffi(const char *kernelSource) { | ||
return opencl_add_kernel(std::string(kernelSource)); | ||
} | ||
|
||
enum OpenCLErrorCode | ||
opencl_run_contiguous_linear_kernel_3_ffi(const char *kernelName, uint64_t numElements, void *buf0, void *buf1, | ||
void *buf2) { | ||
return opencl_run_contiguous_linear_kernel(std::string(kernelName), numElements, *(cl::Buffer *) buf0, | ||
*(cl::Buffer *) buf1, *(cl::Buffer *) buf2); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#else | ||
|
||
void opencl_kernel_placeholder() {} | ||
|
||
#endif // HASTY_IMPL_HAS_OPENCL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters