<commit_before>(ns simplecl.core
  "Clojure wrappers around OpenCL & JOCL."
  ^{:author "<NAME>"}
  (:import
   [com.jogamp.opencl
    CLResource CLBuffer CLMemory$Mem
    CLCommandQueue CLContext CLKernel
    CLDevice CLDevice$Type
    CLProgram CLProgram$Status
    CLPlatform]
   [com.jogamp.opencl.util Filter]
   [com.jogamp.common.nio Buffers]
   [java.nio Buffer ByteBuffer DoubleBuffer FloatBuffer IntBuffer])
  (:require
   [simplecl.utils :as clu]
   [clojure.java.io :as io]))

;;(set! *warn-on-reflection* true)

(def usage-types
  "A collection of buffer usage types required for `make-buffer`."
  {:readonly CLMemory$Mem/READ_ONLY
   :readwrite CLMemory$Mem/READ_WRITE
   :writeonly CLMemory$Mem/WRITE_ONLY
   :allocate CLMemory$Mem/ALLOCATE_BUFFER
   :copy CLMemory$Mem/COPY_BUFFER
   :use CLMemory$Mem/USE_BUFFER})

(def device-types
  "Common OpenCL device types."
  {:all CLDevice$Type/ALL
   :cpu CLDevice$Type/CPU
   :gpu CLDevice$Type/GPU
   :accelerator CLDevice$Type/ACCELERATOR})

(def build-opts
  "Common OpenCL compiler options"
  {:fast-math "-cl-fast-relaxed-math"
   :enable-mad "-cl-mad-enable"
   :no-signed-zeros "-cl-no-signed-zeros"})

(def build-states
  "Possible OpenCL program build states. Also see `build-status` fn."
  {CLProgram$Status/BUILD_SUCCESS :success
   CLProgram$Status/BUILD_NONE :none
   CLProgram$Status/BUILD_IN_PROGRESS :in-progress
   CLProgram$Status/BUILD_ERROR :error})

;;; Useful pre-defined filters for selecting CL platforms. A number of those
;;; can be passed to `select-platform`. Each filter is implemented as HOF,
;;; takes at least one argument for querying a platform and returns a
;;; com.jogamp.opencl.util.Filter proxy.

(defn platform-has-extension?
  [^String x]
  (proxy [Filter] []
    (accept [^CLPlatform p]
      (.isExtensionAvailable p x))))

(defn platform-has-min-version?
  [major minor]
  (proxy [Filter] []
    (accept [^CLPlatform p]
      (.isAtLeast p major minor))))

(defn platform-vendor-matches?
   [re]
   (proxy [Filter] []
     (accept [^CLPlatform p]
       (not (nil? (re-matches re (.getVendor p)))))))

;; # CL state handling

(def ^:dynamic *platform* nil)
(def ^:dynamic *context* nil)
(def ^:dynamic *device* nil)
(def ^:dynamic *program* nil)
(def ^:dynamic *queue* nil)
(def ^:dynamic *max-worksize* 256)

(defmacro with-platform<commit_msg>updating platform-vendor-matches? fn to use re-find instead of re-matches<commit_after>(ns simplecl.core
  "Clojure wrappers around OpenCL & JOCL."
  ^{:author "<NAME>"}
  (:import
   [com.jogamp.opencl
    CLResource CLBuffer CLMemory$Mem
    CLCommandQueue CLContext CLKernel
    CLDevice CLDevice$Type
    CLProgram CLProgram$Status
    CLPlatform]
   [com.jogamp.opencl.util Filter]
   [com.jogamp.common.nio Buffers]
   [java.nio Buffer ByteBuffer DoubleBuffer FloatBuffer IntBuffer])
  (:require
   [simplecl.utils :as clu]
   [clojure.java.io :as io]))

;;(set! *warn-on-reflection* true)

(def usage-types
  "A collection of buffer usage types required for `make-buffer`."
  {:readonly CLMemory$Mem/READ_ONLY
   :readwrite CLMemory$Mem/READ_WRITE
   :writeonly CLMemory$Mem/WRITE_ONLY
   :allocate CLMemory$Mem/ALLOCATE_BUFFER
   :copy CLMemory$Mem/COPY_BUFFER
   :use CLMemory$Mem/USE_BUFFER})

(def device-types
  "Common OpenCL device types."
  {:all CLDevice$Type/ALL
   :cpu CLDevice$Type/CPU
   :gpu CLDevice$Type/GPU
   :accelerator CLDevice$Type/ACCELERATOR})

(def build-opts
  "Common OpenCL compiler options"
  {:fast-math "-cl-fast-relaxed-math"
   :enable-mad "-cl-mad-enable"
   :no-signed-zeros "-cl-no-signed-zeros"})

(def build-states
  "Possible OpenCL program build states. Also see `build-status` fn."
  {CLProgram$Status/BUILD_SUCCESS :success
   CLProgram$Status/BUILD_NONE :none
   CLProgram$Status/BUILD_IN_PROGRESS :in-progress
   CLProgram$Status/BUILD_ERROR :error})

;;; Useful pre-defined filters for selecting CL platforms. A number of those
;;; can be passed to `select-platform`. Each filter is implemented as HOF,
;;; takes at least one argument for querying a platform and returns a
;;; com.jogamp.opencl.util.Filter proxy.

(defn platform-has-extension?
  [^String x]
  (proxy [Filter] []
    (accept [^CLPlatform p]
      (.isExtensionAvailable p x))))

(defn platform-has-min-version?
  [major minor]
  (proxy [Filter] []
    (accept [^CLPlatform p]
      (.isAtLeast p major minor))))

(defn platform-vendor-matches?
   [re]
   (proxy [Filter] []
     (accept [^CLPlatform p]
       (not (nil? (re-find re (.getVendor p)))))))

;; # CL state handling

(def ^:dynamic *platform* nil)
(def ^:dynamic *context* nil)
(def ^:dynamic *device* nil)
(def ^:dynamic *program* nil)
(def ^:dynamic *queue* nil)
(def ^:dynamic *max-worksize* 256)

(defmacro with-platform
{'fraction_non_alphanumeric': 0.12975814931650895, 'fraction_numerical': 0.0012618296529968455, 'mean_word_length': 4.097534833869239, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3671887', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1608, 'n_words': 435}