Unary Minus in FP16 & defining Variable in FP16


Do we have specific Unary Minus in FP16?



What about the -= operator?

Here I am not finding it.

Is it possible to define a variable like this:

half A[4] = {0, 0, 0, 0};

Or I have to do it like this:

__half A[4] = {0, 0, 0, 0};

Another question is about accessing to and element. Is below linne correct?

const __half *B;
B=C    // C refers to an allocated __half memory space
int jb=16;
const __half *Blast = B + jb;

that should work

either should work

You should be able to do pointer arithmetic as usual on half pointers. I’m not sure I understand the question fully. You are missing semicolons and it’s not sensible to attempt to assign a const variable in C++ after its point of definition. However, for example, this should give expected behavior, similar to the expected behavior if you replaced every instance of __half with float:

__half *C = (__half *)malloc(64);
const __half *B = C;
int jb=16;
const __half *Blast = B + jb;
// Blast now points to the element at index 16 of B (or C)

This demonstrates a few of your questions:

$ cat t1976.cu
#include <cuda_fp16.h>
#include <cstdio>

__global__ void k(){

  half A[4] = {0, 0, 1, 0};
  half B = -A[2];
  half C = 0;
  C -= B;
  printf("%f\n", __half2float(C));

int main(){

$ nvcc -arch=sm_70 -o t1976 t1976.cu
$ ./t1976