
Rev. 1.01
5AMD Code Sample for OpenCL
cl_int clStatus = CL_SUCCESS;
cl_file_amd clSsgFile = clCreateSsgFileObjectAMD(m_clContext,
CL_FILE_READ_ONLY_AMD, FILE_NAME, &clStatus);
if (clStatus != CL_SUCCESS) {
std::cout << "Error: Unable to create file handle." << std::endl;
return;
}
// Get the file-size information.
size_t retSize = 0;
LARGE_INTEGER SsgFileSize;
clStatus = clGetSsgFileObjectInfoAMD(clSsgFile, CL_FILE_SIZE_AMD,
sizeof(SsgFileSize), &SsgFileSize, &retSize);
if (clStatus != CL_SUCCESS) {
std::cout << "Error: Unable to retrieve file size." << std::endl;
return;
}
if (retSize != sizeof(SsgFileSize)) {
std::cout << "Error: Invalid file size info returned." << std::endl;
return;
}
// Get the sector-size information.
// Allocated buffer must align with the sector size for best performance.
cl_uint sectorSize = 0;
clStatus = clGetSsgFileObjectInfoAMD(clSsgFile, CL_FILE_BLOCK_SIZE_AMD,
sizeof(sectorSize), §orSize, &retSize);
if (clStatus != CL_SUCCESS) {
std::cout << "Error: Unable to retrieve file size." << std::endl;
return;
}
if (retSize != sizeof(sectorSize)) {
std::cout << "Error: Invalid sector size info returned." << std::endl;
return;
}
// Create buffer.
cl_mem clBuffer = clCreateBuffer(m_clContext, CL_MEM_ USE_PERSISTENT_MEM_AMD,
DATA_SIZE_IN_BYTES, nullptr, &clStatus);
if (clStatus != CL_SUCCESS) {
std::cout << "Error: Unable to create buffer." << std::endl;
return;
}
// Read information from the file; BUFF_OFFSET, SIZE_TO_READ and FILE_OFFSET must
// align with the sector size.
clStatus = clEnqueueReadSsgFileAMD(m_clCommandQueue, clBuffer, CL_TRUE, BUFF_OFFSET,
SIZE_TO_READ, clSsgFile, FILE_OFFSET, 0, NULL, NULL);
if (clStatus != CL_SUCCESS) {
std::cout << "Error: Data transfer failed." << std::endl;
}
// Release the file when you’re done with it.
clStatus = clReleaseSsgFileObjectAMD(clSsgFile);
if (clStatus != CL_SUCCESS) {
std::cout << "Warning: Unable to release file." << std::endl;
}
// Release the buffer when you’re done with it.
clStatus = clReleaseBuffer(clBuffer);
if (clStatus != CL_SUCCESS) {
std::cout << "Warning: Unable to release buffer." << std::endl;