Skip to content

Commit

Permalink
Code rearrangement, no functionality change:
Browse files Browse the repository at this point in the history
* Removed redundant header inclusions in `multi_wrapper_impls/kernel.hpp`
* Moved apriori-compiled kernel multi-wrapper code still remaining in `multi_wrapper_impls/apriori_compiled_kernel.hpp` into `multi_wrapper_impls/kernel.hpp`
  • Loading branch information
eyalroz committed Mar 1, 2024
1 parent 2d1b385 commit 810fccf
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/cuda/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "api/devices.hpp"

#include "api/detail/pci_id.hpp"
#include "api/apriori_compiled_kernel.hpp"
#include "api/kernels/apriori_compiled.hpp"
#include "api/launch_configuration.hpp"
#include "api/kernel_launch.hpp"
#include "api/virtual_memory.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/api/kernel_launch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#include "launch_configuration.hpp"
#include "kernel.hpp"
#include "apriori_compiled_kernel.hpp"
#include "kernels/apriori_compiled.hpp"

#if CUDA_VERSION >= 9000
// The following is necessary for cudaLaunchCooperativeKernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* compiled together with the host-side program.
*/
#pragma once
#ifndef CUDA_API_WRAPPERS_APRIORI_COMPILED_KERNEL_HPP_
#define CUDA_API_WRAPPERS_APRIORI_COMPILED_KERNEL_HPP_
#ifndef CUDA_API_WRAPPERS_KERNELS_APRIORI_COMPILED_HPP_
#define CUDA_API_WRAPPERS_KERNELS_APRIORI_COMPILED_HPP_

#include "kernel.hpp"
#include "current_context.hpp"
#include "../kernel.hpp"

// The following is needed for occupancy-related calculation convenience
// and kernel-attribute-related API functions
Expand Down Expand Up @@ -499,4 +498,4 @@ apriori_compiled_kernel_t get(context_t context, KernelFunctionPtr function_ptr)

} // namespace cuda

#endif // CUDA_API_WRAPPERS_APRIORI_COMPILED_KERNEL_HPP_
#endif // CUDA_API_WRAPPERS_KERNELS_APRIORI_COMPILED_HPP_
74 changes: 59 additions & 15 deletions src/cuda/api/multi_wrapper_impls/apriori_compiled_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,7 @@
#ifndef MULTI_WRAPPER_IMPLS_APRIORI_COMPILED_KERNEL_HPP_
#define MULTI_WRAPPER_IMPLS_APRIORI_COMPILED_KERNEL_HPP_

#include "../array.hpp"
#include "../device.hpp"
#include "../event.hpp"
#include "../kernel_launch.hpp"
#include "../pointer.hpp"
#include "../stream.hpp"
#include "../unique_ptr.hpp"
#include "../primary_context.hpp"
#include "../kernel.hpp"
#include "../apriori_compiled_kernel.hpp"
#include "../virtual_memory.hpp"
#include "../current_context.hpp"
#include "../current_device.hpp"
#include "../texture_view.hpp"
#include "../peer_to_peer.hpp"
#include "../kernels/apriori_compiled.hpp"

