Adding some Lisp code to help keep the triple store environment in sync with the TwitLogic Java components.

(enable-!-reader)

;;;; display ;;;;;;;;;;;;;;;;;;;;;;;;;;;

(in-package :triple-store-user)

(defun show (r)
    (print-triples
        (get-triples-list :s r) :format :ntriple))
(defun show-in (r)
    (print-triples
        (get-triples-list :o r) :format :ntriple))

(defun text (s &optional limit)
    (print-triples (freetext-get-triples s)
    :limit (if (eq limit ()) 10 limit)))

;;;; ranking ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun print-ranking (table)
    (let (seq)
        (maphash
            (lambda (k v)
	        (push (cons k v) seq))
	    table)
        (let ((sorted (sort seq '> :key 'cdr)))
            (dolist (e sorted)
	        (format t "~%~70a ~d" (part->string (car e)) (cdr e))))))

(defun rank (upi-generator &key size)
    ;; 10,000 seems to be a good default size for the hash table.
    ;; It does not cause any appreciable delay.
    (let ((table (make-upi-hash-table :size (if (eq () size) 10000 size))))
        (funcall upi-generator
	    (lambda (upi) (incf (gethash upi table 0))))
	(print-ranking table)))

(use-package :sparql)
(defun rank-from-sparql (query &key size)
    (rank
        (lambda (visit)
	    (dolist
	        (e (run-sparql query :results-format :arrays))
		(funcall visit (elt e 0)))))
	:size size)

(defun rankvector-add-weight (vector key amount)
    (setf (gethash key vector) (+ amount (gethash key vector 0.0))))
(defun rankvector-new-vector (&key size)
    (make-upi-hash-table
        :size (if (eq () size) 10000 size)))

;;;; ranking applications ;;;;;;;;;;;;;;

(defun rank-type-of-subject-by-property (property)
    (rank
        (lambda (visitor)
            (iterate-cursor (tr (get-triples :p property))
	        (iterate-cursor (tr2 (get-triples :s (subject tr) :p !rdf:type))
	            (funcall visitor (object tr2)))))))
(defun rank-type-of-object-by-property (property)
    (rank
        (lambda (visitor)
            (iterate-cursor (tr (get-triples :p property))
	        (iterate-cursor (tr2 (get-triples :s (object tr) :p !rdf:type))
	            (funcall visitor (object tr2)))))))

;;;; geolocation ;;;;;;;;;;;;;;;;;;;;;;;

(enable-!-reader)
(register-namespace "pos" "http://www.w3.org/2003/01/geo/wgs84_pos#")
(register-namespace "geo" "http://franz.com/ns/allegrograph/3.0/geospatial/fn/")
;;(register-namespace "geo" "http://example.org/geo#")

(defun geo-setup ()
    ;; -> http://franz.com/ns/allegrograph/3.0/geospatial/spherical/miles/-180.0/180.0/-90.0/90.0/5.0
    (defparameter *lat-lon-5*   (register-latitude-striping-in-miles 5.0s0)) ;2
    ;; -> http://franz.com/ns/allegrograph/3.0/geospatial/spherical/miles/-180.0/180.0/-90.0/90.0/100.0
    (defparameter *lat-lon-100* (register-latitude-striping-in-miles 100.0s0)) ;3
    (defparameter *geo-properties*
        '((!pos:long :longitude)
          (!pos:lat :latitude)))
    (add-geospatial-subtype-to-db *lat-lon-5*) ; 4
    (add-geospatial-subtype-to-db *lat-lon-100*)) ; 5

(defun get-latitude (r)
    (let (default)
        (iterate-cursor (tr (get-triples :s r :p !pos:lat))
            (handler-case
	        (return-from get-latitude
	            (+ 0.0 (read-from-string (upi->value (object tr)))))
	        (type-error (e) ())
		(reader-error (e) ())))
    default))
(defun get-longitude (r)
    (let (default)
        (iterate-cursor (tr (get-triples :s r :p !pos:long))
            (handler-case
	        (return-from get-longitude
	            (+ 0.0 (read-from-string (upi->value (object tr)))))
	        (type-error (e) ())
		(reader-error (e) ())))
    default))

;;
(defun normalize-latitude (lat)
    (if (eq nil lat) nil
        (if (< lat -90) nil
            (if (> lat 90) nil lat))))

;;
(defun normalize-longitude (lon)
    (if (eq nil lon) nil
        (if (< lon -360) nil
            (if (> lon 360) nil
	        (if (< lon -180) (+ 360 lon)
	            (if (> lon 180) (- 360 lon) lon))))))

;; geo-index a resource with valid pos:long and pos:lat values
(defun index-geopoint (geopoint)
    (let (
        (lat (normalize-latitude (get-latitude geopoint)))
	(lon (normalize-longitude (get-longitude geopoint))))
	(when (and (not (eq nil lat)) (not (eq nil lon)))
	    (with-temp-upi (upi)
	        (add-triple geopoint
	            !geo:isAt5
                    (longitude-latitude->upi *lat-lon-5* lon lat upi)
		    :g !geo:graph)
                (add-triple geopoint
                    !geo:isAt100
                    (longitude-latitude->upi *lat-lon-100* lon lat upi)
		    :g !geo:graph)))))

(defun count-all-geopoints ()
    (defparameter *count* 0)
    (iterate-cursor (tr (get-triples :p !pos:lat))
        (let ((geopoint (subject tr)))
            (let (
	        (lat (normalize-latitude (get-latitude geopoint)))
	        (lon (normalize-longitude (get-longitude geopoint))))
	        (when (and (not (eq nil lat)) (not (eq nil lon)))
	            (setf *count* (+ 1 *count*))))))
    *count*)

(defun index-all-geopoints ()
    (defparameter *geoindexing-in-progress* t)
    ;; Anything with a pos:lat is considered a geopoint
    (iterate-cursor (tr (get-triples :p !pos:lat))
        (index-geopoint (subject tr)))
    (index-new-triples)
    (defparameter *geoindexing-in-progress* nil))

(defun delete-all-geo-triples ()
    (delete-triples :g !geo:graph))

;; Note: there are two triples per geopoint
(defun count-geo-triples ()
    (count-cursor (get-triples :g !geo:graph)))

;;;;;;;;;;;;

