/** Scales a vector by a real constant; \f$ x = \alpha x \f$. @param[in] n Number of elements in vector x. n >= 0. @param[in] alpha Scalar \f$ \alpha \f$ (real) @param[in,out] dx COMPLEX array on GPU device. The n element vector x of dimension (1 + (n-1)*incx). @param[in] incx Stride between consecutive elements of dx. incx > 0. @ingroup magma_cblas1 */ extern "C" void magma_csscal( magma_int_t n, float alpha, magmaFloatComplex_ptr dx, size_t dx_offset, magma_int_t incx, magma_queue_t queue ) { if (n <= 0) return; cl_int err = clblasCsscal( n, alpha, dx, dx_offset, incx, 1, &queue, 0, NULL, g_event ); clFlush(queue); check_error( err ); }
int main(void) { cl_int err; cl_platform_id platform = 0; cl_device_id device = 0; cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 }; cl_context ctx = 0; cl_command_queue queue = 0; cl_mem bufX; cl_event event = NULL; int ret = 0; int lenX = 1 + (N-1)*abs(incx); /* Setup OpenCL environment. */ err = clGetPlatformIDs(1, &platform, NULL); if (err != CL_SUCCESS) { printf( "clGetPlatformIDs() failed with %d\n", err ); return 1; } err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL); if (err != CL_SUCCESS) { printf( "clGetDeviceIDs() failed with %d\n", err ); return 1; } props[1] = (cl_context_properties)platform; ctx = clCreateContext(props, 1, &device, NULL, NULL, &err); if (err != CL_SUCCESS) { printf( "clCreateContext() failed with %d\n", err ); return 1; } queue = clCreateCommandQueue(ctx, device, 0, &err); if (err != CL_SUCCESS) { printf( "clCreateCommandQueue() failed with %d\n", err ); clReleaseContext(ctx); return 1; } /* Setup clblas. */ err = clblasSetup(); if (err != CL_SUCCESS) { printf("clblasSetup() failed with %d\n", err); clReleaseCommandQueue(queue); clReleaseContext(ctx); return 1; } /* Prepare OpenCL memory objects and place vectors inside them. */ bufX = clCreateBuffer(ctx, CL_MEM_READ_WRITE, ( lenX * sizeof(cl_float2)), NULL, &err); err = clEnqueueWriteBuffer(queue, bufX, CL_TRUE, 0, (lenX * sizeof(cl_float2)), X, 0, NULL, NULL); /* Call clblas function. */ err = clblasCsscal( N, alpha, bufX, 0, incx, 1, &queue, 0, NULL, &event); if (err != CL_SUCCESS) { printf("clblasCsscal() failed with %d\n", err); ret = 1; } else { /* Wait for calculations to be finished. */ err = clWaitForEvents(1, &event); /* Fetch results of calculations from GPU memory. */ err = clEnqueueReadBuffer(queue, bufX, CL_TRUE, 0, (lenX * sizeof(cl_float2)), X, 0, NULL, NULL); /* At this point you will get the result of CSSCAL placed in vector X. */ printResult(); } /* Release OpenCL memory objects. */ clReleaseMemObject(bufX); /* Finalize work with clblas. */ clblasTeardown(); /* Release OpenCL working objects. */ clReleaseCommandQueue(queue); clReleaseContext(ctx); return ret; }