 
 ;; =============== Common vector macros and functions =======================
 
-(defn ^:private vector-equals [modl ^CUBlockVector x ^CUBlockVector y]
+(defn ^:private vector-equals [modl hstream ^CUBlockVector x ^CUBlockVector y]
   (let [cnt (.dim x)]
     (if (< 0 cnt)
       (with-release [equals-kernel (function modl "vector_equals")
                      eq-flag-buf (mem-alloc Integer/BYTES)]
         (memset! eq-flag-buf 0)
-        (launch! equals-kernel (grid-1d cnt)
+        (launch! equals-kernel (grid-1d cnt) hstream
                  (parameters cnt
                              (.buffer x) (.offset x) (.stride x)
                              (.buffer y) (.offset y) (.stride y)

    y)
  BlasPlus
  (subcopy [_ x y kx lx ky]
    (vector-subcopy modl ^CUBlockVector x ^CUBlockVector y kx lx ky)
    y)
  (sum [_ x]
    (vector-sum modl ^CUBlockVector x))
  (imax [_ x]
    (throw (UnsupportedOperationException. "TODO.")))
  (imin [this x]
    (throw (UnsupportedOperationException. "TODO.")))
  (set-all [_ alpha x]
    (vector-set modl (double alpha) ^CUBlockVector x)
    x)
  (axpby [_ alpha x beta y]
    (vector-axpby modl (double alpha) x (double beta) y)
    y))

(deftype FloatVectorEngine [cublas-handle modl]
  BlockEngine
  (equals-block [_ x y]
    (vector-equals modl ^CUBlockVector x ^CUBlockVector y))
  Blas
  (swap [_ x y]
    (vector-method cublas-handle JCublas2/cublasSswap ^CUBlockVector x ^CUBlockVector y)

        (= 0 (aget ^ints (memcpy-host! eq-flag-buf (int-array 1)) 0)))
      (= 0 (.dim y)))))

(defn ^:private vector-subcopy [modl hstream ^CUBlockVector x ^CUBlockVector y kx lx ky]
  (when (< 0 (long lx))
    (with-release [copy-kernel (function modl "vector_copy")]
      (launch! copy-kernel (grid-1d lx) hstream
               (parameters (long lx) (.buffer x) (+ (.offset x) (* (long kx) (.stride x))) (.stride x)
                           (.buffer y) (+ (.offset y) (* (long ky) (.stride y))) (.stride y))))))

(defn ^:private vector-sum [modl hstream ^CUBlockVector x]
  (let [cnt (.dim x)
        block-dim 1024]
    (if (< 0 cnt)
      (with-release [sum-kernel (function modl "vector_sum")
                     sum-reduction-kernel (function modl "sum_reduction")
