Skip to content
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

Resolve CUDA Compatibility Issues #263

Closed
wants to merge 6 commits into from
58 changes: 58 additions & 0 deletions cuda_kernel_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

project(cuda_kernel_generator LANGUAGES CXX CUDA)

# Set the C++ and CUDA standards to C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

# Find the CUDA Toolkit
find_package(CUDAToolkit REQUIRED)

# Set the CUDA source files
set(CUDA_KERNEL_GENERATOR_SRC
kernel_generator.cu
kernel_code_generator.cpp
)

# Specify the target for the CUDA kernel generator
add_library(cuda_kernel_generator SHARED
${CUDA_KERNEL_GENERATOR_SRC}
)

# Set the required CUDA flags
set_target_properties(cuda_kernel_generator PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_RUNTIME_LIBRARY Shared
)

# Specify include directories for the target
target_include_directories(cuda_kernel_generator PRIVATE
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
/home/ubuntu/openmind/omnn/math
/usr/local/include
/usr/include
/usr/include/x86_64-linux-gnu
/usr/include/c++/11
/usr/include/c++/11/x86_64-linux-gnu
)

# Link CUDA libraries and the omnn/math library
target_link_libraries(cuda_kernel_generator
CUDA::cudart
/home/ubuntu/openmind/omnn/math/libstorage.a # Corrected the full path to the storage library
)

# Ensure shared libraries are used for the linker
set_property(TARGET cuda_kernel_generator PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON)

# Explicitly set the standard include directories for the host compiler to ensure the correct headers are included
set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/usr/include/c++/11;/usr/include/x86_64-linux-gnu/c++/11;/usr/include/c++/11/backward;/usr/lib/gcc/x86_64-linux-gnu/11/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include")

# Add an executable for testing the shared library
add_executable(test_cuda_kernel_generator test_cuda_kernel_generator.cpp)

# Link the test executable with the shared library
target_link_libraries(test_cuda_kernel_generator cuda_kernel_generator)
14 changes: 14 additions & 0 deletions cuda_kernel_generator/test_cuda_kernel_generator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>

// Forward declaration of a function from the shared library
extern void generateCudaKernel();

int main() {
std::cout << "Testing the CUDA kernel generator shared library...\n";

// Call the function from the shared library
generateCudaKernel();

std::cout << "Test completed.\n";
return 0;
}
49 changes: 17 additions & 32 deletions omnn/math/Valuable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Created by Сергей Кривонос on 01.09.17.
//
#pragma once
#include <omnn/math/OpenOps.h>
#include "OpenOps.h"

