- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Exception thrown at 0x00007FF94628AC4D (igc64.dll) in dpc please work!.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
press 2 select gp
When i try use my intel gpu i get this error i cannot fix it!
using laptop
trying to use GPU 0
<-------CODE-------->
#include <CL/sycl.hpp>
#include <iostream>
#include <fstream>
#include <cmath>
#include <chrono>
using namespace sycl;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
using std::cout;
using std::endl;
using std::ofstream;
typedef std::chrono::steady_clock the_clock;
const int WIDTH = 1920;
const int HEIGHT = 1080;
const int MAX_ITERATIONS = 500;
uint32_t img[HEIGHT][WIDTH];
void write_tga(const char* filename)
{
ofstream outfile(filename, ofstream::binary);
uint8_t header[18] = {
0, // no img ID
0, // no colour map
2, // uncompressed 24-bit img
0, 0, 0, 0, 0, // empty colour map specification
0, 0, // X origin
0, 0, // Y origin
WIDTH & 0xFF, (WIDTH >>
HEIGHT & 0xFF, (HEIGHT >>
24, // bits per pixel
0, // img descriptor
};
outfile.write((const char*)header, 18);
for (int y = 0; y < HEIGHT; ++y)
{
for (int x = 0; x < WIDTH; ++x)
{
uint8_t pixel[3] = {
img[y][x] & 0xFF, // blue channel
(img[y][x] >>
(img[y][x] >> 16) & 0xFF, // red channel
};
outfile.write((const char*)pixel, 3);
}
}
outfile.close();
if (!outfile)
{
// An error has occurred at some point since we opened the file.
std::cout << "Error writing to " << filename << std::endl;
exit(1);
}
}
void write_tgaK9(const char* filename, uint32_t* img)
{
std::ofstream file(filename, std::ios::binary);
// TGA header
uint8_t header[18] = { 0 };
header[2] = 2; // truecolor
header[12] = WIDTH & 0xFF;
header[13] = WIDTH >> 8;
header[14] = HEIGHT & 0xFF;
header[15] = HEIGHT >> 8;
header[16] = 24; // bits per pixel
file.write(reinterpret_cast<char*>(header), sizeof(header));
// Pixel data
for (int y = 0; y < HEIGHT; ++y)
{
for (int x = 0; x < WIDTH; ++x)
{
uint32_t pixel = img[y * WIDTH + x];
uint8_t b = pixel & 0xFF;
uint8_t g = (pixel >>
uint8_t r = (pixel >> 16) & 0xFF;
file.put(b);
file.put(g);
file.put(r);
}
}
file.close();
}
struct ComplexF {
float x;
float y;
};
ComplexF c_add(ComplexF c1, ComplexF c2)
{
ComplexF tmp;
float a = c1.x;
float b = c1.y;
float c = c2.x;
float d = c2.y;
tmp.x = a + c;
tmp.y = b + d;
return tmp;
} // c_add
float c_abs(ComplexF c)
{
return sycl::sqrt(c.x * c.x + c.y * c.y);
} // c_abs
ComplexF c_mul(ComplexF c1, ComplexF c2)
{
ComplexF tmp;
float a = c1.x;
float b = c1.y;
float c = c2.x;
float d = c2.y;
tmp.x = a * c - b * d;
tmp.y = b * c + a * d;
return tmp;
} // c_mul
void selectDevice(queue& Q)
{
int whatToUse{};
std::cout << "Enter 1 for CPU, 2 for GPU: ";
std::cin >> whatToUse;
if (whatToUse == 1)
{
std::cout << "You have selected CPU\n";
Q = queue(cpu_selector{});
}
else if (whatToUse == 2)
{
std::cout << "You have selected GPU\n";
Q = queue(gpu_selector{});
}
else
{
std::cout << "Invalid selection. Exiting...\n";
std::cout << "Defaulting to CPU\n";
Q = queue(cpu_selector{});
}
system("cls");
}
void generateJuliaSet(queue& Q, buffer<uint32_t, 2>& img_buf)
{
Q.submit([&](handler& h) {
auto img_acc = img_buf.get_access<access::mode::write>(h);
h.parallel_for(range<2>(HEIGHT, WIDTH), [=](id<2> idx) {
auto y = idx[0]; // Row
auto x = idx[1]; // Column
float left = -2.0, right = 2.0, top = 2.0, bottom = -2.0;
ComplexF z = { left + (right - left) * x / WIDTH, top + (bottom - top) * y / HEIGHT };
ComplexF c = { 0.285f, 0.01f }; // You can change these values for different Julia sets
int iterations = 0;
while (c_abs(z) < 2.0f && iterations < MAX_ITERATIONS) {
z = c_add(c_mul(z, z), c);
iterations++;
}
if (iterations == MAX_ITERATIONS)
{
// z didn't escape from the circle.
// This point is in the Julia set.
img_acc[{y, x}] = 0x000000; // black
}
else
{
uint8_t red = static_cast<uint8_t>(128.0f + cos(iterations * 0.15f) * 128.0f);
uint8_t green = static_cast<uint8_t>(128.0f + cos(iterations * 0.16f) * 128.0f);
uint8_t blue = static_cast<uint8_t>(128.0f + sin(iterations * 0.17f) * 128.0f);
img_acc[{y, x}] = (red << 16) | (green <<
}
});
});
Q.wait();
//Declare the host accessor host_acc to read from the buffer img_buf
auto host_acc = img_buf.get_access<access::mode::read>();
for (int y = 0; y < HEIGHT; ++y)
{
for (int x = 0; x < WIDTH; ++x) {
img[y][x] = host_acc[y][x];
if ((y < 5) && (x < 5)) {
std::cout << host_acc[y][x] << ", ";
}
}
if (y < 5) {
std::cout << "\n";
}
}
write_tga("Julia.tga");
}
// implement a function to generate a Julia set using nd-range
void generateJuliaSetNDRange(queue& Q, buffer<uint32_t, 2>& img_buf)
{
Q.submit([&](handler& h) {
auto img_acc = img_buf.get_access<access::mode::write>(h);
h.parallel_for(nd_range<2>(range<2>(HEIGHT, WIDTH), range<2>(1, 1)), [=](nd_item<2> idx) {
auto y = idx.get_global_id(0); // Row
auto x = idx.get_global_id(1); // Column
float left = -2.0, right = 2.0, top = 2.0, bottom = -2.0;
ComplexF z = { left + (right - left) * x / WIDTH, top + (bottom - top) * y / HEIGHT };
ComplexF c = { 0.285f, 0.01f }; // You can change these values for different Julia sets
int iterations = 0;
while (c_abs(z) < 2.0f && iterations < MAX_ITERATIONS) {
z = c_add(c_mul(z, z), c);
iterations++;
}
if (iterations == MAX_ITERATIONS)
{
// z didn't escape from the circle.
// This point is in the Julia set.
img_acc[{y, x}] = 0x000000; // black
}
else
{
uint8_t red = static_cast<uint8_t>(128.0f + cos(iterations * 0.15f) * 128.0f);
uint8_t green = static_cast<uint8_t>(128.0f + cos(iterations * 0.16f) * 128.0f);
uint8_t blue = static_cast<uint8_t>(128.0f + sin(iterations * 0.17f) * 128.0f);
img_acc[{y, x}] = (red << 16) | (green <<
}
});
});
Q.wait();
//Declare the host accessor host_acc to read from the buffer img_buf
auto host_acc = img_buf.get_access<access::mode::read>();
for (int y = 0; y < HEIGHT; ++y)
{
for (int x = 0; x < WIDTH; ++x) {
img[y][x] = host_acc[y][x];
if ((y < 5) && (x < 5)) {
std::cout << host_acc[y][x] << ", ";
}
}
if (y < 5) {
std::cout << "\n";
}
}
write_tga("JuliaUsingNDRANGE.tga");
}
void generateJuliaSetUSM(queue& Q)
{
// Allocate shared memory for the image
uint32_t* img = malloc_shared<uint32_t>(WIDTH * HEIGHT, Q);
Q.submit([&](handler& h) {
h.parallel_for(range<2>(HEIGHT, WIDTH), [=](id<2> idx) {
auto y = idx[0]; // Row
auto x = idx[1]; // Column
float left = -2.0, right = 2.0, top = 2.0, bottom = -2.0;
ComplexF z = { left + (right - left) * x / WIDTH, top + (bottom - top) * y / HEIGHT };
ComplexF c = { 0.285f, 0.01f }; // You can change these values for different Julia sets
int iterations = 0;
while (c_abs(z) < 2.0f && iterations < MAX_ITERATIONS) {
z = c_add(c_mul(z, z), c);
iterations++;
}
if (iterations == MAX_ITERATIONS)
{
// z didn't escape from the circle.
// This point is in the Julia set.
img[y * WIDTH + x] = 0x000000; // black
}
else
{
uint8_t red = static_cast<uint8_t>(128.0f + cos(iterations * 0.15f) * 128.0f);
uint8_t green = static_cast<uint8_t>(128.0f + cos(iterations * 0.16f) * 128.0f);
uint8_t blue = static_cast<uint8_t>(128.0f + sin(iterations * 0.17f) * 128.0f);
img[y * WIDTH + x] = (red << 16) | (green <<
}
});
});
Q.wait();
// Write the image to a file
write_tgaK9("JuliaUSM.tga", img);
// Free the shared memory
free(img, Q);
}
void generateJuliaSetBuffers(queue& Q)
{
// Allocate shared memory for the image
uint32_t* img = malloc_shared<uint32_t>(WIDTH * HEIGHT, Q);
buffer<uint32_t, 1> img_buf(img, range<1>(WIDTH * HEIGHT));
Q.submit([&](handler& h) {
auto img_acc = img_buf.get_access<access::mode::write>(h);
h.parallel_for(range<1>(WIDTH * HEIGHT), [=](id<1> idx) {
auto x = idx[0]; // Column
auto y = x / WIDTH; // Row
float left = -2.0, right = 2.0, top = 2.0, bottom = -2.0;
ComplexF z = { left + (right - left) * x / WIDTH, top + (bottom - top) * y / HEIGHT };
ComplexF c = { 0.285f, 0.01f }; // You can change these values for different Julia sets
int iterations = 0;
while (c_abs(z) < 2.0f && iterations < MAX_ITERATIONS) {
z = c_add(c_mul(z, z), c);
iterations++;
}
if (iterations == MAX_ITERATIONS)
{
// z didn't escape from the circle.
// This point is in the Julia set.
img_acc[idx] = 0x000000; // black
}
else
{
uint8_t red = static_cast<uint8_t>(128.0f + cos(iterations * 0.15f) * 128.0f);
uint8_t green = static_cast<uint8_t>(128.0f + cos(iterations * 0.16f) * 128.0f);
uint8_t blue = static_cast<uint8_t>(128.0f + sin(iterations * 0.17f) * 128.0f);
img_acc[idx] = (red << 16) | (green <<
}
});
});
Q.wait();
// Write the image to a file
write_tgaK9("JuliaBuffers.tga", img);
// Free the shared memory
free(img, Q);
}
int main()
{
queue Q;
selectDevice(Q);
//std::cout << "Device name: " << Q.get_device().get_info<info::device::name>() << "\n";
//std::cout << "Device vendor: " << Q.get_device().get_info<info::device::vendor>() << "\n";
//std::cout << "Device version: " << Q.get_device().get_info<info::device::version>() << "\n";
//std::cout << "Device driver version: " << Q.get_device().get_info<info::device::driver_version>() << "\n";
//std::cout << "Device global memory size: " << Q.get_device().get_info<info::device::global_mem_size>() << " bytes\n";
//std::cout << "Device local memory size: " << Q.get_device().get_info<info::device::local_mem_size>() << " bytes\n";
//std::cout << "Device max compute units: " << Q.get_device().get_info<info::device::max_compute_units>() << "\n";
//std::vector<uint32_t> data(HEIGHT * WIDTH);
//buffer<uint32_t, 2> img_buf(data.data(), range<2>(HEIGHT, WIDTH));
//// generate a Julia set, a type of fractal, in parallel on a selected device(CPU or GPU).
//auto start = the_clock::now();
//generateJuliaSet(Q, img_buf);
//auto end = the_clock::now();
//auto time_taken = duration_cast<milliseconds>(end - start).count();
//std::cout << "using " << Q.get_device().get_info<info::device::name>() << " it took " << time_taken << " ms\n";
//
//// generate a Julia set using nd-range
//start = the_clock::now();
//generateJuliaSetNDRange(Q, img_buf);
//end = the_clock::now();
//time_taken = duration_cast<milliseconds>(end - start).count();
//std::cout << "using " << Q.get_device().get_info<info::device::name>() << " it took " << time_taken << " ms\n";
std::cout << "Parallel Mandelbrot set using USM.\n";
auto start = the_clock::now();
generateJuliaSetUSM(Q);
auto end = the_clock::now();
auto time_taken = duration_cast<milliseconds>(end - start).count();
std::cout << "using " << Q.get_device().get_info<info::device::name>() << " it took " << time_taken << " ms\n";
std::cout << "Parallel Mandelbrot set using USM.\n";
std::cout << "Parallel Mandelbrot set using buffers.\n";
return 0;
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please send your reproducer as an attachment? The code provided seems to have some problem and cannot be compiled.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page