;(defun starts-with (s prefix)
;    (if (> (length prefix) (length s))
;        nil
;	(string= prefix (subseq s 0 (length prefix)))))
;
;(defun host-part (uri)
;    (if (starts-with uri "http://")
;        (let ((s (subseq s 7)))
;
;	nil))

;;;;;;;;;;;

;;;; scp ~/Dropbox/work/internships/Franz/btc/btc.cl josh@rambo:/net/gemini/home/josh

(defun cheating ()
  (let ((ht (make-upi-hash-table :size 10000000))
	(freqht (make-upi-hash-table :size 1000000)))
    (time
     (iterate-cursor (tr (get-triples :p !<http://www.w3.org/2003/01/geo/wgs84_pos#lat>))
       (setf (gethash (subject tr) ht) t)))
    (time
     (iterate-cursor (tr (get-triples :p !rdf:type))
       (when (gethash (subject tr) ht)
	 (incf (gethash (object tr) freqht 0)))))
    (setf *ht* ht *freqht* freqht) ; for later analysis
    (time
     (let ((res nil))
       (maphash
	(lambda (k v)
	  (push (cons k v) res))
	freqht)
       (print (length res))
       (setf res (sort res '> :key 'cdr))
       (dolist (e res)
	 (when (> (cdr e) 50)
	   (format t "~%~70s    ~8d" (part->string (car e)) (cdr e))))))))

(register-namespace "pos" "http://www.w3.org/2003/01/geo/wgs84_pos#")

(defun newestcheat ()
(let ((ht (make-upi-hash-table :size 10000000))
      (freqht (make-upi-hash-table :size 1000000)))
    (iterate-cursor (tr (get-triples :p !pos:lat))
        (setf (gethash (subject tr) ht) t))
    (iterate-cursor (tr (get-triples :p !rdf:type))
        (when (gethash (subject tr) ht)
            (incf (gethash (object tr) freqht 0))))
    (print-ranking freqht)))

(register-namespace "pos" "http://www.w3.org/2003/01/geo/wgs84_pos#")

(defun newcheat ()
    (rank
        (lambda (visit)
            (iterate-cursor (tr (get-triples :p !pos:lat))
                (iterate-cursor (f (get-triples :s (subject tr) :p !rdf:type))
	            (funcall visit (object f)))))))

error: pathspec 'src/main/lisp/btc.cl' did not match any file(s) known to git


Replaced curand by mwc64x

Replaced curand by mwc64x

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/HongjianLi/idock.git/'


Delete a4 copy.cl

Delete a4 copy.cl

copied over by mistake.

error: pathspec 'a4/a4' did not match any file(s) known to git
error: pathspec 'copy.cl' did not match any file(s) known to git


Clarify the reason of bugs... Seems that we will finish the work in near future The issues are written in clbpt.cl. Search "ISSUE" to find them.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/CLBplustree/CLBplustree.git/'


Added dummy kernel Hello.cl and commented out all buffer specific code in Convolution.cpp

kernel
void hello_world_kernel (global const float *a,
						global const float *b,
						global float *c,
						const int sz) {

	 const size_t tid = get_global_id(0);

	 if(tid < sz) {
		 c[tid] =  a[tid] + b[tid];
	 }
}

error: pathspec 'src/Hello.cl' did not match any file(s) known to git


Added test script for macros

Added test script for macros

(do
  (defn f (x)
     (do
        (gdefn g (x)
            (* x x x)
        )

        (print x)
        (+ x x (g 4))
     )
  )

  ; Neues define-macro-expand --> erzeugt Code zur Compile/MacroExpand Zeit ?

  (defn foreach (container fcn)
     (do
	   (def i 0)
	   (def max (len container))
	   (while (< i max)
	     (do
		   (apply fcn (list (nth i container)))
		   (setf i (+ i 1))
		 )
	   )
	 )
  )

  (defn make-args-string (count)
    (do
	  (def s "this ")
	  (def i 0)
	  (while (< i count)
	    (do
			(setf s (+ s "p" (string i)))
			(setf s (+ s " "))
			(setf i (+ i 1))
		)
	  )
	  (return s)
	)
  )

  (defn make-args (count)
    (do
	  (def s "this ")
	  (def i 0)
	  (while (< i count)
	    (do
			(setf s (+ s "p" (string i)))
			(setf s (+ s " "))
			(setf i (+ i 1))
		)
	  )
	  (return s)
	)
  )

  (defn make-args-no-this (count)
    (do
	  (def s "")
	  (def i 0)
	  (while (< i count)
	    (do
			(setf s (+ s "p" (string i)))
			(setf s (+ s " "))
			(setf i (+ i 1))
		)
	  )
	  (return s)
	)
  )

  (define-macro create-native-old
      (lambda (lisp-name full-class-name)
        (do
            ; inspect class and generate for all public properties and methods method stubs
            (gdefn (sym (string "create-" lisp-name)) () (call full-class-name))

			(def methods (native-methods full-class-name))
			(print "length=" (len methods))
			(foreach methods (lambda (methodNameAndArgCount)
			   (do
			     (def methodName (first methodNameAndArgCount))
			     (def methodArgsCount (nth 1 methodNameAndArgCount))
			     (print "create method=" methodName methodCount (make-args-string methodArgsCount))

				 (if (= methodArgsCount 0)
				   (gdefn (sym (string lisp-name "-" methodName)) (this) (call this methodName))
				   (nop))
				 (if (> methodArgsCount 0)
				   (gdefn
					  (sym (string lisp-name "-" methodName))
						(macro-expand (make-args methodArgsCount))
; todo --> list flach klopfen !
						(call (append (list this methodName) (macro-expand (make-args-no-this methodArgsCount))))
		           )
				   ;(gdefn (sym (string lisp-name "-" methodName)) (this p1) (call this methodName p1))
				   (nop))
			   )
			))
        )
     )
  )

  (define-macro-expand create-method (method-name arg-count)
      (do
	      (def args (make-args-no-this arg-count))
          (return `(gdefn method-name ,@args))
	  )
  )

  (define-macro-expand create-native
      (lisp-name full-class-name)
        (do
            ; inspect class and generate for all public properties and methods method stubs
            (gdefn (sym (string "create-" lisp-name)) () (call full-class-name))

			(def methods (native-methods full-class-name))
			(print "length=" (len methods))
			(foreach methods (lambda (methodNameAndArgCount)
			   (do
                 (print "arg=" methodNameAndArgCount)
			     (def methodName (first methodNameAndArgCount))
			     (def methodArgsCount (nth 1 methodNameAndArgCount))
			     (print "create method=" methodName methodCount (make-args-string methodArgsCount))

				 (if (= methodArgsCount 0)
				   (gdefn (sym (string lisp-name "-" methodName)) (this) (call this methodName))
				   (nop))
				 (if (> methodArgsCount 0)
				   (gdefn
					  (sym (string lisp-name "-" methodName))        ; function name
						(macro-expand (make-args methodArgsCount))   ; formal arguments
; todo --> list flach klopfen !
                          ; make something like: (call obj "Function-Name" argument1 argument2 ...)
						  (call (append (list this methodName) (macro-expand (make-args-no-this methodArgsCount))))      ; code
		           )
				   ;(gdefn (sym (string lisp-name "-" methodName)) (this p1) (call this methodName p1))
				   (nop))
			   )
			))
        )
  )

  (print (make-args-string 8))
  (def s1 "blub")
  (def s2 "hallo")
  (def sum (+ s1 s2))
  (print blubhallo)
  (print "sum=" sum)
  (print "s1=" s1)
  (print "s2=" s2)
  (print (f 5))
  (print (g 4))
  (print "try macro...")
  (gdefn (sym (string "create-" "ListX")) () (call "System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"))
  (print "....")
  (create-native "List" "System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")
  (print "---")
  (print "(1)")
  (def obj (create-List))
  (print "---" obj)
  (print (native-methods obj))
  (print "try add...")
  (call obj "Add" 5)
  (call obj "Add" 6)
  (print "added elements phase 1")
  (List-Add obj 7)
  (print "added elements")
  (List-get_Count obj)
  (print "added elements #2")
  (print (call obj "get_Count"))
  (print "(2)")
  (print obj)
)

error: pathspec 'CsLisp/Scripts/create-native.cl' did not match any file(s) known to git


Common Lisp Sieve

Common Lisp Sieve

The sieve of Eratosthenes for the language 'common lisp'.

error: pathspec 'math/sieve' did not match any file(s) known to git
error: pathspec 'of' did not match any file(s) known to git
error: pathspec 'eratosthenes/common_lisp/sieve.cl' did not match any file(s) known to git


lstm opencl added kernels for SigmoidNeuron

__kernel void kernel_activate(__global const float* values, __global float* out, int n) {
    int i = get_global_id(0);
    if (i >= n)
        return;

    out[i] = activate(values[i]);
}

__kernel void kernel_derivative(__global const float* values, __global float* out, int n) {
    int i = get_global_id(0);
    if (i >= n)
        return;

    out[i] = derivative(values[i]);
}

float derivative(float x) {
    float act = activate(x);
	return act * (1.0 - act);
}

float activate(float x) {
    return 1.0f / (1.0f + expf(-x);
}

error: pathspec 'nars_lab/src/main/java/nars/rl/lstm/opencl/SigmoidNeuron.cl' did not match any file(s) known to git


Correct rotate/shift test cases for scalar arguments

// TESTING: <<
// TESTING: >>
// TESTING: rotate

#define IMPLEMENT_BODY_G(NAME, BODY, SIZE, GTYPE, SGTYPE, UGTYPE, SUGTYPE)  \
  void NAME##_##GTYPE()                                                     \
  {                                                                         \
    typedef GTYPE gtype;                                                    \
    typedef SGTYPE sgtype;                                                  \
    typedef UGTYPE ugtype;                                                  \
    typedef SUGTYPE sugtype;                                                \
    char const *const typename = #GTYPE;                                    \
    const int vecsize = SIZE;                                               \
    BODY;                                                                   \
  }
#define DEFINE_BODY_G(NAME, EXPR)                                           \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, char    , char  , uchar   , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, char2   , char  , uchar2  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, char3   , char  , uchar3  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, char4   , char  , uchar4  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, char8   , char  , uchar8  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, char16  , char  , uchar16 , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, uchar   , uchar , uchar   , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, uchar2  , uchar , uchar2  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, uchar3  , uchar , uchar3  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, uchar4  , uchar , uchar4  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, uchar8  , uchar , uchar8  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, uchar16 , uchar , uchar16 , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, short   , short , ushort  , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, short2  , short , ushort2 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, short3  , short , ushort3 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, short4  , short , ushort4 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, short8  , short , ushort8 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, short16 , short , ushort16, ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, ushort  , ushort, ushort  , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, ushort2 , ushort, ushort2 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, ushort3 , ushort, ushort3 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, ushort4 , ushort, ushort4 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, ushort8 , ushort, ushort8 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, ushort16, ushort, ushort16, ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, int     , int   , uint    , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, int2    , int   , uint2   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, int3    , int   , uint3   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, int4    , int   , uint4   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, int8    , int   , uint8   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, int16   , int   , uint16  , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, uint    , uint  , uint    , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, uint2   , uint  , uint2   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, uint3   , uint  , uint3   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, uint4   , uint  , uint4   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, uint8   , uint  , uint8   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, uint16  , uint  , uint16  , uint  )      \
  __IF_INT64(                                                               \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, long    , long  , ulong   , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, long2   , long  , ulong2  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, long3   , long  , ulong3  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, long4   , long  , ulong4  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, long8   , long  , ulong8  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, long16  , long  , ulong16 , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, ulong   , ulong , ulong   , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, ulong2  , ulong , ulong2  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, ulong3  , ulong , ulong3  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, ulong4  , ulong , ulong4  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, ulong8  , ulong , ulong8  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, ulong16 , ulong , ulong16 , ulong ))

#define CALL_FUNC_G(NAME)                       \
  NAME##_char    ();                            \
  NAME##_char2   ();                            \
  NAME##_char3   ();                            \
  NAME##_char4   ();                            \
  NAME##_char8   ();                            \
  NAME##_char16  ();                            \
  NAME##_uchar   ();                            \
  NAME##_uchar2  ();                            \
  NAME##_uchar3  ();                            \
  NAME##_uchar4  ();                            \
  NAME##_uchar8  ();                            \
  NAME##_uchar16 ();                            \
  NAME##_short   ();                            \
  NAME##_short2  ();                            \
  NAME##_short3  ();                            \
  NAME##_short4  ();                            \
  NAME##_short8  ();                            \
  NAME##_short16 ();                            \
  NAME##_ushort  ();                            \
  NAME##_ushort2 ();                            \
  NAME##_ushort3 ();                            \
  NAME##_ushort4 ();                            \
  NAME##_ushort8 ();                            \
  NAME##_ushort16();                            \
  NAME##_int     ();                            \
  NAME##_int2    ();                            \
  NAME##_int3    ();                            \
  NAME##_int4    ();                            \
  NAME##_int8    ();                            \
  NAME##_int16   ();                            \
  NAME##_uint    ();                            \
  NAME##_uint2   ();                            \
  NAME##_uint3   ();                            \
  NAME##_uint4   ();                            \
  NAME##_uint8   ();                            \
  NAME##_uint16  ();                            \
  __IF_INT64(                                   \
  NAME##_long    ();                            \
  NAME##_long2   ();                            \
  NAME##_long3   ();                            \
  NAME##_long4   ();                            \
  NAME##_long8   ();                            \
  NAME##_long16  ();                            \
  NAME##_ulong   ();                            \
  NAME##_ulong2  ();                            \
  NAME##_ulong3  ();                            \
  NAME##_ulong4  ();                            \
  NAME##_ulong8  ();                            \
  NAME##_ulong16 ();)

#if __has_extension(c_generic_selections)
# define is_floating(T) _Generic((T)0, float: 1, double: 1, default: 0)
#else
# define is_floating(T) ((T)0.1f > (T)0.0f)
#endif
#define is_signed(T)   ((T)-1 < (T)+1)
#define count_bits(T)  (CHAR_BIT * sizeof(T))

DEFINE_BODY_G
(test_rotate,
 ({
   _CL_STATIC_ASSERT(sgtype, !is_floating(sgtype));
   int patterns[] = {0x01, 0x80, 0x77, 0xee};
   for (int p=0; p<4; ++p) {
     int const bits = count_bits(sgtype);
     int array[64];
     for (int b=0; b<bits; ++b) {
       array[b] = !!(patterns[p] & (1 << (b & 7)));
     }
     typedef union {
       gtype  v;
       sgtype s[16];
     } Tvec;
     for (int shiftbase=0; shiftbase<=bits; ++shiftbase) {
       for (int shiftoffset=0; shiftoffset<(vecsize==1?1:4); ++shiftoffset) {
         Tvec shift;
         Tvec val;
         Tvec shl, shr, rot;
         for (int n=0; n<vecsize; ++n) {
           shift.s[n] = shiftbase + n*shiftoffset;
           // Scalar shift operations undergo integer promotion, i.e.
           // the arguments are converted to int if they are smaller
           // than int. Therefore, overflowing shift counts are
           // interpreted differently.
           if ((vecsize==1) & (sizeof(sgtype) < sizeof(int))) {
             shift.s[n] &= bits-1;
           }
           val.s[n] = 0;
           shl.s[n] = 0;
           shr.s[n] = 0;
           rot.s[n] = 0;
           for (int b=bits; b>=0; --b) {
             int bl = b - (shift.s[n] & (bits-1));
             int br = b + (shift.s[n] & (bits-1));
             int sign = is_signed(sgtype) ? array[bits-1] : 0;
             val.s[n] = (val.s[n] << 1) | array[b];
             shl.s[n] = (shl.s[n] << 1) | (bl < 0 ? 0 : array[bl]);
             shr.s[n] = (shr.s[n] << 1) | (br >= bits ? sign : array[br]);
             rot.s[n] = (rot.s[n] << 1) | array[bl & (bits-1)];
           }
         }
         Tvec res;
         bool equal;
         /* shift left */
         res.v = val.v << shift.v;
         equal = true;
         for (int n=0; n<vecsize; ++n) {
           equal = equal && res.s[n] == shl.s[n];
         }
         if (!equal) {
           for (int n=0; n<vecsize; ++n) {
             printf("FAIL: shift left (<<) type=%s pattern=0x%x shiftbase=%d shiftoffset=%d val=0x%08x count=0x%08x res=0x%08x good=0x%08x\n",
                    typename, patterns[p], shiftbase, shiftoffset,
                    (uint)val.s[n], (uint)shift.s[n],
                    (uint)res.s[n], (uint)shl.s[n]);
           }
           return;
         }
         /* shift right */
         res.v = val.v >> shift.v;
         equal = true;
         for (int n=0; n<vecsize; ++n) {
           equal = equal && res.s[n] == shr.s[n];
         }
         if (!equal) {
           for (int n=0; n<vecsize; ++n) {
             printf("FAIL: shift right (>>) type=%s pattern=0x%x shiftbase=%d shiftoffset=%d val=0x%08x count=0x%08x res=0x%08x good=0x%08x\n",
                    typename, patterns[p], shiftbase, shiftoffset,
                    (uint)val.s[n], (uint)shift.s[n],
                    (uint)res.s[n], (uint)shr.s[n]);
           }
           return;
         }
         /* rotate */
         res.v = rotate(val.v, shift.v);
         equal = true;
         for (int n=0; n<vecsize; ++n) {
           equal = equal && res.s[n] == rot.s[n];
         }
         if (!equal) {
           for (int n=0; n<vecsize; ++n) {
             printf("FAIL: rotate type=%s pattern=0x%x shiftbase=%d shiftoffset=%d val=0x%08x count=0x%08x res=0x%08x good=0x%08x\n",
                    typename, patterns[p], shiftbase, shiftoffset,
                    (uint)val.s[n], (uint)shift.s[n],
                    (uint)res.s[n], (uint)rot.s[n]);
           }
           return;
         }
       }
     }
   }
 })
 )

kernel void test_rotate()
{
  CALL_FUNC_G(test_rotate)
}

// TESTING: <<
// TESTING: >>
// TESTING: rotate

#define IMPLEMENT_BODY_G(NAME, BODY, SIZE, GTYPE, SGTYPE, UGTYPE, SUGTYPE)  \
  void NAME##_##GTYPE()                                                     \
  {                                                                         \
    typedef GTYPE gtype;                                                    \
    typedef SGTYPE sgtype;                                                  \
    typedef UGTYPE ugtype;                                                  \
    typedef SUGTYPE sugtype;                                                \
    char const *const typename = #GTYPE;                                    \
    const int vecsize = SIZE;                                               \
    BODY;                                                                   \
  }
#define DEFINE_BODY_G(NAME, EXPR)                                           \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, char    , char  , uchar   , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, char2   , char  , uchar2  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, char3   , char  , uchar3  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, char4   , char  , uchar4  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, char8   , char  , uchar8  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, char16  , char  , uchar16 , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, uchar   , uchar , uchar   , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, uchar2  , uchar , uchar2  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, uchar3  , uchar , uchar3  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, uchar4  , uchar , uchar4  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, uchar8  , uchar , uchar8  , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, uchar16 , uchar , uchar16 , uchar )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, short   , short , ushort  , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, short2  , short , ushort2 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, short3  , short , ushort3 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, short4  , short , ushort4 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, short8  , short , ushort8 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, short16 , short , ushort16, ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, ushort  , ushort, ushort  , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, ushort2 , ushort, ushort2 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, ushort3 , ushort, ushort3 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, ushort4 , ushort, ushort4 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, ushort8 , ushort, ushort8 , ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, ushort16, ushort, ushort16, ushort)      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, int     , int   , uint    , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, int2    , int   , uint2   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, int3    , int   , uint3   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, int4    , int   , uint4   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, int8    , int   , uint8   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, int16   , int   , uint16  , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, uint    , uint  , uint    , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, uint2   , uint  , uint2   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, uint3   , uint  , uint3   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, uint4   , uint  , uint4   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, uint8   , uint  , uint8   , uint  )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, uint16  , uint  , uint16  , uint  )      \
  __IF_INT64(                                                               \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, long    , long  , ulong   , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, long2   , long  , ulong2  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, long3   , long  , ulong3  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, long4   , long  , ulong4  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, long8   , long  , ulong8  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, long16  , long  , ulong16 , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  1, ulong   , ulong , ulong   , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  2, ulong2  , ulong , ulong2  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  3, ulong3  , ulong , ulong3  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  4, ulong4  , ulong , ulong4  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR,  8, ulong8  , ulong , ulong8  , ulong )      \
  IMPLEMENT_BODY_G(NAME, EXPR, 16, ulong16 , ulong , ulong16 , ulong ))

#define CALL_FUNC_G(NAME)                       \
  NAME##_char    ();                            \
  NAME##_char2   ();                            \
  NAME##_char3   ();                            \
  NAME##_char4   ();                            \
  NAME##_char8   ();                            \
  NAME##_char16  ();                            \
  NAME##_uchar   ();                            \
  NAME##_uchar2  ();                            \
  NAME##_uchar3  ();                            \
  NAME##_uchar4  ();                            \
  NAME##_uchar8  ();                            \
  NAME##_uchar16 ();                            \
  NAME##_short   ();                            \
  NAME##_short2  ();                            \
  NAME##_short3  ();                            \
  NAME##_short4  ();                            \
  NAME##_short8  ();                            \
  NAME##_short16 ();                            \
  NAME##_ushort  ();                            \
  NAME##_ushort2 ();                            \
  NAME##_ushort3 ();                            \
  NAME##_ushort4 ();                            \
  NAME##_ushort8 ();                            \
  NAME##_ushort16();                            \
  NAME##_int     ();                            \
  NAME##_int2    ();                            \
  NAME##_int3    ();                            \
  NAME##_int4    ();                            \
  NAME##_int8    ();                            \
  NAME##_int16   ();                            \
  NAME##_uint    ();                            \
  NAME##_uint2   ();                            \
  NAME##_uint3   ();                            \
  NAME##_uint4   ();                            \
  NAME##_uint8   ();                            \
  NAME##_uint16  ();                            \
  __IF_INT64(                                   \
  NAME##_long    ();                            \
  NAME##_long2   ();                            \
  NAME##_long3   ();                            \
  NAME##_long4   ();                            \
  NAME##_long8   ();                            \
  NAME##_long16  ();                            \
  NAME##_ulong   ();                            \
  NAME##_ulong2  ();                            \
  NAME##_ulong3  ();                            \
  NAME##_ulong4  ();                            \
  NAME##_ulong8  ();                            \
  NAME##_ulong16 ();)

#if __has_extension(c_generic_selections)
# define is_floating(T) _Generic((T)0, float: 1, double: 1, default: 0)
#else
# define is_floating(T) ((T)0.1f > (T)0.0f)
#endif
#define is_signed(T)   ((T)-1 < (T)+1)
#define count_bits(T)  (CHAR_BIT * sizeof(T))

DEFINE_BODY_G
(test_rotate,
 ({
   _CL_STATIC_ASSERT(sgtype, !is_floating(sgtype));
   int patterns[] = {0x01, 0x80, 0x77, 0xee};
   for (int p=0; p<4; ++p) {
     int const bits = count_bits(sgtype);
     int array[64];
     for (int b=0; b<bits; ++b) {
       array[b] = !!(patterns[p] & (1 << (b & 7)));
     }
     typedef union {
       gtype  v;
       sgtype s[16];
     } Tvec;
     for (int shiftbase=0; shiftbase<=bits; ++shiftbase) {
       for (int shiftoffset=0; shiftoffset<(vecsize==1?1:4); ++shiftoffset) {
         Tvec shift;
         Tvec val;
         Tvec shl, shr, rot;
         for (int n=0; n<vecsize; ++n) {
           shift.s[n] = shiftbase + n*shiftoffset;
           val.s[n]  = 0;
           shl.s[n]  = 0;
           shr.s[n]  = 0;
           rot.s[n]  = 0;
           for (int b=bits; b>=0; --b) {
             int bl = b - (shift.s[n] & (bits-1));
             int br = b + (shift.s[n] & (bits-1));
             int sign = is_signed(sgtype) ? array[bits-1] : 0;
             val.s[n] = (val.s[n] << 1) | array[b];
             shl.s[n] = (shl.s[n] << 1) | (bl < 0 ? 0 : array[bl]);
             shr.s[n] = (shr.s[n] << 1) | (br >= bits ? sign : array[br]);
             rot.s[n] = (rot.s[n] << 1) | array[bl & (bits-1)];
           }
         }
         Tvec res;
         bool equal;
         /* shift left */
         res.v = val.v << shift.v;
         equal = true;
         for (int n=0; n<vecsize; ++n) {
           equal = equal && res.s[n] == shl.s[n];
         }
         if (!equal) {
           for (int n=0; n<vecsize; ++n) {
             printf("FAIL: shift left (<<) type=%s pattern=0x%x shiftbase=%d shiftoffset=%d val=0x%08x count=0x%08x res=0x%08x good=0x%08x\n",
                    typename, patterns[p], shiftbase, shiftoffset,
                    (uint)val.s[n], (uint)shift.s[n],
                    (uint)res.s[n], (uint)shl.s[n]);
           }
           return;
         }
         /* shift right */
         res.v = val.v >> shift.v;
         equal = true;
         for (int n=0; n<vecsize; ++n) {
           equal = equal && res.s[n] == shr.s[n];
         }
         if (!equal) {
           for (int n=0; n<vecsize; ++n) {
             printf("FAIL: shift right (>>) type=%s pattern=0x%x shiftbase=%d shiftoffset=%d val=0x%08x count=0x%08x res=0x%08x good=0x%08x\n",
                    typename, patterns[p], shiftbase, shiftoffset,
                    (uint)val.s[n], (uint)shift.s[n],
                    (uint)res.s[n], (uint)shr.s[n]);
           }
           return;
         }
         /* rotate */
         res.v = rotate(val.v, shift.v);
         equal = true;
         for (int n=0; n<vecsize; ++n) {
           equal = equal && res.s[n] == rot.s[n];
         }
         if (!equal) {
           for (int n=0; n<vecsize; ++n) {
             printf("FAIL: rotate type=%s pattern=0x%x shiftbase=%d shiftoffset=%d val=0x%08x count=0x%08x res=0x%08x good=0x%08x\n",
                    typename, patterns[p], shiftbase, shiftoffset,
                    (uint)val.s[n], (uint)shift.s[n],
                    (uint)res.s[n], (uint)rot.s[n]);
           }
           return;
         }
       }
     }
   }
 })
 )

kernel void test_rotate()
{
  CALL_FUNC_G(test_rotate)
}


an old version of dirtyIFU.cl that quickly constructs a GMOS IFU cube to verify QA during observing.

procedure dirtyIFU (inimages)

# Quick and dirty reduction of IFU data
#   Purpose: verify seeing, verify centering, verify signal
#            i.e. morning after sanity checks

char    inimages    {prompt="List of raw input science frame"}
char    gcalflats   {"", prompt="List of raw GCALflats"}
char    rawpath     {"/net/archie/staging/perm/", prompt="Location of raw data"}
char    flat        {"", prompt="Already reduced flat"}
char    dispscript  {"dispscript.cl", prompt="Script to display reduced output"}
char    slits       {"both", prompt="Slit(s) used"}
char    logfile     {"dirtyIFU.log", prompt="Name of logfile"}
bool    verbose     {yes, prompt="Verbose"}
int     status      {0, prompt="Exit status"}
struct  *scanfile   {"", prompt="Internal use only"}

begin
    char    l_inimages = ""
    char    l_gcalflats = ""
    char    l_rawpath = ""
    char    l_flat = ""
    char    l_dispscript = ""
    char    l_slits = ""
    char    l_logfile = ""
    bool    l_verbose

    char    paramstr, lastchar, errmsg
    char    filename, flatused
    char    tmpinimg, tmpinflat
    int     junk
    bool    reduxflat, doscript

    cache ("gloginit")

    status = 0

    junk = fscan (inimages, l_inimages)
    junk = fscan (gcalflats, l_gcalflats)
    junk = fscan (rawpath, l_rawpath)
    junk = fscan (flat, l_flat)
    junk = fscan (dispscript, l_dispscript)
    junk = fscan (slits, l_slits)
    junk = fscan (logfile, l_logfile)
    l_verbose = verbose

    # Make temporary file names
    tmpinimg = mktemp ("tmpinimg")
    tmpinflat = mktemp ("tmpinflat")

    # Create the list of parameter/value pairs.  One pair per line.
    # All lines combined into one string.  Line delimiter is '\n'.
    paramstr =  "inimages       = "//inimages.p_value//"\n"
    paramstr += "gcalflats      = "//gcalflats.p_value//"\n"
    paramstr += "rawpath        = "//rawpath.p_value//"\n"
    paramstr += "flat           = "//flat.p_value//"\n"
    paramstr += "dispscript     = "//dispscript.p_value//"\n"
    paramstr += "slits          = "//slits.p_value//"\n"
    paramstr += "logfile        = "//logfile.p_value//"\n"
    paramstr += "verbose        = "//verbose.p_value

    # Assign a logfile name if not given.  Open logfile and start log.
    # Write parameter/value pairs ("paramstr") to log.
    gloginit (l_logfile, "dirtyIFU", "gmos", paramstr, fl_append+,
        verbose=l_verbose)
    if (gloginit.status != 0) {
        status = gloginit.status
        goto exitnow
    }
    l_logfile = gloginit.logfile.p_value

    # Check dispscript
    if (l_dispscript == "") doscript = no
    else                    doscript = yes

    if (doscript && (yes == access(l_dispscript))) {
        errmsg = "A display script named "//l_dispscript//" already exists."
        status = 102
        glogprint (l_logfile, "dirtyIFU", "status", type="error", errno=status,
            str=errmsg, verbose+)
        goto clean
    }

    ## Ensure rawpath is correct
    lastchar = substr (l_rawpath, strlen (l_rawpath), strlen (l_rawpath))
    if ((l_rawpath != "") && (lastchar != "$") && (lastchar != "/"))
        l_rawpath = l_rawpath//"/"

    # Check inputs
    gemextn (l_inimages, check="exists,mef", process="none", index="",
        extname="", extversion="", ikparams="", omit="kernel,exten",
        replace="^%%"//l_rawpath//"%", outfile="dev$null", logfile=l_logfile,
        verbose=l_verbose)

    if (gemextn.fail_count > 0) {
        errmsg = gemextn.fail_count//" input science frames were not found."
        status = 101
    } else if (gemextn.count == 0) {
        errmsg = "No valid input science frames defined!"
        status = 121
    }

    if (status != 0) {
        glogprint (l_logfile, "dirtyIFU", "status", type="error", errno=status,
            str=errmsg, verbose+)
        goto clean
    } else {
        gemextn (l_inimages, check="", process="none", index="", extname="",
            extversion="", ikparams="", omit="exten", replace="",
            outfile=tmpinimg, logfile=l_logfile, verbose=l_verbose)
    }

    if (l_gcalflats == "") {
        reduxflat = no
    } else {
        reduxflat = yes

        gemextn (l_gcalflats, check="exists,mef", process="none", index="",
            extname="", extversion="", ikparams="", omit="kernel,exten",
            replace="^%%"//l_rawpath//"%", outfile="dev$null",
            logfile=l_logfile, verbose=l_verbose)

        if (gemextn.fail_count > 0) {
            errmsg = gemextn.fail_count//" input GCAL flats were not found."
            status = 101
        } else if (gemextn.count == 0) {
            errmsg = "No input science frames defined!"
            status = 121

        }

        if (status != 0) {
            glogprint (l_logfile, "dirtyIFU", "status", type="error",
                errno=status, str=errmsg, verbose+)
            goto clean
        } else {
            gemextn (l_gcalflats, check="", process="none", index="",
                extname="", extversion="", ikparams="", omit="", replace="",
                outfile=tmpinflat, logfile=l_logfile, verbose=l_verbose)
        }
    }

    if (reduxflat) {
        gfreduce (l_gcalflats, outimag="", outpref="default", slits=l_slits,
            fl_nodsh=no, fl_inter=no, fl_vardq=no, fl_addmdf=yes, fl_over=no,
            fl_trim=yes, fl_bias=no, fl_gscrrej=no, fl_gnsskysub=no,
            fl_extract=yes, fl_gsappwave=yes, fl_wavtran=no, fl_skysub=no,
            fl_fluxcal=no, rawpath=l_rawpath, key_mdf="", mdffile="default",
            mdfdir="gmos$data/", key_biassec="BIASSEC", key_datasec="DATASEC",
            bpmfile="gmos$data/chipgaps.dat", bias="", reference="",
            response="", wavtraname="", sfunction="", extinction="",
            fl_fixnc=no, fl_novlap=yes, perovlap=10., order=1, line=INDEF,
            nsum=10, trace=yes, recenter=yes, thresh=200.,
            function="chebyshev", t_order=5, t_nsum=10, weights="variance",
            gratingdb="gmos$data/GMOSgratings.dat",
            filterdb="gmos$data/GMOSfilters.dat", xoffset=INDEF,
            expr="default", observatory="default", sci_ext="SCI", var_ext="VAR",
            dq_ext="DQ", logfile=l_logfile, verbose=l_verbose)
        if (doscript) {
            scanfile = tmpinflat
            while (fscan (scanfile, filename) != EOF) {
                printf ("gfdisplay erg%s ver=1 \
                    config=gmos$data/gnifu_slitr.cfg \
                    deadfib=gmos$data/gnifu_deadr.cfg\n\n", filename,
                    >> l_dispscript)
            }
            scanfile = ""
        }
        scanfile = tmpinflat
        junk = fscan (scanfile, filename)
        scanfile = ""
        flatused = "erg"//filename
    } else {
        flatused = l_flat
    }

    gfreduce (l_inimages, outimag="", outpref="default", slits=l_slits,
        fl_nodsh=no, fl_inter=no, fl_vardq=no, fl_addmdf=yes, fl_over=no,
        fl_trim=yes, fl_bias=no, fl_gscrrej=yes, fl_gnsskysub=no,
        fl_extract=yes, fl_gsappwave=no, fl_wavtran=no, fl_skysub=yes,
        fl_fluxcal=no, rawpath=l_rawpath, key_mdf="", mdffile="default",
        mdfdir="gmos$data/", key_biassec="BIASSEC", key_datasec="DATASEC",
        bpmfile="gmos$data/chipgaps.dat", bias="", reference=flatused,
        wavtraname="", sfunction="", extinction="", fl_fixnc=no, fl_novlap=yes,
        perovlap=10., order=1, line=INDEF, nsum=10, trace=no, recenter=yes,
        thresh=200., function="chebyshev", t_order=5, t_nsum=10,
        weights="variance", gratingdb="gmos$data/GMOSgratings.dat",
        filterdb="gmos$data/GMOSfilters.dat", xoffset=INDEF, expr="default",
        observatory="default", sci_ext="SCI", var_ext="VAR", dq_ext="DQ",
        logfile=l_logfile, verbose=l_verbose)

    scanfile = tmpinimg
    while (fscan (scanfile, filename) !=  EOF) {
        gfcube ("sexrg"//filename, outimage="sexrg"//filename//"_3D",
            outpref="", ssample=0.1)
        if (doscript) {
            printf ("gfdisplay sexrg%s out=sexrg%s_2D ver=1 \
                config=gmos$data/gnifu_slitr.cfg \
                deadfib=gmos$data/gnifu_deadr.cfg\n\n", filename, filename,
                >> l_dispscript)
        }
    }
    scanfile = ""

clean:
    scanfile = ""
    delete (tmpinimg, ver-, >& "dev$null")
    delete (tmpinflat, ver-, >& "dev$null")

    if (status == 0)
        glogclose (l_logfile, "dirtyIFU", fl_success+, verbose=l_verbose)
    else
        glogclose (l_logfile, "dirtyIFU", fl_success-, verbose=l_verbose)

exitnow:
    ;

end

error: pathspec 'reduxGemini/gmos/iraf/dirtyIFU.cl' did not match any file(s) known to git


AMDGPU: Add a test checking alignments of emitted globals/allocas

Make sure the spec required type alignments are used in preparation
for a possible change which may break this.

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@294278 91177308-0d34-0410-b5e6-96231b3b80d8

// REQUIRES: amdgpu-registered-target
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s

#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#pragma OPENCL EXTENSION cl_khr_fp16 : enable

typedef char __attribute__((ext_vector_type(2))) char2;
typedef char __attribute__((ext_vector_type(3))) char3;
typedef char __attribute__((ext_vector_type(4))) char4;
typedef char __attribute__((ext_vector_type(8))) char8;
typedef char __attribute__((ext_vector_type(16))) char16;

typedef short __attribute__((ext_vector_type(2))) short2;
typedef short __attribute__((ext_vector_type(3))) short3;
typedef short __attribute__((ext_vector_type(4))) short4;
typedef short __attribute__((ext_vector_type(8))) short8;
typedef short __attribute__((ext_vector_type(16))) short16;

typedef int __attribute__((ext_vector_type(2))) int2;
typedef int __attribute__((ext_vector_type(3))) int3;
typedef int __attribute__((ext_vector_type(4))) int4;
typedef int __attribute__((ext_vector_type(8))) int8;
typedef int __attribute__((ext_vector_type(16))) int16;

typedef long __attribute__((ext_vector_type(2))) long2;
typedef long __attribute__((ext_vector_type(3))) long3;
typedef long __attribute__((ext_vector_type(4))) long4;
typedef long __attribute__((ext_vector_type(8))) long8;
typedef long __attribute__((ext_vector_type(16))) long16;

typedef half __attribute__((ext_vector_type(2))) half2;
typedef half __attribute__((ext_vector_type(3))) half3;
typedef half __attribute__((ext_vector_type(4))) half4;
typedef half __attribute__((ext_vector_type(8))) half8;
typedef half __attribute__((ext_vector_type(16))) half16;

typedef float __attribute__((ext_vector_type(2))) float2;
typedef float __attribute__((ext_vector_type(3))) float3;
typedef float __attribute__((ext_vector_type(4))) float4;
typedef float __attribute__((ext_vector_type(8))) float8;
typedef float __attribute__((ext_vector_type(16))) float16;

typedef double __attribute__((ext_vector_type(2))) double2;
typedef double __attribute__((ext_vector_type(3))) double3;
typedef double __attribute__((ext_vector_type(4))) double4;
typedef double __attribute__((ext_vector_type(8))) double8;
typedef double __attribute__((ext_vector_type(16))) double16;

// CHECK: @local_memory_alignment_global.lds_i8 = internal addrspace(3) global [4 x i8] undef, align 1
// CHECK: @local_memory_alignment_global.lds_v2i8 = internal addrspace(3) global [4 x <2 x i8>] undef, align 2
// CHECK: @local_memory_alignment_global.lds_v3i8 = internal addrspace(3) global [4 x <3 x i8>] undef, align 4
// CHECK: @local_memory_alignment_global.lds_v4i8 = internal addrspace(3) global [4 x <4 x i8>] undef, align 4
// CHECK: @local_memory_alignment_global.lds_v8i8 = internal addrspace(3) global [4 x <8 x i8>] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v16i8 = internal addrspace(3) global [4 x <16 x i8>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_i16 = internal addrspace(3) global [4 x i16] undef, align 2
// CHECK: @local_memory_alignment_global.lds_v2i16 = internal addrspace(3) global [4 x <2 x i16>] undef, align 4
// CHECK: @local_memory_alignment_global.lds_v3i16 = internal addrspace(3) global [4 x <3 x i16>] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v4i16 = internal addrspace(3) global [4 x <4 x i16>] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v8i16 = internal addrspace(3) global [4 x <8 x i16>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_v16i16 = internal addrspace(3) global [4 x <16 x i16>] undef, align 32
// CHECK: @local_memory_alignment_global.lds_i32 = internal addrspace(3) global [4 x i32] undef, align 4
// CHECK: @local_memory_alignment_global.lds_v2i32 = internal addrspace(3) global [4 x <2 x i32>] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v3i32 = internal addrspace(3) global [4 x <3 x i32>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_v4i32 = internal addrspace(3) global [4 x <4 x i32>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_v8i32 = internal addrspace(3) global [4 x <8 x i32>] undef, align 32
// CHECK: @local_memory_alignment_global.lds_v16i32 = internal addrspace(3) global [4 x <16 x i32>] undef, align 64
// CHECK: @local_memory_alignment_global.lds_i64 = internal addrspace(3) global [4 x i64] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v2i64 = internal addrspace(3) global [4 x <2 x i64>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_v3i64 = internal addrspace(3) global [4 x <3 x i64>] undef, align 32
// CHECK: @local_memory_alignment_global.lds_v4i64 = internal addrspace(3) global [4 x <4 x i64>] undef, align 32
// CHECK: @local_memory_alignment_global.lds_v8i64 = internal addrspace(3) global [4 x <8 x i64>] undef, align 64
// CHECK: @local_memory_alignment_global.lds_v16i64 = internal addrspace(3) global [4 x <16 x i64>] undef, align 128
// CHECK: @local_memory_alignment_global.lds_f16 = internal addrspace(3) global [4 x half] undef, align 2
// CHECK: @local_memory_alignment_global.lds_v2f16 = internal addrspace(3) global [4 x <2 x half>] undef, align 4
// CHECK: @local_memory_alignment_global.lds_v3f16 = internal addrspace(3) global [4 x <3 x half>] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v4f16 = internal addrspace(3) global [4 x <4 x half>] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v8f16 = internal addrspace(3) global [4 x <8 x half>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_v16f16 = internal addrspace(3) global [4 x <16 x half>] undef, align 32
// CHECK: @local_memory_alignment_global.lds_f32 = internal addrspace(3) global [4 x float] undef, align 4
// CHECK: @local_memory_alignment_global.lds_v2f32 = internal addrspace(3) global [4 x <2 x float>] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v3f32 = internal addrspace(3) global [4 x <3 x float>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_v4f32 = internal addrspace(3) global [4 x <4 x float>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_v8f32 = internal addrspace(3) global [4 x <8 x float>] undef, align 32
// CHECK: @local_memory_alignment_global.lds_v16f32 = internal addrspace(3) global [4 x <16 x float>] undef, align 64
// CHECK: @local_memory_alignment_global.lds_f64 = internal addrspace(3) global [4 x double] undef, align 8
// CHECK: @local_memory_alignment_global.lds_v2f64 = internal addrspace(3) global [4 x <2 x double>] undef, align 16
// CHECK: @local_memory_alignment_global.lds_v3f64 = internal addrspace(3) global [4 x <3 x double>] undef, align 32
// CHECK: @local_memory_alignment_global.lds_v4f64 = internal addrspace(3) global [4 x <4 x double>] undef, align 32
// CHECK: @local_memory_alignment_global.lds_v8f64 = internal addrspace(3) global [4 x <8 x double>] undef, align 64
// CHECK: @local_memory_alignment_global.lds_v16f64 = internal addrspace(3) global [4 x <16 x double>] undef, align 128

// CHECK-LABEL: @local_memory_alignment_global(
// CHECK: store volatile i8 0, i8 addrspace(3)* getelementptr inbounds ([4 x i8], [4 x i8] addrspace(3)* @local_memory_alignment_global.lds_i8, i32 0, i32 0), align 1
// CHECK: store volatile <2 x i8> zeroinitializer, <2 x i8> addrspace(3)* getelementptr inbounds ([4 x <2 x i8>], [4 x <2 x i8>] addrspace(3)* @local_memory_alignment_global.lds_v2i8, i32 0, i32 0), align 2
// CHECK: store volatile <4 x i8> <i8 0, i8 0, i8 0, i8 undef>, <4 x i8> addrspace(3)* bitcast ([4 x <3 x i8>] addrspace(3)* @local_memory_alignment_global.lds_v3i8 to <4 x i8> addrspace(3)*), align 4
// CHECK: store volatile <4 x i8> zeroinitializer, <4 x i8> addrspace(3)* getelementptr inbounds ([4 x <4 x i8>], [4 x <4 x i8>] addrspace(3)* @local_memory_alignment_global.lds_v4i8, i32 0, i32 0), align 4
// CHECK: store volatile <8 x i8> zeroinitializer, <8 x i8> addrspace(3)* getelementptr inbounds ([4 x <8 x i8>], [4 x <8 x i8>] addrspace(3)* @local_memory_alignment_global.lds_v8i8, i32 0, i32 0), align 8
// CHECK: store volatile <16 x i8> zeroinitializer, <16 x i8> addrspace(3)* getelementptr inbounds ([4 x <16 x i8>], [4 x <16 x i8>] addrspace(3)* @local_memory_alignment_global.lds_v16i8, i32 0, i32 0), align 16
// CHECK: store volatile i16 0, i16 addrspace(3)* getelementptr inbounds ([4 x i16], [4 x i16] addrspace(3)* @local_memory_alignment_global.lds_i16, i32 0, i32 0), align 2
// CHECK: store volatile <2 x i16> zeroinitializer, <2 x i16> addrspace(3)* getelementptr inbounds ([4 x <2 x i16>], [4 x <2 x i16>] addrspace(3)* @local_memory_alignment_global.lds_v2i16, i32 0, i32 0), align 4
// CHECK: store volatile <4 x i16> <i16 0, i16 0, i16 0, i16 undef>, <4 x i16> addrspace(3)* bitcast ([4 x <3 x i16>] addrspace(3)* @local_memory_alignment_global.lds_v3i16 to <4 x i16> addrspace(3)*), align 8
// CHECK: store volatile <4 x i16> zeroinitializer, <4 x i16> addrspace(3)* getelementptr inbounds ([4 x <4 x i16>], [4 x <4 x i16>] addrspace(3)* @local_memory_alignment_global.lds_v4i16, i32 0, i32 0), align 8
// CHECK: store volatile <8 x i16> zeroinitializer, <8 x i16> addrspace(3)* getelementptr inbounds ([4 x <8 x i16>], [4 x <8 x i16>] addrspace(3)* @local_memory_alignment_global.lds_v8i16, i32 0, i32 0), align 16
// CHECK: store volatile <16 x i16> zeroinitializer, <16 x i16> addrspace(3)* getelementptr inbounds ([4 x <16 x i16>], [4 x <16 x i16>] addrspace(3)* @local_memory_alignment_global.lds_v16i16, i32 0, i32 0), align 32
// CHECK: store volatile i32 0, i32 addrspace(3)* getelementptr inbounds ([4 x i32], [4 x i32] addrspace(3)* @local_memory_alignment_global.lds_i32, i32 0, i32 0), align 4
// CHECK: store volatile <2 x i32> zeroinitializer, <2 x i32> addrspace(3)* getelementptr inbounds ([4 x <2 x i32>], [4 x <2 x i32>] addrspace(3)* @local_memory_alignment_global.lds_v2i32, i32 0, i32 0), align 8
// CHECK: store volatile <4 x i32> <i32 0, i32 0, i32 0, i32 undef>, <4 x i32> addrspace(3)* bitcast ([4 x <3 x i32>] addrspace(3)* @local_memory_alignment_global.lds_v3i32 to <4 x i32> addrspace(3)*), align 16
// CHECK: store volatile <4 x i32> zeroinitializer, <4 x i32> addrspace(3)* getelementptr inbounds ([4 x <4 x i32>], [4 x <4 x i32>] addrspace(3)* @local_memory_alignment_global.lds_v4i32, i32 0, i32 0), align 16
// CHECK: store volatile <8 x i32> zeroinitializer, <8 x i32> addrspace(3)* getelementptr inbounds ([4 x <8 x i32>], [4 x <8 x i32>] addrspace(3)* @local_memory_alignment_global.lds_v8i32, i32 0, i32 0), align 32
// CHECK: store volatile <16 x i32> zeroinitializer, <16 x i32> addrspace(3)* getelementptr inbounds ([4 x <16 x i32>], [4 x <16 x i32>] addrspace(3)* @local_memory_alignment_global.lds_v16i32, i32 0, i32 0), align 64
// CHECK: store volatile i64 0, i64 addrspace(3)* getelementptr inbounds ([4 x i64], [4 x i64] addrspace(3)* @local_memory_alignment_global.lds_i64, i32 0, i32 0), align 8
// CHECK: store volatile <2 x i64> zeroinitializer, <2 x i64> addrspace(3)* getelementptr inbounds ([4 x <2 x i64>], [4 x <2 x i64>] addrspace(3)* @local_memory_alignment_global.lds_v2i64, i32 0, i32 0), align 16
// CHECK: store volatile <4 x i64> <i64 0, i64 0, i64 0, i64 undef>, <4 x i64> addrspace(3)* bitcast ([4 x <3 x i64>] addrspace(3)* @local_memory_alignment_global.lds_v3i64 to <4 x i64> addrspace(3)*), align 32
// CHECK: store volatile <4 x i64> zeroinitializer, <4 x i64> addrspace(3)* getelementptr inbounds ([4 x <4 x i64>], [4 x <4 x i64>] addrspace(3)* @local_memory_alignment_global.lds_v4i64, i32 0, i32 0), align 32
// CHECK: store volatile <8 x i64> zeroinitializer, <8 x i64> addrspace(3)* getelementptr inbounds ([4 x <8 x i64>], [4 x <8 x i64>] addrspace(3)* @local_memory_alignment_global.lds_v8i64, i32 0, i32 0), align 64
// CHECK: store volatile <16 x i64> zeroinitializer, <16 x i64> addrspace(3)* getelementptr inbounds ([4 x <16 x i64>], [4 x <16 x i64>] addrspace(3)* @local_memory_alignment_global.lds_v16i64, i32 0, i32 0), align 128
// CHECK: store volatile half 0xH0000, half addrspace(3)* getelementptr inbounds ([4 x half], [4 x half] addrspace(3)* @local_memory_alignment_global.lds_f16, i32 0, i32 0), align 2
// CHECK: store volatile <2 x half> zeroinitializer, <2 x half> addrspace(3)* getelementptr inbounds ([4 x <2 x half>], [4 x <2 x half>] addrspace(3)* @local_memory_alignment_global.lds_v2f16, i32 0, i32 0), align 4
// CHECK: store volatile <4 x half> <half 0xH0000, half 0xH0000, half 0xH0000, half undef>, <4 x half> addrspace(3)* bitcast ([4 x <3 x half>] addrspace(3)* @local_memory_alignment_global.lds_v3f16 to <4 x half> addrspace(3)*), align 8
// CHECK: store volatile <4 x half> zeroinitializer, <4 x half> addrspace(3)* getelementptr inbounds ([4 x <4 x half>], [4 x <4 x half>] addrspace(3)* @local_memory_alignment_global.lds_v4f16, i32 0, i32 0), align 8
// CHECK: store volatile <8 x half> zeroinitializer, <8 x half> addrspace(3)* getelementptr inbounds ([4 x <8 x half>], [4 x <8 x half>] addrspace(3)* @local_memory_alignment_global.lds_v8f16, i32 0, i32 0), align 16
// CHECK: store volatile <16 x half> zeroinitializer, <16 x half> addrspace(3)* getelementptr inbounds ([4 x <16 x half>], [4 x <16 x half>] addrspace(3)* @local_memory_alignment_global.lds_v16f16, i32 0, i32 0), align 32
// CHECK: store volatile float 0.000000e+00, float addrspace(3)* getelementptr inbounds ([4 x float], [4 x float] addrspace(3)* @local_memory_alignment_global.lds_f32, i32 0, i32 0), align 4
// CHECK: store volatile <2 x float> zeroinitializer, <2 x float> addrspace(3)* getelementptr inbounds ([4 x <2 x float>], [4 x <2 x float>] addrspace(3)* @local_memory_alignment_global.lds_v2f32, i32 0, i32 0), align 8
// CHECK: store volatile <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float undef>, <4 x float> addrspace(3)* bitcast ([4 x <3 x float>] addrspace(3)* @local_memory_alignment_global.lds_v3f32 to <4 x float> addrspace(3)*), align 16
// CHECK: store volatile <4 x float> zeroinitializer, <4 x float> addrspace(3)* getelementptr inbounds ([4 x <4 x float>], [4 x <4 x float>] addrspace(3)* @local_memory_alignment_global.lds_v4f32, i32 0, i32 0), align 16
// CHECK: store volatile <8 x float> zeroinitializer, <8 x float> addrspace(3)* getelementptr inbounds ([4 x <8 x float>], [4 x <8 x float>] addrspace(3)* @local_memory_alignment_global.lds_v8f32, i32 0, i32 0), align 32
// CHECK: store volatile <16 x float> zeroinitializer, <16 x float> addrspace(3)* getelementptr inbounds ([4 x <16 x float>], [4 x <16 x float>] addrspace(3)* @local_memory_alignment_global.lds_v16f32, i32 0, i32 0), align 64
// CHECK: store volatile double 0.000000e+00, double addrspace(3)* getelementptr inbounds ([4 x double], [4 x double] addrspace(3)* @local_memory_alignment_global.lds_f64, i32 0, i32 0), align 8
// CHECK: store volatile <2 x double> zeroinitializer, <2 x double> addrspace(3)* getelementptr inbounds ([4 x <2 x double>], [4 x <2 x double>] addrspace(3)* @local_memory_alignment_global.lds_v2f64, i32 0, i32 0), align 16
// CHECK: store volatile <4 x double> <double 0.000000e+00, double 0.000000e+00, double 0.000000e+00, double undef>, <4 x double> addrspace(3)* bitcast ([4 x <3 x double>] addrspace(3)* @local_memory_alignment_global.lds_v3f64 to <4 x double> addrspace(3)*), align 32
// CHECK: store volatile <4 x double> zeroinitializer, <4 x double> addrspace(3)* getelementptr inbounds ([4 x <4 x double>], [4 x <4 x double>] addrspace(3)* @local_memory_alignment_global.lds_v4f64, i32 0, i32 0), align 32
// CHECK: store volatile <8 x double> zeroinitializer, <8 x double> addrspace(3)* getelementptr inbounds ([4 x <8 x double>], [4 x <8 x double>] addrspace(3)* @local_memory_alignment_global.lds_v8f64, i32 0, i32 0), align 64
// CHECK: store volatile <16 x double> zeroinitializer, <16 x double> addrspace(3)* getelementptr inbounds ([4 x <16 x double>], [4 x <16 x double>] addrspace(3)* @local_memory_alignment_global.lds_v16f64, i32 0, i32 0), align 128
kernel void local_memory_alignment_global()
{
  volatile local char lds_i8[4];
  volatile local char2 lds_v2i8[4];
  volatile local char3 lds_v3i8[4];
  volatile local char4 lds_v4i8[4];
  volatile local char8 lds_v8i8[4];
  volatile local char16 lds_v16i8[4];

  volatile local short lds_i16[4];
  volatile local short2 lds_v2i16[4];
  volatile local short3 lds_v3i16[4];
  volatile local short4 lds_v4i16[4];
  volatile local short8 lds_v8i16[4];
  volatile local short16 lds_v16i16[4];

  volatile local int lds_i32[4];
  volatile local int2 lds_v2i32[4];
  volatile local int3 lds_v3i32[4];
  volatile local int4 lds_v4i32[4];
  volatile local int8 lds_v8i32[4];
  volatile local int16 lds_v16i32[4];

  volatile local long lds_i64[4];
  volatile local long2 lds_v2i64[4];
  volatile local long3 lds_v3i64[4];
  volatile local long4 lds_v4i64[4];
  volatile local long8 lds_v8i64[4];
  volatile local long16 lds_v16i64[4];

  volatile local half lds_f16[4];
  volatile local half2 lds_v2f16[4];
  volatile local half3 lds_v3f16[4];
  volatile local half4 lds_v4f16[4];
  volatile local half8 lds_v8f16[4];
  volatile local half16 lds_v16f16[4];

  volatile local float lds_f32[4];
  volatile local float2 lds_v2f32[4];
  volatile local float3 lds_v3f32[4];
  volatile local float4 lds_v4f32[4];
  volatile local float8 lds_v8f32[4];
  volatile local float16 lds_v16f32[4];

  volatile local double lds_f64[4];
  volatile local double2 lds_v2f64[4];
  volatile local double3 lds_v3f64[4];
  volatile local double4 lds_v4f64[4];
  volatile local double8 lds_v8f64[4];
  volatile local double16 lds_v16f64[4];

  *lds_i8 = 0;
  *lds_v2i8 = 0;
  *lds_v3i8 = 0;
  *lds_v4i8 = 0;
  *lds_v8i8 = 0;
  *lds_v16i8 = 0;

  *lds_i16 = 0;
  *lds_v2i16 = 0;
  *lds_v3i16 = 0;
  *lds_v4i16 = 0;
  *lds_v8i16 = 0;
  *lds_v16i16 = 0;

  *lds_i32 = 0;
  *lds_v2i32 = 0;
  *lds_v3i32 = 0;
  *lds_v4i32 = 0;
  *lds_v8i32 = 0;
  *lds_v16i32 = 0;

  *lds_i64 = 0;
  *lds_v2i64 = 0;
  *lds_v3i64 = 0;
  *lds_v4i64 = 0;
  *lds_v8i64 = 0;
  *lds_v16i64 = 0;

  *lds_f16 = 0;
  *lds_v2f16 = 0;
  *lds_v3f16 = 0;
  *lds_v4f16 = 0;
  *lds_v8f16 = 0;
  *lds_v16f16 = 0;

  *lds_f32 = 0;
  *lds_v2f32 = 0;
  *lds_v3f32 = 0;
  *lds_v4f32 = 0;
  *lds_v8f32 = 0;
  *lds_v16f32 = 0;

  *lds_f64 = 0;
  *lds_v2f64 = 0;
  *lds_v3f64 = 0;
  *lds_v4f64 = 0;
  *lds_v8f64 = 0;
  *lds_v16f64 = 0;
}

kernel void local_memory_alignment_arg(
  volatile local char* lds_i8,
  volatile local char2* lds_v2i8,
  volatile local char3* lds_v3i8,
  volatile local char4* lds_v4i8,
  volatile local char8* lds_v8i8,
  volatile local char16* lds_v16i8,

  volatile local short* lds_i16,
  volatile local short2* lds_v2i16,
  volatile local short3* lds_v3i16,
  volatile local short4* lds_v4i16,
  volatile local short8* lds_v8i16,
  volatile local short16* lds_v16i16,

  volatile local int* lds_i32,
  volatile local int2* lds_v2i32,
  volatile local int3* lds_v3i32,
  volatile local int4* lds_v4i32,
  volatile local int8* lds_v8i32,
  volatile local int16* lds_v16i32,

  volatile local long* lds_i64,
  volatile local long2* lds_v2i64,
  volatile local long3* lds_v3i64,
  volatile local long4* lds_v4i64,
  volatile local long8* lds_v8i64,
  volatile local long16* lds_v16i64,

  volatile local half* lds_f16,
  volatile local half2* lds_v2f16,
  volatile local half3* lds_v3f16,
  volatile local half4* lds_v4f16,
  volatile local half8* lds_v8f16,
  volatile local half16* lds_v16f16,

  volatile local float* lds_f32,
  volatile local float2* lds_v2f32,
  volatile local float3* lds_v3f32,
  volatile local float4* lds_v4f32,
  volatile local float8* lds_v8f32,
  volatile local float16* lds_v16f32,

  volatile local double* lds_f64,
  volatile local double2* lds_v2f64,
  volatile local double3* lds_v3f64,
  volatile local double4* lds_v4f64,
  volatile local double8* lds_v8f64,
  volatile local double16* lds_v16f64)
{
  *lds_i8 = 0;
  *lds_v2i8 = 0;
  *lds_v3i8 = 0;
  *lds_v4i8 = 0;
  *lds_v8i8 = 0;
  *lds_v16i8 = 0;

  *lds_i16 = 0;
  *lds_v2i16 = 0;
  *lds_v3i16 = 0;
  *lds_v4i16 = 0;
  *lds_v8i16 = 0;
  *lds_v16i16 = 0;

  *lds_i32 = 0;
  *lds_v2i32 = 0;
  *lds_v3i32 = 0;
  *lds_v4i32 = 0;
  *lds_v8i32 = 0;
  *lds_v16i32 = 0;

  *lds_i64 = 0;
  *lds_v2i64 = 0;
  *lds_v3i64 = 0;
  *lds_v4i64 = 0;
  *lds_v8i64 = 0;
  *lds_v16i64 = 0;

  *lds_f16 = 0;
  *lds_v2f16 = 0;
  *lds_v3f16 = 0;
  *lds_v4f16 = 0;
  *lds_v8f16 = 0;
  *lds_v16f16 = 0;

  *lds_f32 = 0;
  *lds_v2f32 = 0;
  *lds_v3f32 = 0;
  *lds_v4f32 = 0;
  *lds_v8f32 = 0;
  *lds_v16f32 = 0;

  *lds_f64 = 0;
  *lds_v2f64 = 0;
  *lds_v3f64 = 0;
  *lds_v4f64 = 0;
  *lds_v8f64 = 0;
  *lds_v16f64 = 0;
}

// CHECK-LABEL: @private_memory_alignment_alloca(
// CHECK: %private_i8 = alloca [4 x i8], align 1
// CHECK: %private_v2i8 = alloca [4 x <2 x i8>], align 2
// CHECK: %private_v3i8 = alloca [4 x <3 x i8>], align 4
// CHECK: %private_v4i8 = alloca [4 x <4 x i8>], align 4
// CHECK: %private_v8i8 = alloca [4 x <8 x i8>], align 8
// CHECK: %private_v16i8 = alloca [4 x <16 x i8>], align 16
// CHECK: %private_i16 = alloca [4 x i16], align 2
// CHECK: %private_v2i16 = alloca [4 x <2 x i16>], align 4
// CHECK: %private_v3i16 = alloca [4 x <3 x i16>], align 8
// CHECK: %private_v4i16 = alloca [4 x <4 x i16>], align 8
// CHECK: %private_v8i16 = alloca [4 x <8 x i16>], align 16
// CHECK: %private_v16i16 = alloca [4 x <16 x i16>], align 32
// CHECK: %private_i32 = alloca [4 x i32], align 4
// CHECK: %private_v2i32 = alloca [4 x <2 x i32>], align 8
// CHECK: %private_v3i32 = alloca [4 x <3 x i32>], align 16
// CHECK: %private_v4i32 = alloca [4 x <4 x i32>], align 16
// CHECK: %private_v8i32 = alloca [4 x <8 x i32>], align 32
// CHECK: %private_v16i32 = alloca [4 x <16 x i32>], align 64
// CHECK: %private_i64 = alloca [4 x i64], align 8
// CHECK: %private_v2i64 = alloca [4 x <2 x i64>], align 16
// CHECK: %private_v3i64 = alloca [4 x <3 x i64>], align 32
// CHECK: %private_v4i64 = alloca [4 x <4 x i64>], align 32
// CHECK: %private_v8i64 = alloca [4 x <8 x i64>], align 64
// CHECK: %private_v16i64 = alloca [4 x <16 x i64>], align 128
// CHECK: %private_f16 = alloca [4 x half], align 2
// CHECK: %private_v2f16 = alloca [4 x <2 x half>], align 4
// CHECK: %private_v3f16 = alloca [4 x <3 x half>], align 8
// CHECK: %private_v4f16 = alloca [4 x <4 x half>], align 8
// CHECK: %private_v8f16 = alloca [4 x <8 x half>], align 16
// CHECK: %private_v16f16 = alloca [4 x <16 x half>], align 32
// CHECK: %private_f32 = alloca [4 x float], align 4
// CHECK: %private_v2f32 = alloca [4 x <2 x float>], align 8
// CHECK: %private_v3f32 = alloca [4 x <3 x float>], align 16
// CHECK: %private_v4f32 = alloca [4 x <4 x float>], align 16
// CHECK: %private_v8f32 = alloca [4 x <8 x float>], align 32
// CHECK: %private_v16f32 = alloca [4 x <16 x float>], align 64
// CHECK: %private_f64 = alloca [4 x double], align 8
// CHECK: %private_v2f64 = alloca [4 x <2 x double>], align 16
// CHECK: %private_v3f64 = alloca [4 x <3 x double>], align 32
// CHECK: %private_v4f64 = alloca [4 x <4 x double>], align 32
// CHECK: %private_v8f64 = alloca [4 x <8 x double>], align 64
// CHECK: %private_v16f64 = alloca [4 x <16 x double>], align 128

// CHECK: store volatile i8 0, i8* %arraydecay, align 1
// CHECK: store volatile <2 x i8> zeroinitializer, <2 x i8>* %arraydecay{{[0-9]+}}, align 2
// CHECK: store volatile <4 x i8> <i8 0, i8 0, i8 0, i8 undef>, <4 x i8>* %storetmp, align 4
// CHECK: store volatile <4 x i8> zeroinitializer, <4 x i8>* %arraydecay{{[0-9]+}}, align 4
// CHECK: store volatile <8 x i8> zeroinitializer, <8 x i8>* %arraydecay{{[0-9]+}}, align 8
// CHECK: store volatile <16 x i8> zeroinitializer, <16 x i8>* %arraydecay{{[0-9]+}}, align 16
// CHECK: store volatile i16 0, i16* %arraydecay{{[0-9]+}}, align 2
// CHECK: store volatile <2 x i16> zeroinitializer, <2 x i16>* %arraydecay{{[0-9]+}}, align 4
// CHECK: store volatile <4 x i16> <i16 0, i16 0, i16 0, i16 undef>, <4 x i16>* %storetmp{{[0-9]+}}, align 8
// CHECK: store volatile <4 x i16> zeroinitializer, <4 x i16>* %arraydecay{{[0-9]+}}, align 8
// CHECK: store volatile <8 x i16> zeroinitializer, <8 x i16>* %arraydecay{{[0-9]+}}, align 16
// CHECK: store volatile <16 x i16> zeroinitializer, <16 x i16>* %arraydecay{{[0-9]+}}, align 32
// CHECK: store volatile i32 0, i32* %arraydecay{{[0-9]+}}, align 4
// CHECK: store volatile <2 x i32> zeroinitializer, <2 x i32>* %arraydecay{{[0-9]+}}, align 8
// CHECK: store volatile <4 x i32> <i32 0, i32 0, i32 0, i32 undef>, <4 x i32>* %storetmp16, align 16
// CHECK: store volatile <4 x i32> zeroinitializer, <4 x i32>* %arraydecay{{[0-9]+}}, align 16
// CHECK: store volatile <8 x i32> zeroinitializer, <8 x i32>* %arraydecay{{[0-9]+}}, align 32
// CHECK: store volatile <16 x i32> zeroinitializer, <16 x i32>* %arraydecay{{[0-9]+}}, align 64
// CHECK: store volatile i64 0, i64* %arraydecay{{[0-9]+}}, align 8
// CHECK: store volatile <2 x i64> zeroinitializer, <2 x i64>* %arraydecay{{[0-9]+}}, align 16
// CHECK: store volatile <4 x i64> <i64 0, i64 0, i64 0, i64 undef>, <4 x i64>* %storetmp23, align 32
// CHECK: store volatile <4 x i64> zeroinitializer, <4 x i64>* %arraydecay{{[0-9]+}}, align 32
// CHECK: store volatile <8 x i64> zeroinitializer, <8 x i64>* %arraydecay{{[0-9]+}}, align 64
// CHECK: store volatile <16 x i64> zeroinitializer, <16 x i64>* %arraydecay{{[0-9]+}}, align 128
// CHECK: store volatile half 0xH0000, half* %arraydecay{{[0-9]+}}, align 2
// CHECK: store volatile <2 x half> zeroinitializer, <2 x half>* %arraydecay{{[0-9]+}}, align 4
// CHECK: store volatile <4 x half> <half 0xH0000, half 0xH0000, half 0xH0000, half undef>, <4 x half>* %storetmp{{[0-9]+}}, align 8
// CHECK: store volatile <4 x half> zeroinitializer, <4 x half>* %arraydecay{{[0-9]+}}, align 8
// CHECK: store volatile <8 x half> zeroinitializer, <8 x half>* %arraydecay{{[0-9]+}}, align 16
// CHECK: store volatile <16 x half> zeroinitializer, <16 x half>* %arraydecay{{[0-9]+}}, align 32
// CHECK: store volatile float 0.000000e+00, float* %arraydecay34, align 4
// CHECK: store volatile <2 x float> zeroinitializer, <2 x float>* %arraydecay{{[0-9]+}}, align 8
// CHECK: store volatile <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float undef>, <4 x float>* %storetmp{{[0-9]+}}, align 16
// CHECK: store volatile <4 x float> zeroinitializer, <4 x float>* %arraydecay{{[0-9]+}}, align 16
// CHECK: store volatile <8 x float> zeroinitializer, <8 x float>* %arraydecay{{[0-9]+}}, align 32
// CHECK: store volatile <16 x float> zeroinitializer, <16 x float>* %arraydecay{{[0-9]+}}, align 64
// CHECK: store volatile double 0.000000e+00, double* %arraydecay{{[0-9]+}}, align 8
// CHECK: store volatile <2 x double> zeroinitializer, <2 x double>* %arraydecay{{[0-9]+}}, align 16
// CHECK: store volatile <4 x double> <double 0.000000e+00, double 0.000000e+00, double 0.000000e+00, double undef>, <4 x double>* %storetmp{{[0-9]+}}, align 32
// CHECK: store volatile <4 x double> zeroinitializer, <4 x double>* %arraydecay{{[0-9]+}}, align 32
// CHECK: store volatile <8 x double> zeroinitializer, <8 x double>* %arraydecay{{[0-9]+}}, align 64
// CHECK: store volatile <16 x double> zeroinitializer, <16 x double>* %arraydecay{{[0-9]+}}, align 128
kernel void private_memory_alignment_alloca()
{
  volatile private char private_i8[4];
  volatile private char2 private_v2i8[4];
  volatile private char3 private_v3i8[4];
  volatile private char4 private_v4i8[4];
  volatile private char8 private_v8i8[4];
  volatile private char16 private_v16i8[4];

  volatile private short private_i16[4];
  volatile private short2 private_v2i16[4];
  volatile private short3 private_v3i16[4];
  volatile private short4 private_v4i16[4];
  volatile private short8 private_v8i16[4];
  volatile private short16 private_v16i16[4];

  volatile private int private_i32[4];
  volatile private int2 private_v2i32[4];
  volatile private int3 private_v3i32[4];
  volatile private int4 private_v4i32[4];
  volatile private int8 private_v8i32[4];
  volatile private int16 private_v16i32[4];

  volatile private long private_i64[4];
  volatile private long2 private_v2i64[4];
  volatile private long3 private_v3i64[4];
  volatile private long4 private_v4i64[4];
  volatile private long8 private_v8i64[4];
  volatile private long16 private_v16i64[4];

  volatile private half private_f16[4];
  volatile private half2 private_v2f16[4];
  volatile private half3 private_v3f16[4];
  volatile private half4 private_v4f16[4];
  volatile private half8 private_v8f16[4];
  volatile private half16 private_v16f16[4];

  volatile private float private_f32[4];
  volatile private float2 private_v2f32[4];
  volatile private float3 private_v3f32[4];
  volatile private float4 private_v4f32[4];
  volatile private float8 private_v8f32[4];
  volatile private float16 private_v16f32[4];

  volatile private double private_f64[4];
  volatile private double2 private_v2f64[4];
  volatile private double3 private_v3f64[4];
  volatile private double4 private_v4f64[4];
  volatile private double8 private_v8f64[4];
  volatile private double16 private_v16f64[4];

  *private_i8 = 0;
  *private_v2i8 = 0;
  *private_v3i8 = 0;
  *private_v4i8 = 0;
  *private_v8i8 = 0;
  *private_v16i8 = 0;

  *private_i16 = 0;
  *private_v2i16 = 0;
  *private_v3i16 = 0;
  *private_v4i16 = 0;
  *private_v8i16 = 0;
  *private_v16i16 = 0;

  *private_i32 = 0;
  *private_v2i32 = 0;
  *private_v3i32 = 0;
  *private_v4i32 = 0;
  *private_v8i32 = 0;
  *private_v16i32 = 0;

  *private_i64 = 0;
  *private_v2i64 = 0;
  *private_v3i64 = 0;
  *private_v4i64 = 0;
  *private_v8i64 = 0;
  *private_v16i64 = 0;

  *private_f16 = 0;
  *private_v2f16 = 0;
  *private_v3f16 = 0;
  *private_v4f16 = 0;
  *private_v8f16 = 0;
  *private_v16f16 = 0;

  *private_f32 = 0;
  *private_v2f32 = 0;
  *private_v3f32 = 0;
  *private_v4f32 = 0;
  *private_v8f32 = 0;
  *private_v16f32 = 0;

  *private_f64 = 0;
  *private_v2f64 = 0;
  *private_v3f64 = 0;
  *private_v4f64 = 0;
  *private_v8f64 = 0;
  *private_v16f64 = 0;
}

error: pathspec 'test/CodeGenOpenCL/amdgpu-alignment.cl' did not match any file(s) known to git


WPacket Recursion Complete

WPacket Recursion Complete


Revise the parameters of Wpacket Group Handler

Reduce repeated operations


Revert "Fix deletion packet initialization"

This reverts commit 0f30b0e38236534934fd67febd3634ad47b9b7e0.


hello world cl-glut code

hello world cl-glut code

(proclaim '(optimize (speed 0) (safety 3) (debug 3)))

(ql:quickload '(alexandria iterate anaphora cl-glut) :silent t)

(defpackage arboreta
  (:use cl iterate anaphora alexandria))

(in-package arboreta)

(defclass hello-window (glut:window)
  ()
  (:default-initargs :pos-x 100 :pos-y 100 :width 250 :height 250
                     :mode '(:single :rgb) :title "hello.lisp"))

(defmethod glut:display-window :before ((w hello-window))
  ;; Select clearing color.
  (gl:clear-color 0 0 0 0)
  ;; Initialize viewing values.
  (gl:matrix-mode :projection)
  (gl:load-identity)
  (gl:ortho 0 1 0 1 -1 1))

(defmethod glut:display ((w hello-window))
  (gl:clear :color-buffer)
  ;; Draw white polygon (rectangle) with corners at
  ;; (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0).
  (gl:color 1 1 1)
  (gl:with-primitive :polygon
    (gl:vertex 0.25 0.25 0)
    (gl:vertex 0.75 0.25 0)
    (gl:vertex 0.75 0.75 0)
    (gl:vertex 0.25 0.75 0))
  ;; Start processing buffered OpenGL routines.
  (gl:flush))

(defun main () (glut:display-window (make-instance 'hello-window)))

(sb-ext:save-lisp-and-die "arboreta" :toplevel #'main :executable t)

error: pathspec 'arboreta.cl' did not match any file(s) known to git


Opmaak verbeterd

Opmaak verbeterd

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/MichielPauwels/LCS.git/'


removed duplicate kernel source file

removed duplicate kernel source file

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/neveraway/oclJPEGDecoder.git/'


Create msp430.cl

Create msp430.cl

;emulator for the MSP430, written to help solve the final level in the Matasano/Square CTF at https://microcorruption.com/

;data structure plans:
;memory to be represented as a large array of bytes
;registers as a much smaller array of words

(defvar *reg* (make-array 16 :element-type '(UNSIGNED-BYTE 16)))

;(setf *reg* (make-array 16 :element-type '(unsigned-byte 16)))

(defvar *mem* (make-array 65536 :element-type '(UNSIGNED-BYTE 8)))

(defun mem (idx)
  (elt *mem* idx))

(defun reg (idx)
  (elt *reg* idx))

(defun flag (idx)
  (ldb (byte 1 idx) (reg 2)))

(defun get-c ()
  (ldb (byte 1 0) (reg 2)))

(defun set-c (int)
  (setf (elt *reg* 2) (dpb int (byte 1 0) (reg 2))))

(defun get-z ()
  (ldb (byte 1 1) (reg 2)))

(defun set-z (int)
  (setf (elt *reg* 2) (dpb int (byte 1 1) (reg 2))))

(defun get-n ()
  (ldb (byte 1 2) (reg 2)))

(defun set-n (int)
  (setf (elt *reg* 2) (dpb int (byte 1 2) (reg 2))))

(defun get-v ()
  (ldb (byte 1 8) (reg 2)))

(defun set-v (int)
  (setf (elt *reg* 2) (dpb int (byte 1 8) (reg 2))))

(defun bytes-to-word (low high)
  (+ (* 256 high) low))

(defun mod+ (&rest args)
  (mod (reduce #'+ args) 65536))

(defun mod* (&rest args)
  (mod (reduce #'* args) 65536))

(defun get-mem (idx)
  (+ (* 256 (mem (+ idx 1))) (mem idx)))

(defun set-mem (idx int)
  (let* ((low (mod int 256))
	 (high (/ (- int low) 256)))
    (setf (elt *mem* idx) low
	  (elt *mem* (+ idx 1)) high)))

(defun mem-fun (idx)
  (function (lambda (int) (set-mem idx (mod int 65536)))))

(defun reg-fun (idx)
  (function (lambda (int) (setf (elt *reg* idx) (mod int 65536)))))

(defun nullp (val)
  (if (= val 0)
      1
      0))

(defun negp (val)
  (ldb (byte 1 15) val))

(defun instruction-decode (bytes)
  ;bytes to be an arry of 6 bytes, to allow for the longest possible instruction
  ;this is the entry point into the instruction decoding, will eventually call the
  ;appropriate function
  (let ((instn (bytes-to-word (elt bytes 0) (elt bytes 1)))
	(data1 (bytes-to-word (elt bytes 2) (elt bytes 3)))
	(data2 (bytes-to-word (elt bytes 4) (elt bytes 5))))
    (cond ((= (ldb (byte 4 12) instn)) (single-decode instn data1))
	  ((= (ldb (byte 3 13) instn)) (jump-decode instn))
	  ((>= (ldb (byte 4 12) instn)) (double-decode instn data1 data2)))))

(defun address-decode (ad dest data)
  ;decodes an address for a single operand instruction
  ;returns an integer representing the current value and a function that sets the new value
  (if (or (= dest 2) (= dest 3))
      (if (= dest 2)
	  (cond ((= ad 0) (values (reg dest)
				  (reg-fun dest))) ;register mode
		((= ad 1) (values (get-mem data)
				  (mem-fun data))) ;absolute mode
		((= ad 2) (values 4 4)) ;represents a constant, can't set things
		((= ad 3) (values 8 8))) ;as above
	  (cond ((= ad 0) (values 0 0))
		((= ad 1) (values 1 1))
		((= ad 2) (values 2 2))
		((= ad 3) (values 65535 65535))))
      (cond ((= ad 0) (values (reg dest)
			      (reg-fun dest))) ;register mode
	    ((= ad 1) (let ((idx (mod+ (reg dest) data)))
			(values (get-mem idx)
				(mem-fun idx)))) ;index mode
	    ((= ad 2) (values (get-mem (reg dest))
			      (mem-fun (reg dest)))) ;indirect mode
	    ((= ad 3) (progn (incf (elt *reg* dest) 2)
			     (values (get-mem (- (reg dest) 2))
				     (mem-fun (- (reg dest) 2)))))))) ;indirect mode with increment

(defun single-decode (instn data)
  ;decodes and calls a single operand instruction
  (let ((opcode (ldb (byte 3 7) instn))
	(ad (ldb (byte 2 4) instn))
	(dest (ldb (byte 4 0) instn)))
    (multiple-value-bind (value set-fun)
	(address-decode ad dest data)
      (cond ((= opcode 0) (rrc value set-fun))
	    ((= opcode 1) (swpb value set-fun))
	    ((= opcode 2) (rra value set-fun))
	    ((= opcode 3) (sxt value set-fun))
	    ((= opcode 4) (psh value set-fun))
	    ((= opcode 5) (call value set-fun))))))
	      ;RETI isn't implemented because it's not in the CTF

(defun rrc (value set-fun)
  (let ((carry (ldb (byte 1 0) value))
	(tmp (ash value -1)))
    (let ((res (dpb (get-c) (byte 1 15) tmp)))
      (funcall set-fun res)
      (set-v (if (and (= (get-c) 1)
		      (= (ldb (byte 1 15) value)))
		 1
		 0))
      (set-c carry)
      (set-n (negp res))
      (set-z (nullp res)))))

(defun swpb (value set-fun)
  (let ((low (ldb (byte 8 8) value))
	(high (ldb (byte 8 0) value)))
    (funcall set-fun (+ (* 256 high) low))))

(defun rra (value set-fun)
  (let ((res (ash value -1)))
    (funcall set-fun res)
    (set-c (ldb (byte 1 0) value))
    (set-n (negp res))
    (set-v 0)
    (set-z (nullp res))))

(defun sxt (value set-fun)
  (let ((res (dpb (* 255 (ldb (byte 1 7) value)) (byte 8 8) value)))
    (funcall set-fun res)
    (set-c (if (= res 0)
	       0
	       1))
    (set-v 0)
    (set-n (negp res))
    (set-z (nullp res))))

(defun psh (value set-fun)
  (setf (elt *mem* (reg 1)) value)
  (incf (elt *reg* 1) -2))

(defun call (value set-fun)
  (psh (reg 0) 'nil)
  (setf (elt *reg* 0) value))

(defun jump-decode (instn)
  (let ((type (ldb (byte 3 10) instn))
	(offset (ldb (byte 10 0) instn))
	(z (flag 1))
	(c (flag 0))
	(n (flag 2))
	(v (flag 8)))
    (cond ((= type 0) (if (= z 0) (jmp offset)))
	  ((= type 1) (if (= z 1) (jmp offset)))
	  ((= type 2) (if (= c 0) (jmp offset)))
	  ((= type 3) (if (= c 1) (jmp offset)))
	  ((= type 4) (if (= n 1) (jmp offset)))
	  ((= type 5) (if (= n v) (jmp offset)))
	  ((= type 6) (if (/= n v) (jmp offset)))
	  ((= type 7) (jmp offset)))))

(defun jmp (offset)
  (setf (elt *reg* 0) (+ (reg 0) 2
		   (- (ldb (byte 9 0) offset)
		      (* (ldb (byte 1 9) offset) 1024))))
  t)

(defun double-decode (instn data1 data2)
  (let ((opcode (ldb (byte 4 12) instn))
	(source (ldb (byte 4 8) instn))
	(ad (ldb (byte 1 7) instn))
	(as (ldb (byte 2 4) instn))
	(dest (ldb (byte 4 0) instn)))
    (multiple-value-bind (dest-val dest-fun)
	(address-decode ad dest data2)
      (multiple-value-bind (source-val source-fun)
	  (address-decode as source data1)
	(cond ((= opcode 4) (mov source-val dest-fun))
	      ((= opcode 5) (add source-val dest-val dest-fun))
	      ((= opcode 6) (addc source-val dest-val dest-fun))
	      ((= opcode 7) (subc source-val dest-val dest-fun))
	      ((= opcode 8) (sub source-val dest-val dest-fun))
	      ((= opcode 9) (cmp source-val dest-val))
	      ((= opcode 10) (dadd source-val dest-val dest-fun))
	      ((= opcode 11) (emu-bit source-val dest-val))
	      ((= opcode 12) (bic source-val dest-val dest-fun))
	      ((= opcode 13) (bis source-val dest-val dest-fun))
	      ((= opcode 14) (xor source-val dest-val dest-fun))
	      ((= opcode 15) (emu-and source-val dest-val dest-fun)))))))

(defun mov (val dest-fun)
  (funcall dest-fun val))

(defun add-flags (res)
  (set-c (ldb (byte 1 16) res))
  (set-v (ldb (byte 1 16) res))
  (set-n (negp res))
  (set-z (nullp res)))

(defun add (source-val dest-val dest-fun)
  (let ((res (+ source-val dest-val)))
    (funcall dest-fun (mod res 65536))
    (add-flags res)))

(defun addc (source-val dest-val dest-fun)
  (let ((res (+ source-val dest-val (get-c))))
    (funcall dest-fun (mod res 65536))
    (add-flags res)))

(defun subc (source-val dest-val dest-fun)
  (let ((res (+ dest-val (lognot source-val) (get-c) 1))) ;random +1 for bug compat
    (funcall dest-fun (mod res 65536))
    (add-flags res)))

(defun sub (source-val dest-val dest-fun)
  (let ((res (+ dest-val (lognot source-val) 1)))
    (funcall dest-fun (mod res 65536))
    (add-flags res)))

(defun cmp (source-val dest-val)
  (let ((res (+ dest-val (lognot source-val) 1)))
    (add-flags res)))

(defun dadd (source-val dest-val dest-fun)
  (let ((res (loop for i in (list 0 4 8 12)
		for c = 0 then (if (>= tmp 10)
				   1
				   0)
		for tmp = (+ (ldb (byte 4 i) source-val)
			     (ldb (byte 4 i) dest-val)
			     c)
		for tmp2 = (if (>= tmp 10)
			      (- tmp 10)
			      tmp)
		for val = tmp2 then (dpb tmp2 (byte 4 i) val)
		finally (progn (set-c c)
			       (if (ldb (byte 1 3) tmp)
				   (set-n 1))
			       (return val)))))
    (funcall dest-fun res)))

(defun emu-bit (source-val dest-val)
  (let ((res (logand source-val dest-val)))
    (set-v 0)
    (set-n (ldb (byte 1 15) res))
    (set-z (nullp res))
    (set-c (nullp res))))

(defun bic (source-val dest-val dest-fun)
  (let ((res (logand (lognot source-val) dest-val)))
    (funcall dest-fun res)))

(defun bis (source-val dest-val dest-fun)
  (funcall dest-fun (logior source-val dest-val)))

(defun xor (source-val dest-val dest-fun)
  (let ((res (logxor source-val dest-val)))
    (funcall dest-fun res)
    (set-v (* (ldb (byte 1 15) source-val)
	      (ldb (byte 1 15) dest-val)))
    (set-n (ldb (byte 1 15) res))
    (set-z (nullp res))
    (set-c (nullp res))))

(defun emu-and (source-val dest-val dest-fun)
  (let ((res (logand source-val dest-val)))
    (funcall dest-fun res)
    (set-v 0)
    (set-n (ldb (byte 1 15) res))
    (set-z (nullp res))
    (set-c (nullp res))))

(let ((test2 19))
  (print (lognot test2)))

error: pathspec 'msp430.cl' did not match any file(s) known to git


debug cl

debug cl

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Saytiras/Massively-Parallel-Algorithms.git/'


simplified freq domain kernel by writing in terms of complex no.... still slightly wrong - may be pre-factors such as N etc.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/beaylott/bagwacl.git/'


added missing kernel file

added missing kernel file

/*******************************************************************************
 *
 * MIT License
 *
 * Copyright (c) 2017 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
inline uint iMod(uint v, uint u, uint d)
{
    uint r = v - mul24(u, d);
    return (r);
}

// N - batch size
// C - # of maps
// H - map height
// W - map width

// RD_BLCK = ((H*W)%8==0) ? 8 : ((H*W)%4==0) ? 4 : ((H*W)%3==0)? 3 : ((H*W)%2==0)? 2 : 1;
// HW_RD = (H*W)/RD_BLCK
// MAP_RD = HW_RD*C

// lcl size0 = ((MAP_RD + 63)/64 < 8) ? ((MAP_RD + 63)/64)*64 : 512;
// local size = (lcl size0, 1, 1)
// global size = (MAP_RD, N, 1)

#ifdef NC_TRANS_NCHW_OPT
__kernel void transpose_NCHW2CNHW_opt(const global float* in, global float* out)
{
    // to reduce granularity loss
    uint c_p_blck = get_global_id(0);
    uint c        = c_p_blck / HW_RD;
    uint p_blck   = iMod(c_p_blck, c, HW_RD);
    uint b        = get_global_id(1);

    uint in_off                 = b * C * H * W + c_p_blck * RD_BLCK + IN_OFF;
    uint out_off                = b * H * W + c * N * H * W + p_blck * RD_BLCK + OUT_OFF;
    const global READ_TYPE* cin = (const global READ_TYPE*)(in + in_off);
    global READ_TYPE* cout      = (global READ_TYPE*)(out + out_off);
    *cout                       = *cin;
}
#endif

#ifdef NC_TRANS_CNHW_OPT
__kernel void transpose_CNHW2NCHW_opt(const global float* in, global float* out)
{
    // to reduce granularity loss
    uint c_p_blck = get_global_id(0);
    uint c        = c_p_blck / HW_RD;
    uint p_blck   = iMod(c_p_blck, c, HW_RD);
    uint b        = get_global_id(1);

    uint in_off                 = b * H * W + c * N * H * W + p_blck * RD_BLCK + IN_OFF;
    uint out_off                = b * C * H * W + c_p_blck * RD_BLCK + OUT_OFF;
    const global READ_TYPE* cin = (const global READ_TYPE*)(in + in_off);
    global READ_TYPE* cout      = (global READ_TYPE*)(out + out_off);
    *cout                       = *cin;
}
#endif

#ifdef NC_TRANS_NCHW
__kernel void transpose_NCHW2CNHW(const global float* in, global float* out)
{
    int i   = get_global_id(0);
    int n_i = get_group_id(1);

    int hw_i = i % HW_OUT;
    int h_i  = hw_i / W_OUT;
    int w_i  = hw_i % W_OUT;
    int c_i  = i / HW_OUT;

    const global float* in_off = in + IN_OFF;
    global float* out_off      = out + OUT_OFF;

    out_off[c_i * N * HW_OUT + n_i * HW_OUT + hw_i] =
        in_off[n_i * C * HW_IN + c_i * HW_IN + h_i * H_STRIDE * W_IN + w_i * W_STRIDE];
}
#endif

#ifdef NC_TRANS_CNHW
__kernel void transpose_CNHW2NCHW(const global float* in, global float* out)
{
    int i   = get_global_id(0);
    int n_i = get_group_id(1);

    int hw_i = i % HW_OUT;
    int h_i  = hw_i / W_OUT;
    int w_i  = hw_i % W_OUT;
    int c_i  = i / HW_OUT;

    const global float* in_off = in + IN_OFF;
    global float* out_off      = out + OUT_OFF;

    out_off[n_i * C * HW_OUT + c_i * HW_OUT + hw_i] =
        in_off[c_i * N * HW_IN + n_i * HW_IN + h_i * H_STRIDE * W_IN + w_i * W_STRIDE];
}
#endif

error: pathspec 'src/kernels/MIOpenUtilKernels4.cl' did not match any file(s) known to git


Initial version that updates to wMax for LIF neuron layer. This is based on LIF_update_state.cl.

git-svn-id: 602a26e73ae9f2a14e2bb95676f2e137fcc39919@3454 7c0444ca-5550-0410-9008-faecdbe78eb5

#include "LIF_params.h"
#include "cl_random.hcl"
#include "../utils/pv_random.h"

#ifndef PV_USE_OPENCL
#  include <math.h>
#  define EXP expf
#  define CL_KERNEL
#  define CL_MEM_GLOBAL
#  define CL_MEM_LOCAL
#else  /* compiling with OpenCL */
#  define EXP exp
#  define CL_KERNEL       __kernel
#  define CL_MEM_GLOBAL   __global
#  define CL_MEM_LOCAL    __local
#  include "conversions.hcl"
#endif

//
// update the state of a retinal layer (spiking)
//
//    assume called with 1D kernel
//
CL_KERNEL
void LIF_update_state_localWmax(
    const float time,
    const float dt,

    const int nx,
    const int ny,
    const int nf,
    const int nb,

    const float tauWmax,
    const float alphaW,
    const float averageR,

    CL_MEM_GLOBAL LIF_params * params,
    CL_MEM_GLOBAL uint4 * rnd,
    CL_MEM_GLOBAL float * V,
    CL_MEM_GLOBAL float * Vth,
    CL_MEM_GLOBAL float * G_E,
    CL_MEM_GLOBAL float * G_I,
    CL_MEM_GLOBAL float * G_IB,
    CL_MEM_GLOBAL float * phiExc,
    CL_MEM_GLOBAL float * phiInh,
    CL_MEM_GLOBAL float * phiInhB,
    CL_MEM_GLOBAL float * R,
    CL_MEM_GLOBAL float * Wmax,
    CL_MEM_GLOBAL float * activity)
{
   int k;

   const float exp_tauE    = EXP(-dt/params->tauE);
   const float exp_tauI    = EXP(-dt/params->tauI);
   const float exp_tauIB   = EXP(-dt/params->tauIB);
   const float exp_tauVth  = EXP(-dt/params->tauVth);

   const float dt_sec = .001 * dt;   // convert to seconds
   const float tauRate = params->tauRate;
   const float exp_tauRate = EXP(-dt/tauRate);
   const float exp_tauWmax = EXP(-dt/tauWmax);

#ifndef PV_USE_OPENCL

for (k = 0; k < nx*ny*nf; k++) {
#else
   k = get_global_id(0);
#endif

   int kex = kIndexExtended(k, nx, ny, nf, nb);

   //
   // kernel (nonheader part) begins here
   //

   // local param variables
   float tau, Vrest, VthRest, Vexc, Vinh, VinhB, deltaVth;

   const float GMAX = 10.0;

   // local variables
   float l_activ;

   uint4 l_rnd = rnd[k];

   float l_V   = V[k];
   float l_Vth = Vth[k];

   float l_G_E  = G_E[k];
   float l_G_I  = G_I[k];
   float l_G_IB = G_IB[k];

   float l_phiExc  = phiExc[k];
   float l_phiInh  = phiInh[k];
   float l_phiInhB = phiInhB[k];

   float l_R = R[k];
   float l_Wmax = Wmax[kex];

   // temporary arrays
   float tauInf, VmemInf;

   //
   // start of LIF2_update_exact_linear
   //

   // define local param variables
   //
   tau   = params->tau;
   Vexc  = params->Vexc;
   Vinh  = params->Vinh;
   VinhB = params->VinhB;
   Vrest = params->Vrest;

   VthRest  = params->VthRest;
   deltaVth = params->deltaVth;

   // add noise
   //

#undef CLRANDOM

#ifdef CLRANDOM
   l_rnd = cl_random_get(l_rnd);
   if (cl_random_prob(l_rnd) < dt_sec*params->noiseFreqE) {
      l_rnd = cl_random_get(l_rnd);
      l_phiExc = l_phiExc + params->noiseAmpE*cl_random_prob(l_rnd);
   }

   l_rnd = cl_random_get(l_rnd);
   if (cl_random_prob(l_rnd) < dt_sec*params->noiseFreqI) {
      l_rnd = cl_random_get(l_rnd);
      l_phiInh = l_phiInh + params->noiseAmpI*cl_random_prob(l_rnd);
   }

   l_rnd = cl_random_get(l_rnd);
   if (cl_random_prob(l_rnd) < dt_sec*params->noiseFreqIB) {
      l_rnd = cl_random_get(l_rnd);
      l_phiInhB = l_phiInhB + params->noiseAmpIB*cl_random_prob(l_rnd);
   }
#else
   if (pv_random_prob() < dt_sec*params->noiseFreqE) {
      l_phiExc = l_phiExc + params->noiseAmpE*pv_random_prob();
   }

   if (pv_random_prob() < dt_sec*params->noiseFreqI) {
      l_phiInh = l_phiInh + params->noiseAmpI*pv_random_prob();
   }

   if (pv_random_prob() < dt_sec*params->noiseFreqIB) {
      l_phiInhB = l_phiInhB + params->noiseAmpIB*pv_random_prob();
   }
#endif
   // l_phi channels must be divided by tau_E, ... in each channel expressed in ms?!
   l_G_E  = l_phiExc  + l_G_E *exp_tauE;
   l_G_I  = l_phiInh  + l_G_I *exp_tauI;
   l_G_IB = l_phiInhB + l_G_IB*exp_tauIB;

   l_G_E  = (l_G_E  > GMAX) ? GMAX : l_G_E;
   l_G_I  = (l_G_I  > GMAX) ? GMAX : l_G_I;
   l_G_IB = (l_G_IB > GMAX) ? GMAX : l_G_IB;

   tauInf  = (dt/tau) * (1.0 + l_G_E + l_G_I + l_G_IB);
   VmemInf = (Vrest + l_G_E*Vexc + l_G_I*Vinh + l_G_IB*VinhB)
           / (1.0 + l_G_E + l_G_I + l_G_IB);

   l_V = VmemInf + (l_V - VmemInf)*EXP(-tauInf);;

   //
   // start of LIF2_update_finish
   //

   l_Vth = VthRest + (l_Vth - VthRest)*exp_tauVth;

   //
   // start of update_f
   //

//   l_G_E  = (l_G_E  > GMAX) ? GMAX : l_G_E;
//   l_G_I  = (l_G_I  > GMAX) ? GMAX : l_G_I;
//   l_G_IB = (l_G_IB > GMAX) ? GMAX : l_G_IB;

   bool fired_flag = (l_V > l_Vth);

   l_activ = fired_flag ? 1.0f             : 0.0f;
   l_V     = fired_flag ? Vrest            : l_V;
   l_Vth   = fired_flag ? l_Vth + deltaVth : l_Vth;
   l_G_IB  = fired_flag ? l_G_IB + 1.0f    : l_G_IB;

   // update average rate
   l_R = (l_activ / tauRate) + l_R*exp_tauRate;
   // multiply by 1000.0 to get the firing rate per second, which is how averageR is estimated
   l_Wmax = - alphaW * (1000.0*l_R - averageR) + (l_Wmax + alphaW * (1000.0*l_R - averageR)) * exp_tauWmax;
   //

   //
   // These actions must be done outside of kernel
   //    1. set activity to 0 in boundary (if needed)
   //    2. update active indices
   //

   // store local variables back to global memory
   //
   activity[kex] = l_activ;

   R[k] = l_R;
   Wmax[kex] = l_Wmax;

   V[k]   = l_V;
   Vth[k] = l_Vth;

   G_E[k]  = l_G_E;
   G_I[k]  = l_G_I;
   G_IB[k] = l_G_IB;

   phiExc[k]  = 0.0f;
   phiInh[k]  = 0.0f;
   phiInhB[k] = 0.0f;

#ifndef PV_USE_OPENCL
   } // loop over k
#endif

}

error: pathspec 'src/kernels/LIF_update_state_localWmax.cl' did not match any file(s) known to git


Minor tweak to make atomic_cmpxchg_false_race test clearer.

kernel void atomic_cmpxchg_false_race(global int *data, local int *scratch)
{
  int l = get_local_id(0);
  if (l == 0)
  {
    scratch[0] = 0;
  }
  barrier(CLK_LOCAL_MEM_FENCE);

  bool done = false;
  int before, old;
  int result;
  for (int i = 0; i < get_local_size(0); i++)
  {
    barrier(CLK_LOCAL_MEM_FENCE);
    before = scratch[0];
    barrier(CLK_LOCAL_MEM_FENCE);

    if (!done)
    {
      old = atomic_cmpxchg(scratch, before, before+1);
      if (old == before)
      {
        done = true;
        result = scratch[0];
      }
    }
  }

  barrier(CLK_LOCAL_MEM_FENCE);
  if (l == 0)
  {
    *data = *scratch;
  }
  data[l+1] = result;
}

kernel void atomic_cmpxchg_false_race(global int *data, local int *scratch)
{
  int l = get_local_id(0);
  if (l == 0)
  {
    scratch[0] = 0;
  }
  barrier(CLK_LOCAL_MEM_FENCE);

  bool done = false;
  int before, old;
  int result;
  for (int i = 0; i < get_local_size(0); i++)
  {
    barrier(CLK_LOCAL_MEM_FENCE);
    before = scratch[0];
    barrier(CLK_LOCAL_MEM_FENCE);

    if (!done)
    {
      old = atomic_cmpxchg(scratch, before, before+1);
    }

    if (old == before)
    {
      done = true;
      result = scratch[0];
    }
  }

  barrier(CLK_LOCAL_MEM_FENCE);
  if (l == 0)
  {
    *data = *scratch;
  }
  data[l+1] = result;
}


Removed a blank

Removed a blank

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/HongjianLi/opencl.git/'