#include <deque>
#include <functional>
#include <list>
#include <map>
#include <memory>
Expand Down Expand Up @@ -58,7 +57,7 @@ struct hash<omnn::math::Valuable> {

namespace omnn{
namespace math {

namespace constants {
extern const Valuable& e;
extern const Valuable& i;
Expand Down Expand Up @@ -106,11 +105,10 @@ class Valuable
virtual Valuable* Move();
virtual void New(void*, Valuable&&);
static constexpr size_t DefaultAllocSize = 768;
constexpr virtual size_t getTypeSize() const { return sizeof(Valuable); }
constexpr virtual size_t getAllocSize() const { return sz; }
constexpr virtual void setAllocSize(size_t sz) { this->sz = sz; }
virtual size_t getTypeSize() const { return sizeof(Valuable); }
virtual size_t getAllocSize() const { return sz; }
virtual void setAllocSize(size_t sz) { this->sz = sz; }

template<class T>
constexpr Valuable() {}

constexpr Valuable(ValuableDescendantMarker)
Expand Down Expand Up @@ -248,12 +246,12 @@ class Valuable
explicit Valuable(Valuable* v);
explicit Valuable(const encapsulated_instance& e);
virtual std::type_index Type() const;
const Valuable Link() const; // TODO : handle simulteneous values changes
const Valuable Link() const; // TODO : handle simulteneous values changes

Valuable& operator =(const Valuable& v);
Valuable& operator =(Valuable&& v);

bool SerializedStrEqual(const std::string_view& s) const;
bool SerializedStrEqual(const std::string& s) const;

Valuable(const Valuable& v);

Expand All @@ -274,8 +272,7 @@ class Valuable
: exp(t.Move())
{ }

MSVC_CONSTEXPR Valuable(Valuable&&) = default;
Valuable();
Valuable(Valuable&&) = default;
Valuable(double d);

template<class T,
Expand All @@ -288,12 +285,11 @@ class Valuable
Valuable(a_rational&&);
Valuable(const a_rational&);

using NewVaFn_t = std::function<Valuable(const std::string&)>;
using NewVaFn_t = Valuable(*)(const std::string&);
Valuable(const std::string& s, NewVaFn_t newVa);
Valuable(const std::string_view&, std::shared_ptr<VarHost>, bool itIsOptimized = false);
Valuable(const std::string& str, std::shared_ptr<VarHost>, bool itIsOptimized = false);

//constexpr
virtual ~Valuable()//{}
virtual ~Valuable()//{}
;
virtual Valuable operator -() const;
virtual Valuable& operator +=(const Valuable&);
Expand Down Expand Up @@ -338,7 +334,7 @@ class Valuable
virtual void optimize(); /// if it simplifies than it should become the type
View GetView() const;
void SetView(View v);
MSVC_CONSTEXPR APPLE_CONSTEXPR bool IsEquation() const {
bool IsEquation() const {
return (GetView() & View::Equation) != View::None;
}

Expand Down Expand Up @@ -455,7 +451,7 @@ class Valuable
virtual bool HasVa(const Variable&) const;
using var_set_t = std::set<Variable>;
virtual void CollectVa(var_set_t& s) const;
using va_names_t = std::map<std::string_view, Variable>;
using va_names_t = std::map<const std::string, Variable>;
virtual void CollectVaNames(va_names_t& s) const;
va_names_t VaNames() const;
virtual std::shared_ptr<VarHost> getVaHost() const;
Expand All @@ -470,7 +466,7 @@ class Valuable
bool IsMonic() const;

Valuable(const std::string& s, const va_names_t& vaNames, bool itIsOptimized = false);
Valuable(std::string_view str, const va_names_t& vaNames, bool itIsOptimized = false);
Valuable(std::string str, const va_names_t& vaNames, bool itIsOptimized = false);

Valuable operator!() const;
explicit operator bool() const;
Expand Down Expand Up @@ -544,7 +540,7 @@ class Valuable
Valuable IfEq(const Valuable& v, const Valuable& Then,
const Valuable& Else) const; /// returns an expression which equals to @Then when this expression
/// equals to @v param and @Else otherwise

/// <summary>
/// bool is 0 or 1
/// </summary>
Expand Down Expand Up @@ -641,7 +637,8 @@ class Valuable
virtual std::wstring save(const std::wstring&) const;

virtual std::ostream& code(std::ostream& out) const;
std::string OpenCL(const std::string_view& TypeName = "float") const;
std::string OpenCL(const std::string& TypeName = "float") const;
std::string Cuda(const std::string& TypeName = "float") const;
std::string OpenCLuint() const;
va_names_t OpenCLparamVarNames() const;

Expand Down Expand Up @@ -721,21 +718,9 @@ thread_local std::unordered_set<ValueT> OptimizationLoopDetect<ValueT>::LoopDete
} // namespace math
} // namespace omnn

namespace std {

template <class T>
requires std::derived_from<T, ::omnn::math::Valuable>
struct hash<T> {
constexpr size_t operator()(const T& v) const { return static_cast<const omnn::math::Valuable&>(v).Hash(); }
};

} // namespace std

::omnn::math::Valuable operator"" _v(const char* v, std::size_t);
const ::omnn::math::Variable& operator"" _va(const char* v, std::size_t);
//constexpr
::omnn::math::Valuable operator"" _v(unsigned long long v);
//constexpr const ::omnn::math::Valuable& operator"" _const(unsigned long long v);
::omnn::math::Valuable operator"" _v(long double v);


Loading