try cmake and make. failed now try with julia.
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/CMakeFiles/
|
||||
/soilsimulator-cppcheck-build-dir/
|
||||
/docs/2025
|
||||
/CMakeCache.txt
|
||||
*.zip
|
||||
8
CMakeLists.txt
Normal file
8
CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(VERSION 3.0...3.18.4)
|
||||
project(proj)
|
||||
add_executable(app src/main.cpp)
|
||||
find_package(OpenCLHeaders REQUIRED)
|
||||
find_package(OpenCLICDLoader REQUIRED)
|
||||
find_package(OpenCLHeadersCpp REQUIRED)
|
||||
target_link_libraries(app PRIVATE OpenCL::Headers OpenCL::OpenCL OpenCL::HeadersCpp)
|
||||
26
Makefile
26
Makefile
@ -4,14 +4,15 @@ BUILD_DIR := ./build
|
||||
SRC_DIR := ./src
|
||||
INC_DIR := ./include
|
||||
SHADER_DIR := ./kernels
|
||||
SHADER_EXT := 'cl'
|
||||
|
||||
# Find all the C and C++ files we want to compile
|
||||
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
|
||||
GLSLS := $(shell find $(SHADER_DIR) -name '*.glsl')
|
||||
GLSLS := $(shell find $(SHADER_DIR) -name '*.cl')
|
||||
|
||||
# Prepends BUILD_DIR and appends .o to every src file
|
||||
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
||||
SPIRVS := $(GLSLS:%.glsl=$(BUILD_DIR)/%.sphv)
|
||||
SPIRVS := $(GLSLS:%.$(SHADER_EXT)=$(BUILD_DIR)/%.sphv)
|
||||
|
||||
# String substitution (suffix version without %).
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
@ -26,7 +27,22 @@ LIBS := OpenCL
|
||||
LDFLAGS := $(addprefix -l,$(LIBS))
|
||||
|
||||
# The -MMD and -MP flags together generate Makefiles for us! we use c++ 26
|
||||
CPPFLAGS := -Wall -Wextra $(INC_FLAGS) -MMD -MP -std=c++23
|
||||
CPPFLAGS := -Wall -Wextra $(INC_FLAGS) -MMD -MP -std=c++20
|
||||
|
||||
#set flags for kernel compiling
|
||||
GPU_VENDOR := glxinfo | grep -E "OpenGL vendor | OpenGL renderer" | cut -d" " -f4
|
||||
ARCH := uname -m
|
||||
ifeq ($(GPU_VENDOR),"AMD")
|
||||
CLFLAGS := --target=amdgcn-amd-amdhsa -mcpu=gfx900
|
||||
else ifeq ($(GPU_VENDOR),"NVIDIA")
|
||||
CLFLAGS := --target=nvtpx64-unkown-unkown
|
||||
else ifeq ($(ARCH), "x86_64")
|
||||
CLFLAGS := --target=spirv64
|
||||
else
|
||||
CLFLAGS := --target=spirv32
|
||||
endif
|
||||
|
||||
CXX := clang
|
||||
|
||||
# The final build step.
|
||||
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
|
||||
@ -38,9 +54,9 @@ $(BUILD_DIR)/%.cpp.o: %.cpp $(SPIRVS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ $(LDFLAGS)
|
||||
|
||||
#build the shaders
|
||||
$(SPIRVS): $(GLSL)
|
||||
$(BUILD_DIR)/%.spv: %.cl
|
||||
mkdir -p $(dir $@)
|
||||
glslc $(shaders).glsl $(shaders).spv
|
||||
$(CXX) $(CLFLAGS) -c $< -o $@
|
||||
|
||||
run: $(BUILD_DIR)/$(TARGET_EXEC)
|
||||
./$(BUILD_DIR)/$(TARGET_EXEC)
|
||||
|
||||
38
julia/vector_add.jl
Normal file
38
julia/vector_add.jl
Normal file
@ -0,0 +1,38 @@
|
||||
using OpenCL, pocl_jll
|
||||
|
||||
function vadd(a, b, c)
|
||||
gid = get_global_id(1)
|
||||
@inbounds c[gid] = a[gid] + b[gid]
|
||||
return
|
||||
end
|
||||
|
||||
a = rand(Float32, 50_000)
|
||||
b = rand(Float32, 50_000)
|
||||
|
||||
d_a = CLArray(a)
|
||||
d_b = CLArray(b)
|
||||
d_c = similar(d_a)
|
||||
|
||||
@opencl global_size=size(a) vadd(d_a, d_b, d_c)
|
||||
|
||||
c = Array(d_c)
|
||||
|
||||
@assert a + b ≈ c
|
||||
using OpenCL, pocl_jll
|
||||
|
||||
function vadd(a, b, c)
|
||||
gid = get_global_id(1)
|
||||
@inbounds c[gid] = a[gid] + b[gid]
|
||||
return
|
||||
end
|
||||
|
||||
a = rand(Float32, 50_000)
|
||||
b = rand(Float32, 50_000)
|
||||
|
||||
d_a = CLArray(a)
|
||||
d_b = CLArray(b)
|
||||
d_c = similar(d_a)
|
||||
|
||||
@opencl global_size=size(a) vadd(d_a, d_b, d_c)
|
||||
|
||||
c = Array(d_c)
|
||||
1
kernels/test.cl
Normal file
1
kernels/test.cl
Normal file
@ -0,0 +1 @@
|
||||
kernel void k(){}
|
||||
15
soilsimulator.cppcheck
Normal file
15
soilsimulator.cppcheck
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="1">
|
||||
<builddir>soilsimulator-cppcheck-build-dir</builddir>
|
||||
<platform>unix64</platform>
|
||||
<analyze-all-vs-configs>false</analyze-all-vs-configs>
|
||||
<parser>clang</parser>
|
||||
<check-headers>true</check-headers>
|
||||
<check-unused-templates>true</check-unused-templates>
|
||||
<max-ctu-depth>2</max-ctu-depth>
|
||||
<max-template-recursion>100</max-template-recursion>
|
||||
<addons>
|
||||
<addon>threadsafety</addon>
|
||||
<addon>misra</addon>
|
||||
</addons>
|
||||
</project>
|
||||
31
src/main.cpp
31
src/main.cpp
@ -1,20 +1,24 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
// opencl
|
||||
#include <CL/cl.hpp>
|
||||
// raylib
|
||||
#include <raylib.h>
|
||||
// #include <raylib.h>
|
||||
// sqllite
|
||||
#include <sqlite3.h>
|
||||
//#include <sqlite3.h>
|
||||
|
||||
//#include "include/layers.hpp"
|
||||
|
||||
#include "include/layers.hpp"
|
||||
|
||||
int main(){
|
||||
// import data
|
||||
sqlite3 *db;
|
||||
|
||||
cl::Platform default_platform=select_platform();
|
||||
std::cout << "Using platform: "<<default_platform.getInfo<CL_PLATFORM_NAME>()<<"\n";
|
||||
|
||||
|
||||
// setup opencl pipeline
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
// setup raylib env
|
||||
@ -24,3 +28,16 @@ int main(){
|
||||
// raylib thread (60fps)
|
||||
// opencl sim (every 15 seconds) swap data every 15 seconds
|
||||
}
|
||||
|
||||
cl::Platform select_platform (){
|
||||
|
||||
std::vector<cl::Platform> all_platforms;
|
||||
cl::Platform::get(&all_platforms);
|
||||
if(all_platforms.size() == 0)
|
||||
{
|
||||
std::cout << "No Platforms found. Check OpenCl installation!\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return all_platforms[0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user