-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
next #19
next #19
Changes from 1 commit
f3d3566
c0fb261
923b6e5
5831051
f1871c4
8933c64
a23b66e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
Copyright (c) 2024, Philip Deegan. | ||
All rights reserved. | ||
|
||
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 Philip Deegan 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. | ||
*/ | ||
// IWYU pragma: private, include "mkn/gpu.hpp" | ||
#ifndef _MKN_GPU_CLI_HPP_ | ||
#define _MKN_GPU_CLI_HPP_ | ||
|
||
#include <optional> | ||
#include <type_traits> | ||
|
||
#include "mkn/kul/env.hpp" | ||
|
||
namespace mkn::gpu { | ||
|
||
template <typename Device> | ||
struct Cli { | ||
// | ||
|
||
auto bx_threads() const { | ||
char const* ENV = "MKN_GPU_BX_THREADS"; | ||
if (mkn::kul::env::EXISTS(ENV)) { | ||
return as<std::int32_t>(mkn::kul::env::GET(ENV)); | ||
} | ||
return dev.maxThreadsPerBlock; | ||
} | ||
|
||
template <typename T> | ||
auto static as(std::string const& from) { | ||
T t; | ||
std::stringstream ss(from); | ||
ss >> t; | ||
return t; | ||
} | ||
|
||
Device const& dev; | ||
}; | ||
|
||
} /* namespace mkn::gpu */ | ||
|
||
#endif /*_MKN_GPU_CLI_HPP_*/ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
Copyright (c) 2020, Philip Deegan. | ||
Copyright (c) 2024, Philip Deegan. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
|
@@ -38,6 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
#include "mkn/kul/assert.hpp" | ||
#include "mkn/kul/threads.hpp" | ||
|
||
#include "mkn/gpu/cli.hpp" | ||
#include "mkn/gpu/def.hpp" | ||
|
||
#include <cassert> | ||
|
@@ -82,6 +83,15 @@ struct dim3 { | |
std::size_t x = 1, y = 1, z = 1; | ||
}; | ||
|
||
void setLimitMallocHeapSize(std::size_t const& /*bytes*/) { | ||
// noop | ||
} | ||
|
||
auto supportsCooperativeLaunch(int const /*dev*/ = 0) { | ||
int supportsCoopLaunch = 0; | ||
return supportsCoopLaunch; | ||
} | ||
|
||
struct Stream { | ||
Stream() {} | ||
~Stream() {} | ||
|
@@ -93,6 +103,19 @@ struct Stream { | |
std::size_t stream = 0; | ||
}; | ||
|
||
struct StreamEvent { | ||
StreamEvent(Stream&) {} | ||
~StreamEvent() {} | ||
|
||
auto& operator()() { return event; }; | ||
void record() { ; } | ||
bool finished() const { return true; } | ||
void reset() {} | ||
|
||
Stream stream; | ||
std::size_t event = 0; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The introduction of the |
||
|
||
template <typename T> | ||
struct Pointer { | ||
Pointer(T* _t) : t{_t} {} | ||
|
@@ -129,7 +152,7 @@ void alloc_managed(T*& p, Size size) { | |
MKN_GPU_ASSERT(p = reinterpret_cast<T*>(std::malloc(size * sizeof(T)))); | ||
} | ||
|
||
void destroy(void* p) { | ||
void inline destroy(void* p) { | ||
KLOG(TRC); | ||
std::free(p); | ||
} | ||
|
@@ -146,6 +169,12 @@ void destroy_host(T*& p) { | |
std::free(p); | ||
} | ||
|
||
template <typename T, typename Size> | ||
void copy_on_device(T* dst, T const* src, Size size = 1) { | ||
KLOG(TRC); | ||
MKN_GPU_ASSERT(std::memcpy(dst, src, size * sizeof(T))); | ||
} | ||
|
||
template <typename Size> | ||
void send(void* p, void* t, Size size = 1) { | ||
KLOG(TRC); | ||
|
@@ -177,7 +206,7 @@ void take_async(T* p, Span& span, Stream& /*stream*/, std::size_t start) { | |
take(p, span.data(), span.size(), start); | ||
} | ||
|
||
void sync() {} | ||
void inline sync() {} | ||
|
||
#include "mkn/gpu/alloc.hpp" | ||
#include "mkn/gpu/device.hpp" | ||
|
@@ -186,7 +215,7 @@ namespace detail { | |
static thread_local std::size_t idx = 0; | ||
} | ||
|
||
template <typename F, typename... Args> | ||
template <bool _sync = true, bool _coop = false, typename F, typename... Args> | ||
void launch(F f, dim3 g, dim3 b, std::size_t /*ds*/, std::size_t /*stream*/, Args&&... args) { | ||
std::size_t N = (g.x * g.y * g.z) * (b.x * b.y * b.z); | ||
KLOG(TRC) << N; | ||
|
@@ -252,6 +281,8 @@ static void global_gd_kernel(F& f, std::size_t s, Args... args) { | |
|
||
#include "launchers.hpp" | ||
|
||
void grid_sync() {} | ||
|
||
} /* namespace MKN_GPU_NS */ | ||
|
||
#undef MKN_GPU_ASSERT | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper error handling for environment variable retrieval.
The function
bx_threads
retrieves an environment variable and converts it to an integer. Consider adding error handling for cases where the environment variable is not a valid integer.