namespace cuda {

Expand Down Expand Up @@ -124,6 +110,64 @@ inline kernel::attribute_value_t apriori_compiled_kernel_t::get_attribute(kernel
#endif // defined(__CUDACC__)
#endif // ! CAN_GET_APRIORI_KERNEL_HANDLE

namespace kernel {


namespace detail_ {

template<typename KernelFunctionPtr>
apriori_compiled_kernel_t get(
::cuda::device::id_t device_id,
context::handle_t & primary_context_handle,
KernelFunctionPtr function_ptr)
{
static_assert(
::std::is_pointer<KernelFunctionPtr>::value
and ::std::is_function<typename ::std::remove_pointer<KernelFunctionPtr>::type>::value,
"function must be a bona fide pointer to a kernel (__global__) function");

auto ptr_ = reinterpret_cast<const void *>(function_ptr);
#if CAN_GET_APRIORI_KERNEL_HANDLE
auto handle = detail_::get_handle(ptr_);
#else
auto handle = nullptr;
#endif
return wrap(device_id, primary_context_handle, handle, ptr_, do_hold_primary_context_refcount_unit);
}

} // namespace detail_


/**
* @brief Obtain a wrapped kernel object corresponding to a "raw" kernel function
*
* @note Kernel objects are device (and context) specific;' but kernels built
* from functions in program sources are used (only?) with the primary context of a device
*
* @note The returned kernel proxy object will keep the device's primary
* context active while the kernel exists.
*/
template<typename KernelFunctionPtr>
apriori_compiled_kernel_t get(const device_t& device, KernelFunctionPtr function_ptr)
{
auto primary_context_handle = device::primary_context::detail_::obtain_and_increase_refcount(device.id());
return detail_::get(device.id(), primary_context_handle, function_ptr);
}

} // namespace kernel

namespace detail_ {

template<>
inline ::cuda::device::primary_context_t
get_implicit_primary_context<apriori_compiled_kernel_t>(apriori_compiled_kernel_t kernel)
{
const kernel_t& kernel_ = kernel;
return get_implicit_primary_context(kernel_);
}

} // namespace detail_

} // namespace cuda

#endif // MULTI_WRAPPER_IMPLS_APRIORI_COMPILED_KERNEL_HPP_
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/api/multi_wrapper_impls/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "../stream.hpp"
#include "../primary_context.hpp"
#include "../kernel.hpp"
#include "../apriori_compiled_kernel.hpp"
#include "../kernels/apriori_compiled.hpp"
#include "../current_context.hpp"
#include "../current_device.hpp"
#include "../peer_to_peer.hpp"
Expand Down
53 changes: 0 additions & 53 deletions src/cuda/api/multi_wrapper_impls/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,10 @@
#include "../pointer.hpp"
#include "../primary_context.hpp"
#include "../kernel.hpp"
#include "../apriori_compiled_kernel.hpp"
#include "../current_context.hpp"

namespace cuda {

namespace kernel {

namespace detail_ {

template<typename KernelFunctionPtr>
apriori_compiled_kernel_t get(
device::id_t device_id,
context::handle_t & primary_context_handle,
KernelFunctionPtr function_ptr)
{
static_assert(
::std::is_pointer<KernelFunctionPtr>::value
and ::std::is_function<typename ::std::remove_pointer<KernelFunctionPtr>::type>::value,
"function must be a bona fide pointer to a kernel (__global__) function");

auto ptr_ = reinterpret_cast<const void *>(function_ptr);
#if CAN_GET_APRIORI_KERNEL_HANDLE
auto handle = detail_::get_handle(ptr_);
#else
auto handle = nullptr;
#endif
return detail_::wrap(device_id, primary_context_handle, handle, ptr_, do_hold_primary_context_refcount_unit);
}

} // namespace detail_

/**
* @brief Obtain a wrapped kernel object corresponding to a "raw" kernel function
*
* @note Kernel objects are device (and context) specific;' but kernels built
* from functions in program sources are used (only?) with the primary context of a device
*
* @note The returned kernel proxy object will keep the device's primary
* context active while the kernel exists.
*/
template<typename KernelFunctionPtr>
apriori_compiled_kernel_t get(const device_t& device, KernelFunctionPtr function_ptr)
{
auto primary_context_handle = device::primary_context::detail_::obtain_and_increase_refcount(device.id());
return detail_::get(device.id(), primary_context_handle, function_ptr);
}


} // namespace kernel

inline context_t kernel_t::context() const noexcept
{
constexpr bool dont_take_ownership { false };
Expand Down Expand Up @@ -101,13 +55,6 @@ inline device::primary_context_t get_implicit_primary_context<kernel_t>(kernel_t
return primary_context;
}

template<>
inline device::primary_context_t get_implicit_primary_context<apriori_compiled_kernel_t>(apriori_compiled_kernel_t kernel)
{
const kernel_t& kernel_ = kernel;
return get_implicit_primary_context(kernel_);
}

} // namespace detail_

} // namespace cuda
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/runtime_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "api/devices.hpp"

#include "api/detail/pci_id.hpp"
#include "api/apriori_compiled_kernel.hpp"
#include "api/kernels/apriori_compiled.hpp"
#include "api/kernel.hpp"
#include "api/launch_configuration.hpp"
#include "api/kernel_launch.hpp"
Expand Down

0 comments on commit 810fccf

Please sign in to comment.