GpuThreadIndex

The index of the running thread within its block.

Declaration

Sintaxe

GpuThreadIndex(int dim, ttype type, expr? value)

Argumentos

Argument

Descrição

dim

which dimension to report, counting from zero.

type

the type of the expression.

value

the compile time value of the expression, when the frontend could fold it; nil otherwise.

Valores de retorno

The value of the expression.

Descrição

Every thread of a kernel runs the same body, and this is what tells them apart. The index counts from zero within the block; the position in the whole grid is GpuBlockIndex * GpuBlockSize + GpuThreadIndex. In a kernel whose layout has lanes (see gpu_kernel_layout), that position numbers the iterations, which several threads share: the lanes, which GpuLaneIndex tells apart.

Exemplos

(GpuThreadIndex
  :dim 0
  :type (Integer
    :kind 4
  )
  :value nil
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "m" (Module
        :symtab (SymbolTable
          :id 1
          :symbols {
            "scale" (Function
              :symtab (SymbolTable
                :id 2
                :symbols {
                  "a" (Variable
                    :parent_symtab 2
                    :name "a"
                    :dependencies []
                    :intent :InOut
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (Array
                      :type (Real
                        :kind 4
                      )
                      :dims [
                        (dimension
                          :start (IntegerConstant
                            :n 1
                            :type (Integer
                              :kind 4
                            )
                            :intboz_type :Decimal
                          )
                          :length (IntegerConstant
                            :n 256
                            :type (Integer
                              :kind 4
                            )
                            :intboz_type :Decimal
                          )
                        )
                      ]
                      :physical_type :FixedSizeArray
                      :memory_space :Global
                    )
                    :type_declaration nil
                    :abi :Source
                    :access :Public
                    :presence :Required
                    :value_attr false
                    :target_attr false
                    :contiguous_attr false
                    :bindc_name nil
                    :is_volatile false
                    :is_asynchronous false
                    :is_protected false
                    :pass_attr :NotMethod
                    :self_argument nil
                    :codims []
                    :common_block nil
                  )
                  "i" (Variable
                    :parent_symtab 2
                    :name "i"
                    :dependencies []
                    :intent :Local
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (Integer
                      :kind 4
                    )
                    :type_declaration nil
                    :abi :Source
                    :access :Public
                    :presence :Required
                    :value_attr false
                    :target_attr false
                    :contiguous_attr false
                    :bindc_name nil
                    :is_volatile false
                    :is_asynchronous false
                    :is_protected false
                    :pass_attr :NotMethod
                    :self_argument nil
                    :codims []
                    :common_block nil
                  )
                }
              )
              :name "scale"
              :function_signature (FunctionType
                :arg_types [
                  (Array
                    :type (Real
                      :kind 4
                    )
                    :dims [
                      (dimension
                        :start (IntegerConstant
                          :n 1
                          :type (Integer
                            :kind 4
                          )
                          :intboz_type :Decimal
                        )
                        :length (IntegerConstant
                          :n 256
                          :type (Integer
                            :kind 4
                          )
                          :intboz_type :Decimal
                        )
                      )
                    ]
                    :physical_type :FixedSizeArray
                    :memory_space :Global
                  )
                ]
                :return_var_type nil
                :abi :Source
                :deftype :Implementation
                :bindc_name nil
                :elemental false
                :pure false
                :module false
                :inline false
                :static false
                :restrictions []
                :is_restriction false
                :exec_space :Kernel
              )
              :dependencies []
              :args [
                (Var
                  :v (SymbolRef 2 "a")
                )
              ]
              :body [
                (Assignment
                  :target (Var
                    :v (SymbolRef 2 "i")
                  )
                  :value (IntegerBinOp
                    :left (GpuThreadIndex
                      :dim 0
                      :type (Integer
                        :kind 4
                      )
                      :value nil
                    )
                    :op :Add
                    :right (IntegerConstant
                      :n 1
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :type (Integer
                      :kind 4
                    )
                    :value nil
                  )
                  :overloaded nil
                  :realloc_lhs false
                  :move_allocation false
                  :new_target false
                  :new_allocation false
                )
                (Assignment
                  :target (Var
                    :v (SymbolRef 2 "i")
                  )
                  :value (IntegerBinOp
                    :left (GpuBlockIndex
                      :dim 0
                      :type (Integer
                        :kind 4
                      )
                      :value nil
                    )
                    :op :Mul
                    :right (GpuBlockSize
                      :dim 0
                      :type (Integer
                        :kind 4
                      )
                      :value nil
                    )
                    :type (Integer
                      :kind 4
                    )
                    :value nil
                  )
                  :overloaded nil
                  :realloc_lhs false
                  :move_allocation false
                  :new_target false
                  :new_allocation false
                )
                (Assignment
                  :target (ArrayItem
                    :v (Var
                      :v (SymbolRef 2 "a")
                    )
                    :args [
                      (array_index
                        :left nil
                        :right (Var
                          :v (SymbolRef 2 "i")
                        )
                        :step nil
                      )
                    ]
                    :type (Real
                      :kind 4
                    )
                    :storage_format :ColMajor
                    :value nil
                    :in_bounds false
                  )
                  :value (RealConstant
                    :r 0.0
                    :type (Real
                      :kind 4
                    )
                  )
                  :overloaded nil
                  :realloc_lhs false
                  :move_allocation false
                  :new_target false
                  :new_allocation false
                )
              ]
              :return_var nil
              :access :Public
              :deterministic false
              :side_effect_free false
              :module_file nil
            )
          }
        )
        :name "m"
        :parent_module nil
        :dependencies []
        :loaded_from_mod false
        :intrinsic false
        :has_submodules false
        :global_init nil
      )
      "main" (Program
        :symtab (SymbolTable
          :id 3
          :symbols {}
        )
        :name "main"
        :dependencies []
        :body []
        :global_init nil
      )
    }
  )
  :items []
  :global_init nil
)

Veja Também

exec_space, GpuKernelLaunch, GpuThreadIndex, GpuBlockIndex, GpuBlockSize