public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
* [ITA] pocl
@ 2024-01-03  5:14 Takashi Yano
  2024-01-03  5:25 ` Takashi Yano
  0 siblings, 1 reply; 18+ messages in thread
From: Takashi Yano @ 2024-01-03  5:14 UTC (permalink / raw)
  To: cygwin-apps

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

I'd like to adopt the pocl package.

- Update to latest upstream release.
- Enable CUDA support.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

[-- Attachment #2: pocl.cygport --]
[-- Type: text/plain, Size: 1763 bytes --]

inherit clang cmake

NAME="pocl"
VERSION=3.1
RELEASE=1
CATEGORY="Libs"
# The entire code is under MIT
# include/utlist.h which is under BSD-1-Clause (unbundled)
# lib/kernel/vecmath which is under GPL-3.0-or-later OR LGPL-3.0-or-later
LICENSE="MIT, BSD-1-Clause, GPL-3.0-or-later OR LGPL-3.0-or-later"
SUMMARY="OpenCL backend implementation"
DESCRIPTION="Portable Computing Language (pocl) aims to become a MIT-licensed
open source implementation of the OpenCL standard which can be easily adapted
for new targets and devices, both for homogeneous CPU and heterogenous GPUs/
accelerators.  pocl uses Clang as an OpenCL C frontend and LLVM for the kernel
compiler implementation, and as a portability layer."
HOMEPAGE="http://portablecl.org/"
SRC_URI="https://github.com/pocl/pocl/archive/v${VERSION}/pocl-v${VERSION}.tar.gz"

PKG_NAMES="libpocl2 libpocl-common libpocl-devel"
libpocl2_REQUIRES="clang libpocl-common"
libpocl2_CONTENTS="
	usr/bin/cygpocl-2.dll
	usr/bin/libpocl-devices-basic.so
	usr/bin/libpocl-devices-cuda.so
	usr/bin/libpocl-devices-pthread.so
"
libpocl_common_CONTENTS="
	etc/OpenCL/vendors/pocl.icd
	usr/share/doc/pocl/
	usr/share/pocl/
"
libpocl_devel_OBSOLETES="libpoclu-devel"
libpocl_devel_REQUIRES="libpocl-common"
libpocl_devel_CONTENTS="
	usr/bin/poclcc.exe
	usr/lib/libpocl.dll.a
	usr/lib/pkgconfig/pocl.pc
	usr/lib/pocl/cygllvmopencl.dll
	usr/lib/libpocl-devices-basic.dll.a
	usr/lib/libpocl-devices-cuda.dll.a
	usr/lib/libpocl-devices-pthread.dll.a
"


DIFF_EXCLUDES="cl.hpp* testsuite"

CYGCMAKE_ARGS="
	-DPOCL_INSTALL_ICD_VENDORDIR=/etc/OpenCL/vendors
	-DPOCL_ICD_ABSOLUTE_PATH=OFF
	-DENABLE_ICD=ON
	-DENABLE_LIBLLVMOPENCL=ON
	-DENABLE_CUDA=ON
	-DCMAKE_INSTALL_PREFIX=/usr
"

[-- Attachment #3: pocl-3.1-1.src.patch --]
[-- Type: text/plain, Size: 9892 bytes --]

--- origsrc/pocl-3.1/CMakeLists.txt	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/CMakeLists.txt	2024-01-02 08:55:53.483796100 +0900
@@ -817,9 +819,9 @@ endif()
 # constant addrspace variables, and stack protector likely slows
 # down the kernels, so it needs to be determined whether it's worth
 # the trouble.
-set(DEFAULT_KERNEL_CL_FLAGS  "-xcl -fno-stack-protector -fPIC ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
-set(DEFAULT_KERNEL_C_FLAGS "-xc -std=c11 -D__CBUILD__ -fno-math-errno -fno-stack-protector -fPIC ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
-set(DEFAULT_KERNEL_CXX_FLAGS "-xc++ -std=c++11 -fno-stack-protector -fPIC ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
+set(DEFAULT_KERNEL_CL_FLAGS  "-xcl -fno-stack-protector ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
+set(DEFAULT_KERNEL_C_FLAGS "-xc -std=c11 -D__CBUILD__ -fno-math-errno -fno-stack-protector ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
+set(DEFAULT_KERNEL_CXX_FLAGS "-xc++ -std=c++11 -fno-stack-protector ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
 
 
 set(EXTRA_KERNEL_FLAGS "" CACHE STRING "Extra arguments to all kernel compilation commands (defaults to empty)")
@@ -883,11 +885,12 @@ if(ENABLE_SPIR)
   endif()
 
   # required for the wrapper generator
-  if(CMAKE_VERSION VERSION_LESS 3.12.0)
-    find_program(Python3_EXECUTABLE NAMES "python3" REQUIRED)
-  else()
-    find_package(Python3 REQUIRED COMPONENTS Interpreter)
-  endif()
+  #if(CMAKE_VERSION VERSION_LESS 3.12.0)
+  #  find_program(Python3_EXECUTABLE NAMES "python3" REQUIRED)
+  #else()
+  #  find_package(Python3 REQUIRED COMPONENTS Interpreter)
+  #endif()
+  set(Python3_EXECUTABLE "/usr/bin/python3")
 
 endif()
 
--- origsrc/pocl-3.1/cmake/LLVM.cmake	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/cmake/LLVM.cmake	2024-01-02 08:17:57.230897700 +0900
@@ -287,7 +287,7 @@ endforeach()
 
 macro(find_program_or_die OUTPUT_VAR PROG_NAME DOCSTRING)
   find_program(${OUTPUT_VAR}
-    NAMES "${PROG_NAME}${LLVM_BINARY_SUFFIX}${CMAKE_EXECUTABLE_SUFFIX}" "${PROG_NAME}${CMAKE_EXECUTABLE_SUFFIX}"
+    NAMES "${PROG_NAME}${LLVM_BINARY_SUFFIX}" "${PROG_NAME}"
     HINTS "${LLVM_BINDIR}" "${LLVM_CONFIG_LOCATION}" "${LLVM_PREFIX}" "${LLVM_PREFIX_BIN}"
     DOC "${DOCSTRING}"
     NO_CMAKE_PATH
--- origsrc/pocl-3.1/lib/CL/CMakeLists.txt	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/CL/CMakeLists.txt	2024-01-02 08:17:57.233896100 +0900
@@ -294,9 +294,10 @@ set_target_properties("${POCL_LIBRARY_NA
 
 target_link_libraries("${POCL_LIBRARY_NAME}" PRIVATE ${POCL_PRIVATE_LINK_LIST})
 install(TARGETS "${POCL_LIBRARY_NAME}"
-        ARCHIVE DESTINATION ${POCL_INSTALL_PUBLIC_LIBDIR}/static
+        ARCHIVE DESTINATION ${POCL_INSTALL_PUBLIC_LIBDIR}
         COMPONENT "dev"
         LIBRARY DESTINATION ${POCL_INSTALL_PUBLIC_LIBDIR}
+        RUNTIME DESTINATION ${POCL_INSTALL_PUBLIC_BINDIR}
         COMPONENT "lib"
 )
 
--- origsrc/pocl-3.1/lib/CL/devices/cuda/CMakeLists.txt	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/CL/devices/cuda/CMakeLists.txt	2024-01-02 08:54:26.135685300 +0900
@@ -23,8 +23,11 @@
 #
 #=============================================================================
 
-find_package(CUDA REQUIRED)
+find_program(CUDA_EXECUTABLE nvcc REQUIRED)
+get_filename_component(CUDA_TOOLKIT_BIN_DIR "${CUDA_EXECUTABLE}" DIRECTORY)
+set(CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_BIN_DIR}/..")
 message(STATUS "CUDA_TOOLKIT_ROOT_DIR = ${CUDA_TOOLKIT_ROOT_DIR}")
+set(CUDA_INCLUDE_DIRS "${CUDA_TOOLKIT_ROOT_DIR}/include")
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS}")
 include_directories(${LLVM_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/../../../llvmopencl)
@@ -32,7 +36,12 @@ include_directories(${LLVM_INCLUDE_DIRS}
 add_pocl_device_library("pocl-devices-cuda" pocl-cuda.c pocl-cuda.h pocl-ptx-gen.cc pocl-ptx-gen.h)
 target_compile_definitions("pocl-devices-cuda" PRIVATE "-DCUDA_TOOLKIT_ROOT_DIR=\"${CUDA_TOOLKIT_ROOT_DIR}\"")
 if(ENABLE_LOADABLE_DRIVERS)
-  target_link_libraries(pocl-devices-cuda PRIVATE cuda ${POCL_LLVM_LIBS} ${PTHREAD_LIBRARY})
+  if (X86_64)
+    set(CUDA_LIB_ARCH "x64")
+  else()
+    set(CUDA_LIB_ARCH "Win32")
+  endif()
+  target_link_libraries(pocl-devices-cuda PRIVATE ${CUDA_TOOLKIT_ROOT_DIR}/lib/${CUDA_LIB_ARCH}/cuda.lib ${POCL_LLVM_LIBS} ${PTHREAD_LIBRARY})
 endif()
 
 if(ENABLE_CUDNN)
--- origsrc/pocl-3.1/lib/CL/devices/cuda/pocl-cuda.c	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/CL/devices/cuda/pocl-cuda.c	2024-01-02 08:17:57.239883300 +0900
@@ -73,6 +73,10 @@ cudnnHandle_t cudnn;
       }                                                                       \
   }
 
+#ifdef __CYGWIN__
+#undef POCL_DEBUG_MESSAGES
+#endif
+
 typedef struct pocl_cuda_device_data_s
 {
   CUdevice device;
@@ -567,6 +571,9 @@ pocl_cuda_init_queue (cl_device_id devic
 
   queue_data->use_threads
       = !pocl_get_bool_option ("POCL_CUDA_DISABLE_QUEUE_THREADS", 1);
+#ifdef __CYGWIN__
+  queue_data->use_threads = 0; /* Thread does not work in windows CUDA */
+#endif
 
   if (queue_data->use_threads)
     {
@@ -2107,7 +2114,8 @@ pocl_cuda_free_event_data (cl_event even
     {
       pocl_cuda_event_data_t *event_data
           = (pocl_cuda_event_data_t *)event->data;
-      PTHREAD_CHECK (pthread_cond_destroy (&event_data->event_cond));
+      if (event_data->event_cond)
+        PTHREAD_CHECK (pthread_cond_destroy (&event_data->event_cond));
       if (event->queue->properties & CL_QUEUE_PROFILING_ENABLE)
         cuEventDestroy (event_data->start);
       cuEventDestroy (event_data->end);
--- origsrc/pocl-3.1/lib/CL/devices/cuda/pocl-ptx-gen.cc	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/CL/devices/cuda/pocl-ptx-gen.cc	2024-01-02 08:17:57.241882300 +0900
@@ -960,11 +960,19 @@ int pocl_cuda_get_ptr_arg_alignment(cons
                 llvm::dyn_cast<llvm::GetElementPtrInst>(U)) {
           for (auto UU : GEP->users()) {
             if (llvm::StoreInst *SI = llvm::dyn_cast<llvm::StoreInst>(UU)) {
+#ifdef LLVM_OLDER_THAN_15_0
+              Alignments[i] = SI->getAlignment();
+#else
               Alignments[i] = SI->getAlign().value();
+#endif
               break;
             }
             if (llvm::LoadInst *LI = llvm::dyn_cast<llvm::LoadInst>(UU)) {
+#ifdef LLVM_OLDER_THAN_15_0
+              Alignments[i] = LI->getAlignment();
+#else
               Alignments[i] = LI->getAlign().value();
+#endif
               break;
             }
           }
--- origsrc/pocl-3.1/lib/CL/devices/topology/pocl_topology.c	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/CL/devices/topology/pocl_topology.c	2024-01-02 08:17:57.244880900 +0900
@@ -205,7 +205,7 @@ exit_destroy:
 }
 
 // #ifdef HWLOC
-#elif defined(__linux__) || defined(__ANDROID__)
+#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__)
 
 #define L3_CACHE_SIZE "/sys/devices/system/cpu/cpu0/cache/index3/size"
 #define L2_CACHE_SIZE "/sys/devices/system/cpu/cpu0/cache/index2/size"
--- origsrc/pocl-3.1/lib/CL/pocl_build.c	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/CL/pocl_build.c	2024-01-02 10:47:45.937257900 +0900
@@ -690,6 +690,13 @@ compile_and_link_program(int compile_pro
         goto ERROR_CLEAN_OPTIONS;
     }
 
+#ifdef __CYGWIN__
+  if (program->compiler_options == NULL)
+    {
+      program->compiler_options = (char *)malloc(512);
+      program->compiler_options[0] = '\0';
+    }
+#endif
   POCL_MSG_PRINT_LLVM ("building program with options %s\n",
                        program->compiler_options);
 
--- origsrc/pocl-3.1/lib/CL/pocl_util.c	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/CL/pocl_util.c	2024-01-02 08:17:57.247891900 +0900
@@ -59,8 +59,10 @@
 #if defined(__APPLE__)
 #define _DARWIN_C_SOURCE
 #endif
-#ifdef __linux__
+#if defined(__linux__) || defined(__CYGWIN__)
 #define _GNU_SOURCE
+#undef __GNU_VISIBLE
+#define __GNU_VISIBLE 1
 #endif
 #include <dlfcn.h>
 #endif
--- origsrc/pocl-3.1/lib/kernel/host/spir_wrapper32.ll	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/kernel/host/spir_wrapper32.ll	2024-01-02 08:17:57.250886400 +0900
@@ -2663,7 +2663,7 @@ attributes #0 = { nounwind "correctly-ro
 
 !0 = !{i32 1, i32 2}
 !1 = !{!"clang version 6.0.0"}
-!2 = !{i32 1, !"wchar_size", i32 4}
+!2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
 
 
--- origsrc/pocl-3.1/lib/kernel/host/spir_wrapper64.ll	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/kernel/host/spir_wrapper64.ll	2024-01-02 08:17:57.255884700 +0900
@@ -14731,7 +14731,7 @@ attributes #0 = { nounwind "correctly-ro
 
 !0 = !{i32 1, i32 2}
 !1 = !{!"clang version 6.0.0"}
-!2 = !{i32 1, !"wchar_size", i32 4}
+!2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
 
 
--- origsrc/pocl-3.1/lib/llvmopencl/CMakeLists.txt	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/llvmopencl/CMakeLists.txt	2024-01-02 08:17:57.257883900 +0900
@@ -115,9 +115,10 @@ harden("llvmopencl")
 
 # not sure where other platforms get their library linkage list, probably there is
 # way to make this more consistent on different platforms
-if(MSVC)
+if(WIN32 OR CYGWIN)
+  target_link_libraries("llvmopencl" pocl)
   target_link_libraries("llvmopencl" ${POCL_LLVM_LIBS})
-endif(MSVC)
+endif(WIN32 OR CYGWIN)
 
 #target_link_libraries("llvmopencl" "${LLVM_SYSLIBS}")
 endif(ENABLE_LIBLLVMOPENCL)
--- origsrc/pocl-3.1/lib/llvmopencl/DebugHelpers.h	2022-12-05 21:36:08.000000000 +0900
+++ src/pocl-3.1/lib/llvmopencl/DebugHelpers.h	2024-01-02 08:17:57.260886300 +0900
@@ -24,7 +24,7 @@
 #define _POCL_DEBUG_HELPERS_H
 
 #include <string>
-#if _MSC_VER
+#if _MSC_VER || defined(__CYGWIN__)
 #  include <set>
 #endif
 

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-01-15  3:14 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03  5:14 [ITA] pocl Takashi Yano
2024-01-03  5:25 ` Takashi Yano
2024-01-03  7:54   ` Marco Atzeri
2024-01-03  9:29     ` Takashi Yano
2024-01-03 11:38       ` Brian Inglis
2024-01-03 12:00         ` Takashi Yano
2024-01-03 12:26           ` Brian Inglis
2024-01-03 12:42             ` Takashi Yano
2024-01-03 12:30           ` Takashi Yano
2024-01-03 14:08             ` Takashi Yano
2024-01-04  0:55               ` Takashi Yano
2024-01-13 15:48                 ` Jon Turney
2024-01-14 14:57                   ` Takashi Yano
2024-01-14 20:46                     ` Jon Turney
2024-01-15  3:14                       ` Takashi Yano
2024-01-07 12:51       ` Jon Turney
2024-01-07 13:05         ` Takashi Yano
2024-01-08  0:38     ` Andrew Schulman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).