repo_name
stringclasses
10 values
file_path
stringlengths
29
222
content
stringlengths
24
926k
extention
stringclasses
5 values
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/monte_carlo_pi/mc_pi_device_api.cpp
//============================================================== // Copyright © 2020 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= /* * * Content: * This file contains Monte Carlo Pi number evaluation benchmark for DPC++ * device interface of random number generators. * *******************************************************************************/ #include <iostream> #include <numeric> #include <vector> #include <sycl/sycl.hpp> #include "oneapi/mkl/rng/device.hpp" using namespace oneapi; // Value of Pi with many exact digits to compare with estimated value of Pi static const auto pi = 3.1415926535897932384626433832795; // Initialization value for random number generator static const auto seed = 7777; // Default Number of 2D points static const auto n_samples = 120000000; double estimate_pi(sycl::queue& q, size_t n_points) { double estimated_pi; // Estimated value of Pi size_t n_under_curve = 0; // Number of points fallen under the curve size_t count_per_thread = 32; constexpr size_t vec_size = 2; { sycl::buffer<size_t, 1> count_buf(&n_under_curve, 1); q.submit([&] (sycl::handler& h) { auto count_acc = count_buf.template get_access<sycl::access::mode::write>(h); h.parallel_for(sycl::range<1>(n_points / (count_per_thread * vec_size / 2)), [=](sycl::item<1> item) { size_t id_global = item.get_id(0); sycl::vec<float, vec_size> r; sycl::atomic_ref<size_t, sycl::memory_order::relaxed, sycl::memory_scope::device, sycl::access::address_space::global_space> atomic_counter { count_acc[0] }; size_t count = 0; // Create an object of basic random numer generator (engine) mkl::rng::device::philox4x32x10<vec_size> engine(seed, id_global * count_per_thread * vec_size); // Create an object of distribution (by default float, a = 0.0f, b = 1.0f) mkl::rng::device::uniform distr; for(int i = 0; i < count_per_thread; i++) { // Step 1. Generate 2D point r = mkl::rng::device::generate(distr, engine); // Step 2. Increment counter if point is under curve (x ^ 2 + y ^ 2 < 1.0f) if(sycl::length(r) <= 1.0f) { count += 1; } } atomic_counter.fetch_add(count); }); }); } estimated_pi = n_under_curve / ((double)n_points) * 4.0; return estimated_pi; } int main(int argc, char ** argv) { std::cout << std::endl; std::cout << "Monte Carlo pi Calculation Simulation" << std::endl; std::cout << "Device Api" << std::endl; std::cout << "-------------------------------------" << std::endl; double estimated_pi; size_t n_points = n_samples; if(argc >= 2) { n_points = atol(argv[1]); if(n_points == 0) { n_points = n_samples; } } std::cout << "Number of points = " << n_points << std::endl; // This exception handler with catch async exceptions auto exception_handler = [&](sycl::exception_list exceptions) { for(std::exception_ptr const& e : exceptions) { try { std::rethrow_exception(e); } catch (sycl::exception const& e) { std::cout << "Caught asynchronous SYCL exception:\n" << e.what() << std::endl; std::terminate(); } } }; try { // Queue constructor passed exception handler sycl::queue q(sycl::default_selector{}, exception_handler); // Launch Pi number calculation estimated_pi = estimate_pi(q, n_points); } catch (...) { // Some other exception detected std::cout << "Failure" << std::endl; std::terminate(); } // Printing results std::cout << "Estimated value of Pi = " << estimated_pi << std::endl; std::cout << "Exact value of Pi = " << pi << std::endl; std::cout << "Absolute error = " << fabs(pi-estimated_pi) << std::endl; std::cout << std::endl; return 0; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/monte_carlo_pi/mc_pi_usm.cpp
//============================================================== // Copyright © 2020 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= /* * * Content: * This file contains Monte Carlo Pi number evaluation benchmark for DPC++ * USM-based interface of random number generators. * *******************************************************************************/ #include <iostream> #include <numeric> #include <vector> #include <numeric> #include <sycl/sycl.hpp> #include "oneapi/mkl.hpp" using namespace oneapi; // Value of Pi with many exact digits to compare with estimated value of Pi static const auto pi = 3.1415926535897932384626433832795; // Initialization value for random number generator static const auto seed = 7777; // Default Number of 2D points static const auto n_samples = 120000000; double estimate_pi(sycl::queue& q, size_t n_points) { double estimated_pi; // Estimated value of Pi size_t n_under_curve = 0; // Number of points fallen under the curve // Step 1. Generate n_points * 2 random numbers // 1.1. Generator initialization // Create an object of basic random numer generator (engine) mkl::rng::philox4x32x10 engine(q, seed); // Create an object of distribution (by default float, a = 0.0f, b = 1.0f) mkl::rng::uniform distr; float* rng_ptr = sycl::malloc_device<float>(n_points * 2, q); // 1.2. Random number generation auto event = mkl::rng::generate(distr, engine, n_points * 2, rng_ptr); // Step 2. Count points under curve (x ^ 2 + y ^ 2 < 1.0f) size_t wg_size = std::min(q.get_device().get_info<sycl::info::device::max_work_group_size>(), n_points); size_t max_compute_units = q.get_device().get_info<sycl::info::device::max_compute_units>(); size_t wg_num = (n_points > wg_size * max_compute_units) ? max_compute_units : 1; size_t count_per_thread = n_points / (wg_size * wg_num); size_t* count_ptr = sycl::malloc_shared<size_t>(wg_num, q); // Make sure, that generation is finished event.wait_and_throw(); event = q.submit([&] (sycl::handler& h) { h.parallel_for(sycl::nd_range<1>(wg_size * wg_num, wg_size), [=](sycl::nd_item<1> item) { sycl::vec<float, 2> r; size_t count = 0; for(int i = 0; i < count_per_thread; i++) { r.load(i + item.get_global_linear_id() * count_per_thread, sycl::global_ptr<float>(rng_ptr)); if(sycl::length(r) <= 1.0f) { count += 1; } } count_ptr[item.get_group_linear_id()] = reduce_over_group(item.get_group(), count, std::plus<size_t>()); }); }); event.wait_and_throw(); n_under_curve = std::accumulate(count_ptr, count_ptr + wg_num, 0); // Step 3. Calculate approximated value of Pi estimated_pi = n_under_curve / ((double)n_points) * 4.0; sycl::free(rng_ptr, q); sycl::free(count_ptr, q); return estimated_pi; } int main(int argc, char ** argv) { std::cout << std::endl; std::cout << "Monte Carlo pi Calculation Simulation" << std::endl; std::cout << "Unified Shared Memory Api" << std::endl; std::cout << "-------------------------------------" << std::endl; double estimated_pi; size_t n_points = n_samples; if(argc >= 2) { n_points = atol(argv[1]); if(n_points == 0) { n_points = n_samples; } } std::cout << "Number of points = " << n_points << std::endl; // This exception handler with catch async exceptions auto exception_handler = [&](sycl::exception_list exceptions) { for(std::exception_ptr const& e : exceptions) { try { std::rethrow_exception(e); } catch (sycl::exception const& e) { std::cout << "Caught asynchronous SYCL exception:\n" << e.what() << std::endl; std::terminate(); } } }; try { // Queue constructor passed exception handler sycl::queue q(sycl::default_selector{}, exception_handler); // Launch Pi number calculation estimated_pi = estimate_pi(q, n_points); } catch (...) { // Some other exception detected std::cout << "Failure" << std::endl; std::terminate(); } // Printing results std::cout << "Estimated value of Pi = " << estimated_pi << std::endl; std::cout << "Exact value of Pi = " << pi << std::endl; std::cout << "Absolute error = " << fabs(pi-estimated_pi) << std::endl; std::cout << std::endl; return 0; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/computed_tomography/computed_tomography.cpp
//===================================================================== // Copyright © 2020 Intel Corporation // // SPDX-License-Identifier: MIT // ==================================================================== /* * Content: * Reconstruct the original image from the Computed Tomography (CT) * data using oneMKL DPC++ fast Fourier transform (FFT) functions. ************************************************************************ * Usage: * ====== * program.out p q input.bmp radon.bmp restored.bmp * Input: * p, q - parameters of Radon transform * input.bmp - must be a 24-bit uncompressed input bitmap * Output: * radon.bmp - p-by-(2q+1) result of Radon transform of input.bmp * restored.bmp - 2q-by-2q result of FFT-based reconstruction * * Steps: * ====== * - Acquire Radon transforms from the original image - perform * line integrals for the original image in 'p' directions onto * '2q+1' points for each direction to obtain a sinogram. * Reconstruction phase - * 1) Perform 'p' 1-D FFT's using oneMKL DFT DPC++ asynchronous USM API, * constructing full fourier representation of the object using 'p' * projections. * 2) Interpolate from radial grid(fourier representation from step2) * onto Cartesian grid. * 3) Perform one 2-D inverse FFT to obtain the reconstructed * image using oneMKL DFT DPCPP asynchronous USM API. */ #include <cmath> #include <complex> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sycl/sycl.hpp> #include "oneapi/mkl.hpp" #if !defined(M_PI) #define M_PI 3.14159265358979323846 #endif #if !defined(REAL_DATA) #define REAL_DATA double #endif typedef std::complex<REAL_DATA> complex; typedef oneapi::mkl::dft::descriptor<oneapi::mkl::dft::precision::DOUBLE, oneapi::mkl::dft::domain::REAL> descriptor_real; typedef oneapi::mkl::dft::descriptor<oneapi::mkl::dft::precision::DOUBLE, oneapi::mkl::dft::domain::COMPLEX> descriptor_complex; // A simple transparent matrix class, row-major layout template <typename T> struct matrix { sycl::queue q; T *data; int h, w, ldw; matrix(sycl::queue &main_queue) : q{main_queue}, data{NULL} {} matrix(const matrix &); matrix &operator=(const matrix &); void deallocate() { if (data) free(data, q.get_context()); } void allocate(int _h, int _w, int _ldw) { h = _h; w = _w; ldw = _ldw; // leading dimension for w deallocate(); data = (T *)malloc_shared(sizeof(T) * h * ldw, q.get_device(), q.get_context()); } ~matrix() { deallocate(); } }; typedef matrix<REAL_DATA> matrix_r; typedef matrix<complex> matrix_c; // Computational functions sycl::event step1_fft_1d(matrix_r &radon_image, descriptor_real &fft1d, sycl::queue &main_queue, const std::vector<sycl::event> &deps = {}); sycl::event step2_interpolation(matrix_r &result, matrix_r &radon_image, sycl::queue &main_queue, const std::vector<sycl::event> &deps = {}); sycl::event step3_ifft_2d(matrix_r &fhat, descriptor_complex &ifft2d, sycl::queue &main_queue, const std::vector<sycl::event> &deps = {}); // Support functions void bmp_read(matrix_r &image, std::string fname); void bmp_write(std::string fname, const matrix_r &image, bool isComplex); sycl::event acquire_radon(matrix_r &result, matrix_r &input, sycl::queue &main_queue); template <typename T> inline int is_odd(const T &n) { return n & 1; } template <typename T> void die(std::string err, T param); void die(std::string err); // Main function carrying out the steps mentioned above int main(int argc, char **argv) { int p = argc > 1 ? atoi(argv[1]) : 200; // # of projections in range 0..PI int q = argc > 2 ? atoi(argv[2]) : 100; // # of density points per projection is 2q+1 std::string original_bmpname = argc > 3 ? argv[3] : "input.bmp"; std::string radon_bmpname = argc > 4 ? argv[4] : "radon.bmp"; std::string restored_bmpname = argc > 5 ? argv[5] : "restored.bmp"; // Create execution queue. // This sample requires double precision, so look for a device that supports it. sycl::queue main_queue; try { main_queue = sycl::queue(sycl::aspect_selector({sycl::aspect::fp64})); } catch (sycl::exception &e) { std::cerr << "Could not find any device with double precision support. Exiting.\n"; return 0; } std::cout << "Reading original image from " << original_bmpname << std::endl; matrix_r original_image(main_queue); bmp_read(original_image, original_bmpname); std::cout << "Allocating radonImage for backprojection" << std::endl; matrix_r radon_image(main_queue); // space for p-by-(2q+2) reals, or for p-by-(q+1) complex numbers radon_image.allocate(p, 2 * q + 1, 2 * q + 2); if (!radon_image.data) die("cannot allocate memory for radonImage\n"); std::cout << "Performing backprojection" << std::endl; auto ev = acquire_radon(radon_image, original_image, main_queue); ev.wait(); // wait here for bmpWrite bmp_write(radon_bmpname, radon_image, false); std::cout << "Restoring original: step1 - fft_1d in-place" << std::endl; descriptor_real fft1d((radon_image.w) - 1); // 2*q auto step1 = step1_fft_1d(radon_image, fft1d, main_queue); std::cout << "Allocating array for radial->cartesian interpolation" << std::endl; matrix_r fhat(main_queue); fhat.allocate(2 * q, 2 * 2 * q, 2 * 2 * q); if (!fhat.data) die("cannot allocate memory for fhat\n"); std::cout << "Restoring original: step2 - interpolation" << std::endl; auto step2 = step2_interpolation(fhat, radon_image, main_queue, {step1}); // step2.wait(); //wait here for bmpWrite // bmpWrite( "check-after-interpolation.bmp", fhat , true); //For debugging purpose std::cout << "Restoring original: step3 - ifft_2d in-place" << std::endl; descriptor_complex ifft2d({fhat.h, (fhat.w) / 2}); // fhat.w/2 in complex'es auto step3 = step3_ifft_2d(fhat, ifft2d, main_queue, {step2}); std::cout << "Saving restored image to " << restored_bmpname << std::endl; step3.wait(); // Wait for the reconstructed image bmp_write(restored_bmpname, fhat, true); return 0; } // Step 1: batch of 1d r2c fft. // ghat[j, lambda] <-- scale * FFT_1D( g[j,l] ) sycl::event step1_fft_1d(matrix_r &radon, descriptor_real &fft1d, sycl::queue &main_queue, const std::vector<sycl::event> &deps) { std::int64_t p = radon.h; std::int64_t q2 = radon.w - 1; // w = 2*q + 1 std::int64_t ldw = radon.ldw; REAL_DATA scale = 1.0 / sqrt(0.0 + q2); // Make sure we can do in-place r2c if (is_odd(ldw)) die("c-domain needs even ldw at line %i\n", __LINE__); if (q2 / 2 + 1 > ldw / 2) die("no space for in-place r2c, line %i\n", __LINE__); // Configure descriptor fft1d.set_value(oneapi::mkl::dft::config_param::NUMBER_OF_TRANSFORMS, p); fft1d.set_value(oneapi::mkl::dft::config_param::FWD_DISTANCE, ldw); // in REAL_DATA's fft1d.set_value(oneapi::mkl::dft::config_param::BWD_DISTANCE, ldw / 2); // in complex'es fft1d.set_value(oneapi::mkl::dft::config_param::FORWARD_SCALE, scale); fft1d.commit(main_queue); auto fft1d_ev = oneapi::mkl::dft::compute_forward(fft1d, radon.data, deps); return fft1d_ev; } // Step 2: interpolation to Cartesian grid. // ifreq_dom[x, y] <-- interpolation( freq_dom[theta, ksi] ) sycl::event step2_interpolation(matrix_r &fhat, matrix_r &radon_image, sycl::queue &main_queue, const std::vector<sycl::event> &deps) { // radonImage is the result of r2c FFT // rt(pp,:) contains frequences 0...q complex *rt = (complex *)radon_image.data; complex *ft = (complex *)fhat.data; int q = (radon_image.w - 1) / 2; // w = 2q + 1 int ldq = radon_image.ldw / 2; int p = radon_image.h; int h = fhat.h; int w = fhat.w / 2; // fhat.w/2 in complex'es int ldw = fhat.ldw / 2; // fhat.ldw/2 in complex'es auto ev = main_queue.submit([&](sycl::handler &cgh) { cgh.depends_on(deps); auto interpolateKernel = [=](sycl::item<1> item) { const int i = item.get_id(0); for (int j = 0; j < w; ++j) { REAL_DATA yy = 2.0 * i / h - 1; // yy = [-1...1] REAL_DATA xx = 2.0 * j / w - 1; // xx = [-1...1] REAL_DATA r = sycl::sqrt(xx * xx + yy * yy); REAL_DATA phi = sycl::atan2(yy, xx); complex fhat_ij = complex(0.); if (r <= 1) { if (phi < 0) { r = -r; phi += M_PI; } int qq = sycl::floor(REAL_DATA(q + r * q + 0.5)) - q; // qq = [-q...q) if (qq >= q) qq = q - 1; int pp = sycl::floor(REAL_DATA(phi / M_PI * p + 0.5)); // pp = [0...p) if (pp >= p) pp = p - 1; if (qq >= 0) fhat_ij = rt[pp * ldq + qq]; else fhat_ij = std::conj(rt[pp * ldq - qq]); if (is_odd(qq)) fhat_ij = -fhat_ij; if (is_odd(i)) fhat_ij = -fhat_ij; if (is_odd(j)) fhat_ij = -fhat_ij; } ft[i * ldw + j] = fhat_ij; } }; cgh.parallel_for<class interpolateKernelClass>(sycl::range<1>(h), interpolateKernel); }); return ev; } // Step 3: inverse FFT // ifreq_dom[x, y] <-- IFFT_2D( ifreq_dom[x, y] ) sycl::event step3_ifft_2d(matrix_r &fhat, descriptor_complex &ifft2d, sycl::queue &main_queue, const std::vector<sycl::event> &deps) { // Configure descriptor std::int64_t strides[3] = {0, (fhat.ldw) / 2, 1}; // fhat.ldw/2, in complex'es ifft2d.set_value(oneapi::mkl::dft::config_param::INPUT_STRIDES, strides); ifft2d.commit(main_queue); sycl::event ifft2d_ev = oneapi::mkl::dft::compute_backward(ifft2d, fhat.data, deps); return ifft2d_ev; } // Simplified BMP structure. // See http://msdn.microsoft.com/en-us/library/dd183392(v=vs.85).aspx #pragma pack(push, 1) struct bmp_header { char bf_type[2]; unsigned int bf_size; unsigned int bf_reserved; unsigned int bf_off_bits; unsigned int bi_size; unsigned int bi_width; unsigned int bi_height; unsigned short bi_planes; unsigned short bi_bit_count; unsigned int bi_compression; unsigned int bi_size_image; unsigned int bi_x_pels_per_meter; unsigned int bi_y_pels_per_meter; unsigned int bi_clr_used; unsigned int bi_clr_important; }; #pragma pack(pop) // Read image from fname and convert it to gray-scale REAL. void bmp_read(matrix_r &image, std::string fname) { std::fstream fp; fp.open(fname, std::fstream::in | std::fstream::binary); if (fp.fail()) die("cannot open the file %s\n", fname); bmp_header header; fp.read((char *)(&header), sizeof(header)); if (header.bi_bit_count != 24) die("not a 24-bit image in %s\n", fname); if (header.bi_compression) die("%s is compressed bmp\n", fname); if (header.bi_height <= 0 || header.bi_width <= 0) die("image %s has zero size\n", fname); if (header.bi_height > 65536 || header.bi_width > 65536) die("image %s too large\n", fname); image.allocate(header.bi_height, header.bi_width, header.bi_width); if (!image.data) die("no memory to read %s\n", fname); fp.seekg(sizeof(header), std::ios_base::beg); REAL_DATA *image_data = (REAL_DATA *)image.data; for (int i = 0; i < image.h; ++i) { for (int j = 0; j < image.w; ++j) { struct { unsigned char b, g, r; } pixel; fp.read((char *)(&pixel), 3); REAL_DATA gray = (255 * 3.0 - pixel.r - pixel.g - pixel.b) / 255; image_data[i * image.ldw + j] = gray; } fp.seekg((4 - 3 * image.w % 4) % 4, std::ios_base::cur); } if (!fp) die("error reading %s\n", fname); fp.close(); } inline REAL_DATA to_real(const REAL_DATA &x) { return x; } inline REAL_DATA to_real(const complex &x) { return std::abs(x); } template <typename T> void bmp_write_templ(std::string fname, int h, int w, int ldw, T *data) { unsigned sizeof_line = (w * 3 + 3) / 4 * 4; unsigned sizeof_image = h * sizeof_line; bmp_header header = {{'B', 'M'}, unsigned(sizeof(header) + sizeof_image), 0, sizeof(header), sizeof(header) - offsetof(bmp_header, bi_size), unsigned(w), unsigned(h), 1, 24, 0, sizeof_image, 6000, 6000, 0, 0}; std::fstream fp; fp.open(fname, std::fstream::out | std::fstream::binary); if (fp.fail()) die("failed to save the image, cannot open file", fname); fp.write((char *)(&header), sizeof(header)); REAL_DATA minabs = 1e38, maxabs = 0; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) { REAL_DATA ijabs = to_real(data[i * ldw + j]); if (!(ijabs > minabs)) minabs = ijabs; if (!(ijabs < maxabs)) maxabs = ijabs; } for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { REAL_DATA ijabs = to_real(data[i * ldw + j]); REAL_DATA gray = 255 * (ijabs - maxabs) / (minabs - maxabs); struct { unsigned char b, g, r; } pixel; pixel.b = pixel.g = pixel.r = (unsigned char)(gray + 0.5); fp.write((char *)(&pixel), 3); } for (int j = 3 * w; j % 4; ++j) fp.put(0); } fp.close(); } void bmp_write(std::string fname, const matrix_r &image, bool isComplex) { if (isComplex) bmp_write_templ(fname, image.h, image.w / 2, image.ldw / 2, (complex *)image.data); else bmp_write_templ(fname, image.h, image.w, image.ldw, image.data); } sycl::event acquire_radon(matrix_r &result, matrix_r &input, sycl::queue &main_queue) { int h_r = result.h, w_r = result.w, ldw_r = result.ldw; int h_i = input.h, w_i = input.w, ldw_i = input.ldw; // Integrate image along line [(x,y),(cos theta, sin theta)] = R*s auto integrate_along_line = [=](REAL_DATA theta, REAL_DATA s, int h, int w, int ldw, REAL_DATA *data) { REAL_DATA R = 0.5 * sycl::sqrt(REAL_DATA(h * h + w * w)); REAL_DATA S = s * R, B = sycl::sqrt(1 - s * s) * R; REAL_DATA cs = sycl::cos(theta), sn = sycl::sin(theta); REAL_DATA dl = 1, dx = -dl * sn, dy = dl * cs; // integration step // unadjusted start of integration REAL_DATA x0 = 0.5 * w + S * cs + B * sn; REAL_DATA y0 = 0.5 * h + S * sn - B * cs; // unadjusted end of integration REAL_DATA x1 = 0.5 * w + S * cs - B * sn; REAL_DATA y1 = 0.5 * h + S * sn + B * cs; int N = 0; // number of sampling points on the interval do { // Adjust start-end of the integration interval if (x0 < 0) { if (x1 < 0) break; else { y0 -= (0 - x0) * cs / sn; x0 = 0; } } if (y0 < 0) { if (y1 < 0) break; else { x0 -= (0 - y0) * sn / cs; y0 = 0; } } if (x1 < 0) { if (x0 < 0) break; else { y1 -= (0 - x1) * cs / sn; x1 = 0; } } if (y1 < 0) { if (y0 < 0) break; else { x1 -= (0 - y1) * sn / cs; y1 = 0; } } if (x0 > w) { if (x1 > w) break; else { y0 -= (w - x0) * cs / sn; x0 = w; } } if (y0 > h) { if (y1 > h) break; else { x0 -= (h - y0) * sn / cs; y0 = h; } } if (x1 > w) { if (x0 > w) break; else { y1 -= (w - x1) * cs / sn; x1 = w; } } if (y1 > h) { if (y0 > h) break; else { x1 -= (h - y1) * sn / cs; y1 = h; } } // Compute number of steps N = int(sycl::fabs(dx) > sycl::fabs(dy) ? ((x1 - x0) / dx) : ((y1 - y0) / dy)); } while (0); // Integrate REAL_DATA sum = 0; for (int n = 0; n < N; ++n) { int i = sycl::floor(y0 + n * dy + 0.5 * dy); int j = sycl::floor(x0 + n * dx + 0.5 * dx); sum += data[i * ldw + j]; } sum *= dl; return sum; }; REAL_DATA *input_data = (REAL_DATA *)input.data; REAL_DATA *result_data = (REAL_DATA *)result.data; sycl::event ev = main_queue.submit([&](sycl::handler &cgh) { auto acquire_radon_kernel = [=](sycl::item<1> item) { const int i = item.get_id(0); REAL_DATA theta = i * M_PI / h_r; // theta=[0,...,M_PI) for (int j = 0; j < w_r; ++j) { REAL_DATA s = -1. + (2.0 * j + 1) / w_r; // s=(-1,...,1) REAL_DATA projection = integrate_along_line(theta, s, h_i, w_i, ldw_i, input_data); result_data[i * ldw_r + j] = projection; } }; cgh.parallel_for<class acquire_radon_class>(sycl::range<1>(h_r), acquire_radon_kernel); }); return ev; } template <typename T> void die(std::string err, T param) { std::cout << "Fatal error: " << err << " " << param << std::endl; fflush(0); exit(1); } void die(std::string err) { std::cout << "Fatal error: " << err << " " << std::endl; fflush(0); exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/student_t_test/t_test.cpp
//============================================================== // Copyright © 2021 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= /* * * Content: * This file contains Student's T-test DPC++ implementation with * buffer APIs. * *******************************************************************************/ #include <sycl/sycl.hpp> #include <cstdlib> #include <iostream> #include <vector> #include "oneapi/mkl.hpp" using fp_type = float; // Initialization value for random number generator static const auto seed = 7777; // Quantity of samples to check using Students' T-test static const auto n_samples = 1000000; // Expected mean value of random samples static const auto expected_mean = 0.0f; // Expected standard deviation of random samples static const auto expected_std_dev = 1.0f; // T-test threshold which corresponds to 5% significance level and infinite // degrees of freedom static const auto threshold = 1.95996f; // T-test function with expected mean // Returns: -1 if something went wrong, 1 - in case of NULL hypothesis should be // accepted, 0 - in case of NULL hypothesis should be rejected template <typename RealType> std::int32_t t_test(sycl::queue &q, sycl::buffer<RealType, 1> &r, std::int64_t n, RealType expected_mean) { std::int32_t res = -1; RealType sqrt_n_observations = sycl::sqrt(static_cast<RealType>(n)); // Create buffers to be passed inside oneMKL stats functions sycl::buffer<RealType, 1> mean_buf(sycl::range{1}); sycl::buffer<RealType, 1> variance_buf(sycl::range{1}); // Perform computations of mean and variance auto dataset = oneapi::mkl::stats::make_dataset<oneapi::mkl::stats::layout::row_major>( 1, n, r); oneapi::mkl::stats::mean(q, dataset, mean_buf); q.wait_and_throw(); oneapi::mkl::stats::central_moment(q, mean_buf, dataset, variance_buf); q.wait_and_throw(); // Create Host accessors and check the condition sycl::host_accessor mean_acc(mean_buf); sycl::host_accessor variance_acc(variance_buf); if ((sycl::abs(mean_acc[0] - expected_mean) * sqrt_n_observations / sycl::sqrt(variance_acc[0])) < static_cast<RealType>(threshold)) { res = 1; } else { res = 0; } return res; } // T-test function with two input arrays // Returns: -1 if something went wrong, 1 - in case of NULL hypothesis should be // accepted, 0 - in case of NULL hypothesis should be rejected template <typename RealType> std::int32_t t_test(sycl::queue &q, sycl::buffer<RealType, 1> &r1, std::int64_t n1, sycl::buffer<RealType, 1> &r2, std::int64_t n2) { std::int32_t res = -1; // Create buffers to be passed inside oneMKL stats functions sycl::buffer<RealType, 1> mean1_buf(sycl::range{1}); sycl::buffer<RealType, 1> variance1_buf(sycl::range{1}); sycl::buffer<RealType, 1> mean2_buf(sycl::range{1}); sycl::buffer<RealType, 1> variance2_buf(sycl::range{1}); // Perform computations of mean and variance auto dataset1 = oneapi::mkl::stats::make_dataset<oneapi::mkl::stats::layout::row_major>( 1, n1, r1); auto dataset2 = oneapi::mkl::stats::make_dataset<oneapi::mkl::stats::layout::row_major>( 1, n2, r2); oneapi::mkl::stats::mean(q, dataset1, mean1_buf); q.wait_and_throw(); oneapi::mkl::stats::central_moment(q, mean1_buf, dataset1, variance1_buf); oneapi::mkl::stats::mean(q, dataset2, mean2_buf); q.wait_and_throw(); oneapi::mkl::stats::central_moment(q, mean2_buf, dataset2, variance2_buf); q.wait_and_throw(); // Create Host accessors and check the condition sycl::host_accessor mean1_acc{mean1_buf}; sycl::host_accessor variance1_acc{variance1_buf}; sycl::host_accessor mean2_acc{mean2_buf}; sycl::host_accessor variance2_acc{variance2_buf}; bool almost_equal = (variance1_acc[0] < 2 * variance2_acc[0]) || (variance2_acc[0] < 2 * variance1_acc[0]); if (almost_equal) { if ((sycl::abs(mean1_acc[0] - mean2_acc[0]) / sycl::sqrt((static_cast<RealType>(1.0) / static_cast<RealType>(n1) + static_cast<RealType>(1.0) / static_cast<RealType>(n2)) * ((n1 - 1) * (n1 - 1) * variance1_acc[0] + (n2 - 1) * (n2 - 1) * variance2_acc[0]) / (n1 + n2 - 2))) < static_cast<RealType>(threshold)) { res = 1; } else { res = 0; } } else { if ((sycl::abs(mean1_acc[0] - mean2_acc[0]) / sycl::sqrt((variance1_acc[0] + variance2_acc[0]))) < static_cast<RealType>(threshold)) { res = 1; } else { res = 0; } } return res; } int main(int argc, char **argv) { std::cout << "\nStudent's T-test Simulation\n"; std::cout << "Buffer Api\n"; std::cout << "-------------------------------------\n"; size_t n_points = n_samples; fp_type mean = expected_mean; fp_type std_dev = expected_std_dev; if (argc >= 2) { n_points = std::atol(argv[1]); if (n_points == 0) { n_points = n_samples; } } if (argc >= 3) { mean = std::atof(argv[2]); if (std::isnan(mean) || std::isinf(mean)) { mean = expected_mean; } } if (argc >= 4) { std_dev = std::atof(argv[3]); if (std_dev <= static_cast<fp_type>(0.0f)) { std_dev = expected_std_dev; } } std::cout << "Number of random samples = " << n_points << " with mean = " << mean << ", std_dev = " << std_dev << "\n"; // This exception handler with catch async exceptions auto exception_handler = [](sycl::exception_list exceptions) { for (std::exception_ptr const &e : exceptions) { try { std::rethrow_exception(e); } catch (sycl::exception const &e) { std::cout << "Caught asynchronous SYCL exception during generation:\n" << e.what() << std::endl; } } }; std::int32_t res0, res1; try { // Queue constructor passed exception handler sycl::queue q(sycl::default_selector{}, exception_handler); // Prepare buffers for random output sycl::buffer<fp_type, 1> rng_buf0(n_points); sycl::buffer<fp_type, 1> rng_buf1(n_points); // Create engine object oneapi::mkl::rng::default_engine engine(q, seed); // Create distribution object oneapi::mkl::rng::gaussian<fp_type> distribution(mean, std_dev); // Perform generation oneapi::mkl::rng::generate(distribution, engine, n_points, rng_buf0); oneapi::mkl::rng::generate(distribution, engine, n_points, rng_buf1); q.wait_and_throw(); // Launch T-test with expected mean res0 = t_test(q, rng_buf0, n_points, mean); // Launch T-test with two input arrays res1 = t_test(q, rng_buf0, n_points, rng_buf1, n_points); } catch (...) { // Some other exception detected std::cout << "Failure\n"; std::terminate(); } // Printing results std::cout << "T-test result with expected mean: " << res0 << "\n"; std::cout << "T-test result with two input arrays: " << res1 << "\n\n"; return 0; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/student_t_test/t_test_usm.cpp
//============================================================== // Copyright © 2021 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= /* * * Content: * This file contains Student's T-test DPC++ implementation with * USM APIs. * *******************************************************************************/ #include <sycl/sycl.hpp> #include <cstdlib> #include <iostream> #include <vector> #include "oneapi/mkl.hpp" using fp_type = float; // Initialization value for random number generator static const auto seed = 7777; // Quantity of samples to check using Students' T-test static const auto n_samples = 1000000; // Expected mean value of random samples static const auto expected_mean = 0.0f; // Expected standard deviation of random samples static const auto expected_std_dev = 1.0f; // T-test threshold which corresponds to 5% significance level and infinite // degrees of freedom static const auto threshold = 1.95996f; // T-test function with expected mean // Returns: -1 if something went wrong, 1 - in case of NULL hypothesis should be // accepted, 0 - in case of NULL hypothesis should be rejected template <typename RealType> std::int32_t t_test(sycl::queue& q, RealType* r, std::int64_t n, RealType expected_mean) { std::int32_t res = -1; RealType sqrt_n_observations = sycl::sqrt(static_cast<RealType>(n)); // Allocate memory to be passed inside oneMKL stats functions RealType* mean = sycl::malloc_shared<RealType>(1, q); RealType* variance = sycl::malloc_shared<RealType>(1, q); // Perform computations of mean and variance auto dataset = oneapi::mkl::stats::make_dataset<oneapi::mkl::stats::layout::row_major>( 1, n, r); oneapi::mkl::stats::mean(q, dataset, mean); q.wait_and_throw(); oneapi::mkl::stats::central_moment(q, mean, dataset, variance); q.wait_and_throw(); // Check the condition if ((sycl::abs(mean[0] - expected_mean) * sqrt_n_observations / sycl::sqrt(variance[0])) < static_cast<RealType>(threshold)) { res = 1; } else { res = 0; } // Free allocated memory sycl::free(mean, q); sycl::free(variance, q); return res; } // T-test function with two input arrays // Returns: -1 if something went wrong, 1 - in case of NULL hypothesis should be // accepted, 0 - in case of NULL hypothesis should be rejected template <typename RealType> std::int32_t t_test(sycl::queue& q, RealType* r1, std::int64_t n1, RealType* r2, std::int64_t n2) { std::int32_t res = -1; // Allocate memory to be passed inside oneMKL stats functions RealType* mean1 = sycl::malloc_shared<RealType>(1, q); RealType* variance1 = sycl::malloc_shared<RealType>(1, q); RealType* mean2 = sycl::malloc_shared<RealType>(1, q); RealType* variance2 = sycl::malloc_shared<RealType>(1, q); // Perform computations of mean and variance auto dataset1 = oneapi::mkl::stats::make_dataset<oneapi::mkl::stats::layout::row_major>( 1, n1, r1); auto dataset2 = oneapi::mkl::stats::make_dataset<oneapi::mkl::stats::layout::row_major>( 1, n2, r2); oneapi::mkl::stats::mean(q, dataset1, mean1); q.wait_and_throw(); oneapi::mkl::stats::central_moment(q, mean1, dataset1, variance1); oneapi::mkl::stats::mean(q, dataset2, mean2); q.wait_and_throw(); oneapi::mkl::stats::central_moment(q, mean2, dataset2, variance2); q.wait_and_throw(); // Check the condition bool almost_equal = (variance1[0] < 2 * variance2[0]) || (variance2[0] < 2 * variance1[0]); if (almost_equal) { if ((sycl::abs(mean1[0] - mean2[0]) / sycl::sqrt((static_cast<RealType>(1.0) / static_cast<RealType>(n1) + static_cast<RealType>(1.0) / static_cast<RealType>(n2)) * ((n1 - 1) * (n1 - 1) * variance1[0] + (n2 - 1) * (n2 - 1) * variance2[0]) / (n1 + n2 - 2))) < static_cast<RealType>(threshold)) { res = 1; } else { res = 0; } } else { if ((sycl::abs(mean1[0] - mean2[0]) / sycl::sqrt((variance1[0] + variance2[0]))) < static_cast<RealType>(threshold)) { res = 1; } else { res = 0; } } // Free allocated memory sycl::free(mean1, q); sycl::free(variance1, q); sycl::free(mean2, q); sycl::free(variance2, q); return res; } int main(int argc, char** argv) { std::cout << "\nStudent's T-test Simulation\n"; std::cout << "Unified Shared Memory Api\n"; std::cout << "-------------------------------------\n"; size_t n_points = n_samples; fp_type mean = expected_mean; fp_type std_dev = expected_std_dev; if (argc >= 2) { n_points = std::atol(argv[1]); if (n_points == 0) { n_points = n_samples; } } if (argc >= 3) { mean = std::atof(argv[2]); if (std::isnan(mean) || std::isinf(mean)) { mean = expected_mean; } } if (argc >= 4) { std_dev = std::atof(argv[3]); if (std_dev <= static_cast<fp_type>(0.0f)) { std_dev = expected_std_dev; } } std::cout << "Number of random samples = " << n_points << " with mean = " << mean << ", std_dev = " << std_dev << "\n"; // This exception handler with catch async exceptions auto exception_handler = [](sycl::exception_list exceptions) { for (std::exception_ptr const& e : exceptions) { try { std::rethrow_exception(e); } catch (sycl::exception const& e) { std::cout << "Caught asynchronous SYCL exception during generation:\n" << e.what() << std::endl; } } }; std::int32_t res0, res1; try { // Queue constructor passed exception handler sycl::queue q(sycl::default_selector{}, exception_handler); // Allocate memory for random output fp_type* rng_arr0 = sycl::malloc_shared<fp_type>(n_points, q); fp_type* rng_arr1 = sycl::malloc_shared<fp_type>(n_points, q); // Create engine object oneapi::mkl::rng::default_engine engine(q, seed); // Create distribution object oneapi::mkl::rng::gaussian<fp_type> distribution(mean, std_dev); // Perform generation oneapi::mkl::rng::generate(distribution, engine, n_points, rng_arr0); oneapi::mkl::rng::generate(distribution, engine, n_points, rng_arr1); q.wait_and_throw(); // Launch T-test with expected mean res0 = t_test(q, rng_arr0, n_points, mean); // Launch T-test with two input arrays res1 = t_test(q, rng_arr0, n_points, rng_arr1, n_points); // Free allocated memory sycl::free(rng_arr0, q); sycl::free(rng_arr1, q); } catch (...) { // Some other exception detected std::cout << "Failure\n"; std::terminate(); } // Printing results std::cout << "T-test result with expected mean: " << res0 << "\n"; std::cout << "T-test result with two input arrays: " << res1 << "\n\n"; return 0; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/fourier_correlation/fcorr_1d_usm.cpp
//============================================================== // Copyright © 2020 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= // // Content: // This code implements the 1D Fourier correlation algorithm // using SYCL, oneMKL, and unified shared memory (USM). // // ============================================================= #include <mkl.h> #include <sycl/sycl.hpp> #include <iostream> #include <string> #include <oneapi/mkl/dfti.hpp> #include <oneapi/mkl/rng.hpp> #include <oneapi/mkl/vm.hpp> template <typename T, typename I> using maxloc = sycl::ext::oneapi::maximum<std::pair<T, I>>; constexpr size_t L = 1; int main(int argc, char** argv) { unsigned int N = (argc == 1) ? 32 : std::stoi(argv[1]); if ((N % 2) != 0) N++; if (N < 32) N = 32; // Initialize SYCL queue sycl::queue Q(sycl::default_selector_v); std::cout << "Running on: " << Q.get_device().get_info<sycl::info::device::name>() << "\n"; // Initialize signal and correlation arrays auto sig1 = sycl::malloc_shared<float>(N + 2, Q); auto sig2 = sycl::malloc_shared<float>(N + 2, Q); auto corr = sycl::malloc_shared<float>(N + 2, Q); // Initialize input signals with artificial data std::uint32_t seed = (unsigned)time(NULL); // Get RNG seed value oneapi::mkl::rng::mcg31m1 engine(Q, seed); // Initialize RNG engine // Set RNG distribution oneapi::mkl::rng::uniform<float, oneapi::mkl::rng::uniform_method::standard> rng_distribution(-0.00005, 0.00005); auto evt1 = oneapi::mkl::rng::generate(rng_distribution, engine, N, sig1); // Noise auto evt2 = oneapi::mkl::rng::generate(rng_distribution, engine, N, sig2); evt1.wait(); evt2.wait(); Q.single_task<>([=]() { sig1[N - N / 4 - 1] = 1.0; sig1[N - N / 4] = 1.0; sig1[N - N / 4 + 1] = 1.0; // Signal sig2[N / 4 - 1] = 1.0; sig2[N / 4] = 1.0; sig2[N / 4 + 1] = 1.0; }) .wait(); // Initialize FFT descriptor oneapi::mkl::dft::descriptor<oneapi::mkl::dft::precision::SINGLE, oneapi::mkl::dft::domain::REAL> transform_plan(N); transform_plan.commit(Q); // Perform forward transforms on real arrays evt1 = oneapi::mkl::dft::compute_forward(transform_plan, sig1); evt2 = oneapi::mkl::dft::compute_forward(transform_plan, sig2); // Compute: DFT(sig1) * CONJG(DFT(sig2)) oneapi::mkl::vm::mulbyconj( Q, N / 2, reinterpret_cast<std::complex<float>*>(sig1), reinterpret_cast<std::complex<float>*>(sig2), reinterpret_cast<std::complex<float>*>(corr), {evt1, evt2}) .wait(); // Perform backward transform on complex correlation array oneapi::mkl::dft::compute_backward(transform_plan, corr).wait(); // Find the shift that gives maximum correlation value using parallel maxloc // reduction std::pair<float, int>* max_res = sycl::malloc_shared<std::pair<float, int>>(1, Q); std::pair<float, int> max_identity = {std::numeric_limits<float>::min(), std::numeric_limits<int>::min()}; *max_res = max_identity; auto red_max = reduction(max_res, max_identity, maxloc<float, int>()); Q.parallel_for(sycl::nd_range<1>{N, L}, red_max, [=](sycl::nd_item<1> item, auto& max_res) { int i = item.get_global_id(0); std::pair<float, int> partial = {corr[i], i}; max_res.combine(partial); }) .wait(); float max_corr = max_res->first; int shift = max_res->second; shift = (shift > N / 2) ? shift - N : shift; // Treat the signals as circularly // shifted versions of each other. std::cout << "Shift the second signal " << shift << " elements relative to the first signal to get a maximum, " "normalized correlation score of " << max_corr / N << ".\n"; // Cleanup sycl::free(sig1, Q); sycl::free(sig2, Q); sycl::free(corr, Q); sycl::free(max_res, Q); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/fourier_correlation/fcorr_1d_buffers.cpp
//============================================================== // Copyright © 2020 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= // // Content: // This code implements the 1D Fourier correlation algorithm // using SYCL, oneMKL, oneDPL, and explicit buffering. // // ============================================================= #include <oneapi/dpl/algorithm> #include <oneapi/dpl/execution> #include <oneapi/dpl/iterator> #include <sycl/sycl.hpp> #include <oneapi/mkl/dfti.hpp> #include <oneapi/mkl/rng.hpp> #include <oneapi/mkl/vm.hpp> #include <mkl.h> #include <iostream> #include <string> int main(int argc, char **argv) { unsigned int N = (argc == 1) ? 32 : std::stoi(argv[1]); if ((N % 2) != 0) N++; if (N < 32) N = 32; // Initialize SYCL queue sycl::queue Q(sycl::default_selector_v); std::cout << "Running on: " << Q.get_device().get_info<sycl::info::device::name>() << "\n"; // Create buffers for signal data. This will only be used on the device. sycl::buffer<float> sig1_buf{N + 2}; sycl::buffer<float> sig2_buf{N + 2}; sycl::buffer<float> corr_buf{N + 2}; // Initialize the input signals with artificial data std::uint32_t seed = (unsigned)time(NULL); // Get RNG seed value oneapi::mkl::rng::mcg31m1 engine(Q, seed); // Initialize RNG engine // Set RNG distribution oneapi::mkl::rng::uniform<float, oneapi::mkl::rng::uniform_method::standard> rng_distribution(-0.00005, 0.00005); oneapi::mkl::rng::generate(rng_distribution, engine, N, sig1_buf); // Noise oneapi::mkl::rng::generate(rng_distribution, engine, N, sig2_buf); Q.submit([&](sycl::handler &h) { sycl::accessor sig1_acc{sig1_buf, h, sycl::write_only}; sycl::accessor sig2_acc{sig2_buf, h, sycl::write_only}; h.single_task<>([=]() { sig1_acc[N - N / 4 - 1] = 1.0; sig1_acc[N - N / 4] = 1.0; sig1_acc[N - N / 4 + 1] = 1.0; // Signal sig2_acc[N / 4 - 1] = 1.0; sig2_acc[N / 4] = 1.0; sig2_acc[N / 4 + 1] = 1.0; }); }); // End signal initialization // Initialize FFT descriptor oneapi::mkl::dft::descriptor<oneapi::mkl::dft::precision::SINGLE, oneapi::mkl::dft::domain::REAL> transform_plan(N); transform_plan.commit(Q); // Perform forward transforms on real arrays oneapi::mkl::dft::compute_forward(transform_plan, sig1_buf); oneapi::mkl::dft::compute_forward(transform_plan, sig2_buf); // Compute: DFT(sig1) * CONJG(DFT(sig2)) auto sig1_buf_cplx = sig1_buf.template reinterpret<std::complex<float>, 1>((N + 2) / 2); auto sig2_buf_cplx = sig2_buf.template reinterpret<std::complex<float>, 1>((N + 2) / 2); auto corr_buf_cplx = corr_buf.template reinterpret<std::complex<float>, 1>((N + 2) / 2); oneapi::mkl::vm::mulbyconj(Q, N / 2, sig1_buf_cplx, sig2_buf_cplx, corr_buf_cplx); // Perform backward transform on complex correlation array oneapi::mkl::dft::compute_backward(transform_plan, corr_buf); // Find the shift that gives maximum correlation value auto policy = oneapi::dpl::execution::make_device_policy(Q); auto maxloc = oneapi::dpl::max_element(policy, oneapi::dpl::begin(corr_buf), oneapi::dpl::end(corr_buf)); int shift = oneapi::dpl::distance(oneapi::dpl::begin(corr_buf), maxloc); float max_corr = corr_buf.get_host_access()[shift]; shift = (shift > N / 2) ? shift - N : shift; // Treat the signals as circularly // shifted versions of each other. std::cout << "Shift the second signal " << shift << " elements relative to the first signal to get a maximum, " "normalized correlation score of " << max_corr / N << ".\n"; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/fourier_correlation/fcorr_2d_usm.cpp
//============================================================== // Copyright © 2020 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= // // Content: // This code implements the 2D Fourier correlation algorithm // using SYCL, oneMKL, oneDPL, and unified shared memory // (USM). // // ============================================================= #include <oneapi/dpl/algorithm> #include <oneapi/dpl/execution> #include <oneapi/dpl/iterator> #include <sycl/sycl.hpp> #include <oneapi/mkl/dfti.hpp> #include <oneapi/mkl/vm.hpp> #include <mkl.h> #include <iostream> int main(int argc, char **argv) { // Initialize SYCL queue sycl::queue Q(sycl::default_selector_v); std::cout << "Running on: " << Q.get_device().get_info<sycl::info::device::name>() << std::endl; // Allocate 2D image and correlation arrays unsigned int n_rows = 8, n_cols = 8; auto img1 = sycl::malloc_shared<float>(n_rows * n_cols * 2 + 2, Q); auto img2 = sycl::malloc_shared<float>(n_rows * n_cols * 2 + 2, Q); auto corr = sycl::malloc_shared<float>(n_rows * n_cols * 2 + 2, Q); // Initialize input images with artificial data. Do initialization on the device. // Generalized strides for row-major addressing int r_stride = 1, c_stride = (n_cols / 2 + 1) * 2, c_stride_h = (n_cols / 2 + 1); Q.parallel_for<>(sycl::range<2>{n_rows, n_cols}, [=](sycl::id<2> idx) { unsigned int r = idx[0]; unsigned int c = idx[1]; img1[r * c_stride + c * r_stride] = 0.0; img2[r * c_stride + c * r_stride] = 0.0; corr[r * c_stride + c * r_stride] = 0.0; }).wait(); Q.single_task<>([=]() { // Set a box of elements in the lower right of the first image img1[4 * c_stride + 5 * r_stride] = 1.0; img1[4 * c_stride + 6 * r_stride] = 1.0; img1[5 * c_stride + 5 * r_stride] = 1.0; img1[5 * c_stride + 6 * r_stride] = 1.0; // Set a box of elements in the upper left of the second image img2[1 * c_stride + 1 * r_stride] = 1.0; img2[1 * c_stride + 2 * r_stride] = 1.0; img2[2 * c_stride + 1 * r_stride] = 1.0; img2[2 * c_stride + 2 * r_stride] = 1.0; }).wait(); std::cout << std::endl << "First image:" << std::endl; for (unsigned int r = 0; r < n_rows; r++) { for (unsigned int c = 0; c < n_cols; c++) { std::cout << img1[r * c_stride + c * r_stride] << " "; } std::cout << std::endl; } std::cout << std::endl << "Second image:" << std::endl; for (unsigned int r = 0; r < n_rows; r++) { for (unsigned int c = 0; c < n_cols; c++) { std::cout << img2[r * c_stride + c * r_stride] << " "; } std::cout << std::endl; } // Initialize FFT descriptor oneapi::mkl::dft::descriptor<oneapi::mkl::dft::precision::SINGLE, oneapi::mkl::dft::domain::REAL> forward_plan({n_rows, n_cols}); // Data layout in real domain std::int64_t real_layout[4] = {0, c_stride, 1}; forward_plan.set_value(oneapi::mkl::dft::config_param::INPUT_STRIDES, real_layout); // Data layout in conjugate-even domain std::int64_t complex_layout[4] = {0, c_stride_h, 1}; forward_plan.set_value(oneapi::mkl::dft::config_param::OUTPUT_STRIDES, complex_layout); // Perform forward transforms on real arrays forward_plan.commit(Q); auto evt1 = oneapi::mkl::dft::compute_forward(forward_plan, img1); auto evt2 = oneapi::mkl::dft::compute_forward(forward_plan, img2); // Compute: DFT(img1) * CONJG(DFT(img2)) oneapi::mkl::vm::mulbyconj(Q, n_rows * c_stride_h, reinterpret_cast<std::complex<float>*>(img1), reinterpret_cast<std::complex<float>*>(img2), reinterpret_cast<std::complex<float>*>(corr), {evt1, evt2}) .wait(); // Perform backward transform on complex correlation array oneapi::mkl::dft::descriptor<oneapi::mkl::dft::precision::SINGLE, oneapi::mkl::dft::domain::REAL> backward_plan({n_rows, n_cols}); // Data layout in conjugate-even domain backward_plan.set_value(oneapi::mkl::dft::config_param::INPUT_STRIDES, complex_layout); // Data layout in real domain backward_plan.set_value(oneapi::mkl::dft::config_param::OUTPUT_STRIDES, real_layout); backward_plan.commit(Q); auto bwd = oneapi::mkl::dft::compute_backward(backward_plan, corr); bwd.wait(); std::cout << std::endl << "Normalized Fourier correlation result:" << std::endl; for (unsigned int r = 0; r < n_rows; r++) { for (unsigned int c = 0; c < n_cols; c++) { std::cout << corr[r * c_stride + c * r_stride] / (n_rows * n_cols) << " "; } std::cout << std::endl; } // Find the translation vector that gives maximum correlation value auto policy = oneapi::dpl::execution::make_device_policy(Q); auto maxloc = oneapi::dpl::max_element(policy, corr, corr + (n_rows * n_cols * 2 + 2)); policy.queue().wait(); auto s = oneapi::dpl::distance(corr, maxloc); float max_corr = corr[s]; int x_shift = s % (n_cols + 2); int y_shift = s / (n_rows + 2); std::cout << std::endl << "Shift the second image (x, y) = (" << x_shift << ", " << y_shift << ") elements relative to the first image to get a maximum," << std::endl << "normalized correlation score of " << max_corr / (n_rows * n_cols) << ". Treat the images as circularly shifted versions of each other." << std::endl; // Cleanup sycl::free(img1, Q); sycl::free(img2, Q); sycl::free(corr, Q); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/monte_carlo_european_opt/src/montecarlo.hpp
//============================================================== // Copyright © 2022 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= #pragma once #define _USE_MATH_DEFINES #include <math.h> #include <iostream> #include <vector> #include <sycl/sycl.hpp> #ifndef DATA_TYPE #define DATA_TYPE double #endif #ifndef ITEMS_PER_WORK_ITEM #define ITEMS_PER_WORK_ITEM 4 #endif #ifndef VEC_SIZE #define VEC_SIZE 8 #endif using DataType = DATA_TYPE; //Should be > 1 constexpr int num_options = 384000; //Should be > 16 constexpr int path_length = 262144; //Test iterations constexpr int num_iterations = 5; constexpr DataType risk_free = 0.06f; constexpr DataType volatility = 0.10f; constexpr DataType RLog2E = -risk_free * M_LOG2E; constexpr DataType MuLog2E = M_LOG2E * (risk_free - 0.5 * volatility * volatility); constexpr DataType VLog2E = M_LOG2E * volatility; template<typename MonteCarlo_vector> void check(const MonteCarlo_vector& h_CallResult, const MonteCarlo_vector& h_CallConfidence, const MonteCarlo_vector& h_StockPrice, const MonteCarlo_vector& h_OptionStrike, const MonteCarlo_vector& h_OptionYears) { std::vector<DataType> h_CallResultRef(num_options); auto BlackScholesRefImpl = []( DataType Sf, //Stock price DataType Xf, //Option strike DataType Tf //Option years ) { // BSM Formula: https://www.nobelprize.org/prizes/economic-sciences/1997/press-release/ // N(d)=1/2 + 1/2*ERF(d/sqrt(2)), https://software.intel.com/en-us/node/531898 DataType S = Sf, L = Xf, t = Tf, r = risk_free, sigma = volatility; DataType N_d1 = 1. / 2. + 1. / 2. * std::erf(((std::log(S / L) + (r + 0.5 * sigma * sigma) * t) / (sigma * std::sqrt(t))) / std::sqrt(2.)); DataType N_d2 = 1. / 2. + 1. / 2. * std::erf(((std::log(S / L) + (r - 0.5 * sigma * sigma) * t) / (sigma * std::sqrt(t))) / std::sqrt(2.)); return S * N_d1 - L * std::exp(-r * t) * N_d2; }; for (int opt = 0; opt < num_options; opt++) { h_CallResultRef[opt] = BlackScholesRefImpl(h_StockPrice[opt], h_OptionStrike[opt], h_OptionYears[opt]); } std::cout << "Running quality test..." << std::endl; DataType sum_delta = 0.0, sum_ref = 0.0, max_delta = 0.0, sum_reserve = 0.0; for (int opt = 0; opt < num_options; opt++) { DataType ref = h_CallResultRef[opt]; DataType delta = std::fabs(h_CallResultRef[opt] - h_CallResult[opt]); if (delta > max_delta) { max_delta = delta; } sum_delta += delta; sum_ref += std::fabs(ref); if (delta > 1e-6) { sum_reserve += h_CallConfidence[opt] / delta; } max_delta = std::max(delta, max_delta); } sum_reserve /= static_cast<double>(num_options); DataType L1_norm = sum_delta / sum_ref; std::cout << "L1_Norm = "<< L1_norm << std::endl; std::cout << "Average RESERVE = "<< sum_reserve << std::endl; std::cout << "Max Error = "<< max_delta << std::endl; std::cout << (sum_reserve > 1.0f ? "TEST PASSED!" : "TEST FAILED!") << std::endl; }
hpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/monte_carlo_european_opt/src/montecarlo_main.cpp
//============================================================== // Copyright © 2022 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= #include <cmath> #include <limits> #include <iostream> #include <sycl/sycl.hpp> #include <oneapi/mkl.hpp> #include <oneapi/mkl/rng/device.hpp> #include "montecarlo.hpp" #include "timer.hpp" template<typename Type, int> class k_MonteCarlo; // can be useful for profiling int main(int argc, char** argv) { try { std::cout << "MonteCarlo European Option Pricing in " << (std::is_same_v<DataType, double> ? "Double" : "Single") << " precision using " << #if USE_PHILOX "PHILOX4x32x10" << #elif USE_MRG "MRG32k3a" << #else "MCG59" << #endif " generator." << std::endl; std::cout << "Pricing " << num_options << " Options with Path Length = " << path_length << ", sycl::vec size = " << VEC_SIZE << ", Options Per Work Item = " << ITEMS_PER_WORK_ITEM << " and Iterations = " << num_iterations << std::endl; sycl::queue my_queue; sycl::usm_allocator<DataType, sycl::usm::alloc::shared> alloc(my_queue); std::vector<DataType, decltype(alloc)> h_call_result(num_options, alloc); std::vector<DataType, decltype(alloc)> h_call_confidence(num_options, alloc); std::vector<DataType, decltype(alloc)> h_stock_price(num_options, alloc); std::vector<DataType, decltype(alloc)> h_option_strike(num_options, alloc); std::vector<DataType, decltype(alloc)> h_option_years(num_options, alloc); DataType* h_call_result_ptr = h_call_result.data(); DataType* h_call_confidence_ptr = h_call_confidence.data(); DataType* h_stock_price_ptr = h_stock_price.data(); DataType* h_option_strike_ptr = h_option_strike.data(); DataType* h_option_years_ptr = h_option_years.data(); // calculate the number of blocks constexpr DataType fpath_lengthN = static_cast<DataType>(path_length); constexpr DataType stddev_denom = 1.0 / (fpath_lengthN * (fpath_lengthN - 1.0)); DataType confidence_denom = 1.96 / std::sqrt(fpath_lengthN); constexpr int rand_seed = 777; constexpr std::size_t local_size = 256; const std::size_t global_size = (num_options * local_size) / ITEMS_PER_WORK_ITEM; // It requires num_options be divisible by ITEMS_PER_WORK_ITEM const int block_n = path_length / (local_size * VEC_SIZE); timer tt{}; double total_time = 0.0; namespace mkl_rng = oneapi::mkl::rng; mkl_rng::mcg59 engine( #if !INIT_ON_HOST my_queue, #else sycl::queue{sycl::cpu_selector_v}, #endif rand_seed); // random number generator object auto rng_event_1 = mkl_rng::generate(mkl_rng::uniform<DataType>(5.0, 50.0), engine, num_options, h_stock_price_ptr); auto rng_event_2 = mkl_rng::generate(mkl_rng::uniform<DataType>(10.0, 25.0), engine, num_options, h_option_strike_ptr); auto rng_event_3 = mkl_rng::generate(mkl_rng::uniform<DataType>(1.0, 5.0), engine, num_options, h_option_years_ptr); std::size_t n_states = global_size; using EngineType = #if USE_PHILOX mkl_rng::device::philox4x32x10<VEC_SIZE>; #elif USE_MRG mkl_rng::device::mrg32k3a<VEC_SIZE>; #else mkl_rng::device::mcg59<VEC_SIZE>; #endif // initialization needs only on first step auto deleter = [my_queue](auto* ptr) {sycl::free(ptr, my_queue);}; auto rng_states_uptr = std::unique_ptr<EngineType, decltype(deleter)>(sycl::malloc_device<EngineType>(n_states, my_queue), deleter); auto* rng_states = rng_states_uptr.get(); my_queue.parallel_for<class k_initialize_state>( sycl::range<1>(n_states), std::vector<sycl::event>{rng_event_1, rng_event_2, rng_event_3}, [=](sycl::item<1> idx) { auto id = idx[0]; #if USE_MRG constexpr std::uint32_t seed = 12345u; rng_states[id] = EngineType({ seed, seed, seed, seed, seed, seed }, { 0, (4096 * id) }); #else rng_states[id] = EngineType(rand_seed, id * ITEMS_PER_WORK_ITEM * VEC_SIZE * block_n); #endif }) .wait_and_throw(); // main cycle for (int i = 0; i < num_iterations; i++) { tt.start(); my_queue.parallel_for<k_MonteCarlo<DataType, ITEMS_PER_WORK_ITEM>>( sycl::nd_range<1>({global_size}, {local_size}), [=](sycl::nd_item<1> item) { auto local_state = rng_states[item.get_global_id()]; for(std::size_t i = 0; i < ITEMS_PER_WORK_ITEM; ++i) { const std::size_t i_options = item.get_group_linear_id() * ITEMS_PER_WORK_ITEM + i; DataType option_years = h_option_years_ptr[i_options]; const DataType VBySqrtT = VLog2E * sycl::sqrt(option_years); const DataType MuByT = MuLog2E * option_years; const DataType Y = h_stock_price_ptr[i_options]; const DataType Z = h_option_strike_ptr[i_options]; DataType v0 = 0, v1 = 0; mkl_rng::device::gaussian<DataType> distr(MuByT, VBySqrtT); for (int block = 0; block < block_n; ++block) { auto rng_val_vec = mkl_rng::device::generate(distr, local_state); auto rng_val = Y * sycl::exp2(rng_val_vec) - Z; for (int lane = 0; lane < VEC_SIZE; ++lane) { DataType rng_element = sycl::max(rng_val[lane], DataType{}); // reduce within the work-item v0 += rng_element; v1 += rng_element * rng_element; } } // reduce within the work-group v0 = sycl::reduce_over_group(item.get_group(), v0, std::plus<>()); v1 = sycl::reduce_over_group(item.get_group(), v1, std::plus<>()); const DataType exprt = sycl::exp2(RLog2E * option_years); DataType call_result = exprt * v0 * (DataType(1) / fpath_lengthN); const DataType std_dev = sycl::sqrt((fpath_lengthN * v1 - v0 * v0) * stddev_denom); DataType call_confidence = static_cast<DataType>(exprt * std_dev * confidence_denom); if(item.get_local_id() == 0) { h_call_result_ptr[i_options] = call_result; h_call_confidence_ptr[i_options] = call_confidence; } } }).wait_and_throw(); tt.stop(); if(i != 0) total_time += tt.duration(); } std::cout << "Completed in " << total_time << " seconds. Options per second = " << static_cast<double>(num_options * (num_iterations - 1)) / total_time << std::endl; // check results check(h_call_result, h_call_confidence, h_stock_price, h_option_strike, h_option_years); } catch (sycl::exception e) { std::cout << e.what(); exit(1); } return 0; }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/monte_carlo_european_opt/src/timer.hpp
//============================================================== // Copyright © 2022 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= #pragma once #include <chrono> class timer { public: timer() { start(); } void start() { t1_ = std::chrono::steady_clock::now(); } void stop() { t2_ = std::chrono::steady_clock::now(); } auto duration() { return std::chrono::duration<double>(t2_ - t1_).count(); } private: std::chrono::steady_clock::time_point t1_, t2_; };
hpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/matrix_mul_mkl/matrix_mul_mkl.cpp
//============================================================== // Copyright © 2023 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= // // Contents: // A simple matrix multiplication benchmark, using the oneAPI Math Kernel // Library (oneMKL). // #include <sycl/sycl.hpp> #include <oneapi/mkl.hpp> #include <chrono> #include <cstdlib> #include <iomanip> #include <iostream> #include <string> #include "utilities.hpp" using namespace sycl; template <typename T> void test(queue &Q, int M, int N, int K) { std::cout << "\nBenchmarking (" << M << " x " << K << ") x (" << K << " x " << N << ") matrix multiplication, " << type_string<T>() << std::endl;; std::cout << " -> Initializing data...\n"; /* Allocate A/B/C matrices */ int lda = nice_ld<T>(M); int ldb = nice_ld<T>(K); int ldc = nice_ld<T>(M); auto A = malloc_device<T>(lda * K, Q); auto B = malloc_device<T>(ldb * N, Q); auto C = malloc_device<T>(ldc * N, Q); /* Fill A/B with random data */ constexpr int rd_size = 1048576; auto random_data = malloc_host<T>(rd_size, Q); generate_random_data(rd_size, random_data); replicate_data(Q, A, lda * K, random_data, rd_size); replicate_data(Q, B, ldb * N, random_data, rd_size); /* Measure time for a given number of GEMM calls */ auto time_gemms = [=, &Q](int runs) -> double { using namespace oneapi::mkl; using namespace std::chrono; auto start = steady_clock::now(); for (int i = 0; i < runs; i++) blas::gemm(Q, transpose::N, transpose::N, M, N, K, 1, A, lda, B, ldb, 0, C, ldc); Q.wait_and_throw(); auto end = steady_clock::now(); return duration<double>(end - start).count(); }; /* Do a warmup call to initialize MKL and ensure kernels are JIT'ed if needed */ std::cout << " -> Warmup...\n"; (void) time_gemms(1); /* Time one GEMM call, and estimate how many calls will be required to keep the * GPU busy for 1s. */ auto tare = time_gemms(1); int ncalls = std::max(4, std::min(1000, int(1. / tare))); /* Time that many GEMMs, subtracting the first call time to remove host overhead. * This gives a better idea of device performance. */ std::cout << " -> Timing...\n"; auto time = time_gemms(ncalls + 1) - tare; auto avg = time / ncalls; /* Calculate and display performance */ auto op_count = double(M) * double(N) * double(K) * 2; auto flops = op_count / avg; flops *= 1e-9; char unit = 'G'; if (flops >= 1000.) { flops *= 1e-3; unit = 'T'; } if (flops >= 1000.) { flops *= 1e-3; unit = 'P'; } std::cout << "\nAverage performance: " << flops << unit << 'F' << std::endl; /* Free data */ free(A, Q); free(B, Q); free(C, Q); free(random_data, Q); } void usage(const char *pname) { std::cerr << "Usage:\n" << " " << pname << " [type] N benchmark (NxN) x (NxN) square matrix multiplication (default: N = 4096)\n" << " " << pname << " [type] M N K benchmark (MxK) x (KxN) square matrix multiplication\n" << "\n" << "The optional [type] selects the data type:\n" << " double [default]\n" << " single\n" << " half\n" << "\n" << "This benchmark uses the default DPC++ device, which can be controlled using\n" << " the ONEAPI_DEVICE_SELECTOR environment variable\n"; std::exit(1); } int main(int argc, char **argv) { auto pname = argv[0]; int M = 4096, N = 4096, K = 4096; std::string type = "double"; if (argc <= 1) usage(pname); if (argc > 1 && std::isalpha(argv[1][0])) { type = argv[1]; argc--; argv++; } if (argc > 1) M = N = K = std::atoi(argv[1]); if (argc > 3) { N = std::atoi(argv[2]); K = std::atoi(argv[3]); } if (M <= 0 || N <= 0 || K <= 0) usage(pname); queue Q; std::cout << "oneMKL DPC++ GEMM benchmark\n" << "---------------------------\n" << "Device: " << Q.get_device().get_info<info::device::name>() << std::endl << "Core/EU count: " << Q.get_device().get_info<info::device::max_compute_units>() << std::endl << "Maximum clock frequency: " << Q.get_device().get_info<info::device::max_clock_frequency>() << " MHz" << std::endl; if (type == "double") test<double>(Q, M, N, K); else if (type == "single" || type == "float") test<float>(Q, M, N, K); else if (type == "half") test<half>(Q, M, N, K); else usage(pname); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/matrix_mul_mkl/utilities.hpp
//============================================================== // Copyright © 2023 Intel Corporation // // SPDX-License-Identifier: MIT // ============================================================= #include <sycl/sycl.hpp> #include <algorithm> template <typename T> const char *type_string() { return "unknown type"; } template <> const char *type_string<sycl::half>() { return "half precision"; } template <> const char *type_string<float>() { return "single precision"; } template <> const char *type_string<double>() { return "double precision"; } /* Choose inter-column padding for optimal performance */ template <typename T> int nice_ld(int x) { x = std::max(x, 1); x *= sizeof(T); x = (x + 511) & ~511; x += 256; x /= sizeof(T); return x; } /* Random number generation helpers */ template <typename T> void generate_random_data(size_t elems, T *v) { #pragma omp parallel for for (size_t i = 0; i < elems; i++) v[i] = double(std::rand()) / RAND_MAX; } template <typename T> void replicate_data(sycl::queue &Q, T *dst, size_t dst_elems, const T *src, size_t src_elems) { while (dst_elems > 0) { auto copy_elems = std::min(dst_elems, src_elems); Q.copy(src, dst, copy_elems); dst += copy_elems; dst_elems -= copy_elems; } Q.wait(); }
hpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Common/cublas_utils.h
/* * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of NVIDIA CORPORATION nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cmath> #include <functional> #include <iostream> #include <random> #include <stdexcept> #include <string> #include <dpct/lib_common_utils.hpp> #include <complex> // CUDA API error checking /* DPCT1001:1: The statement could not be removed. */ /* DPCT1000:2: Error handling if-stmt was detected but could not be rewritten. */ #define CUDA_CHECK(err) \ do { \ int err_ = (err); \ if (err_ != 0) { \ std::printf("CUDA error %d at %s:%d\n", err_, __FILE__, __LINE__); \ throw std::runtime_error("CUDA error"); \ } \ } while (0) // cublas API error checking #define CUBLAS_CHECK(err) \ do { \ int err_ = (err); \ if (err_ != 0) { \ std::printf("cublas error %d at %s:%d\n", err_, __FILE__, \ __LINE__); \ throw std::runtime_error("cublas error"); \ } \ } while (0) // memory alignment #define ALIGN_TO(A, B) (((A + B - 1) / B) * B) // device memory pitch alignment static const size_t device_alignment = 32; // type traits template <typename T> struct traits; template <> struct traits<float> { // scalar type typedef float T; typedef T S; static constexpr T zero = 0.f; static constexpr dpct::library_data_t cuda_data_type = dpct::library_data_t::real_float; inline static S abs(T val) { return fabs(val); } template <typename RNG> inline static T rand(RNG &gen) { return (S)gen(); } inline static T add(T a, T b) { return a + b; } inline static T mul(T v, double f) { return v * f; } }; template <> struct traits<double> { // scalar type typedef double T; typedef T S; static constexpr T zero = 0.; static constexpr dpct::library_data_t cuda_data_type = dpct::library_data_t::real_double; inline static S abs(T val) { return fabs(val); } template <typename RNG> inline static T rand(RNG &gen) { return (S)gen(); } inline static T add(T a, T b) { return a + b; } inline static T mul(T v, double f) { return v * f; } }; template <> struct traits<sycl::float2> { // scalar type typedef float S; typedef sycl::float2 T; static constexpr T zero = {0.f, 0.f}; static constexpr dpct::library_data_t cuda_data_type = dpct::library_data_t::complex_float; inline static S abs(T val) { return dpct::cabs<float>(val); } template <typename RNG> inline static T rand(RNG &gen) { return sycl::float2((S)gen(), (S)gen()); } inline static T add(T a, T b) { return a + b; } inline static T add(T a, S b) { return a + sycl::float2(b, 0.f); } inline static T mul(T v, double f) { return sycl::float2(v.x() * f, v.y() * f); } }; template <> struct traits<sycl::double2> { // scalar type typedef double S; typedef sycl::double2 T; static constexpr T zero = {0., 0.}; static constexpr dpct::library_data_t cuda_data_type = dpct::library_data_t::complex_double; inline static S abs(T val) { return dpct::cabs<double>(val); } template <typename RNG> inline static T rand(RNG &gen) { return sycl::double2((S)gen(), (S)gen()); } inline static T add(T a, T b) { return a + b; } inline static T add(T a, S b) { return a + sycl::double2(b, 0.); } inline static T mul(T v, double f) { return sycl::double2(v.x() * f, v.y() * f); } }; template <typename T> void print_matrix(const int &m, const int &n, const T *A, const int &lda); template <> void print_matrix(const int &m, const int &n, const float *A, const int &lda) { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { std::printf("%0.2f ", A[j * lda + i]); } std::printf("\n"); } } template <> void print_matrix(const int &m, const int &n, const double *A, const int &lda) { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { std::printf("%0.2f ", A[j * lda + i]); } std::printf("\n"); } } template <> void print_matrix(const int &m, const int &n, const sycl::float2 *A, const int &lda) { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { std::printf("%0.2f + %0.2fj ", A[j * lda + i].x(), A[j * lda + i].y()); } std::printf("\n"); } } template <> void print_matrix(const int &m, const int &n, const sycl::double2 *A, const int &lda) { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { std::printf("%0.2f + %0.2fj ", A[j * lda + i].x(), A[j * lda + i].y()); } std::printf("\n"); } } template <typename T> void print_vector(const int &m, const T *A); template <> void print_vector(const int &m, const float *A) { for (int i = 0; i < m; i++) { std::printf("%0.2f ", A[i]); } std::printf("\n"); } template <> void print_vector(const int &m, const double *A) { for (int i = 0; i < m; i++) { std::printf("%0.2f ", A[i]); } std::printf("\n"); } template <> void print_vector(const int &m, const sycl::float2 *A) { for (int i = 0; i < m; i++) { std::printf("%0.2f + %0.2fj ", A[i].x(), A[i].y()); } std::printf("\n"); } template <> void print_vector(const int &m, const sycl::double2 *A) { for (int i = 0; i < m; i++) { std::printf("%0.2f + %0.2fj ", A[i].x(), A[i].y()); } std::printf("\n"); } template <typename T> void generate_random_matrix(int m, int n, T **A, int *lda) { std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<typename traits<T>::S> dis(-1.0, 1.0); auto rand_gen = std::bind(dis, gen); *lda = n; size_t matrix_mem_size = static_cast<size_t>(*lda * m * sizeof(T)); // suppress gcc 7 size warning if (matrix_mem_size <= PTRDIFF_MAX) *A = (T *)malloc(matrix_mem_size); else throw std::runtime_error("Memory allocation size is too large"); if (*A == NULL) throw std::runtime_error("Unable to allocate host matrix"); // random matrix and accumulate row sums for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { T *A_row = (*A) + *lda * i; A_row[j] = traits<T>::rand(rand_gen); } } } // Makes matrix A of size mxn and leading dimension lda diagonal dominant template <typename T> void make_diag_dominant_matrix(int m, int n, T *A, int lda) { for (int i = 0; i < std::min(m, n); ++i) { T *A_row = A + lda * i; auto row_sum = traits<typename traits<T>::S>::zero; for (int j = 0; j < n; ++j) { row_sum += traits<T>::abs(A_row[j]); } A_row[i] = traits<T>::add(A_row[i], row_sum); } } // Returns cudaDataType value as defined in library_types.h for the string // containing type name dpct::library_data_t get_cuda_library_type(std::string type_string) { if (type_string.compare("CUDA_R_16F") == 0) return dpct::library_data_t::real_half; else if (type_string.compare("CUDA_C_16F") == 0) return dpct::library_data_t::complex_half; else if (type_string.compare("CUDA_R_32F") == 0) return dpct::library_data_t::real_float; else if (type_string.compare("CUDA_C_32F") == 0) return dpct::library_data_t::complex_float; else if (type_string.compare("CUDA_R_64F") == 0) return dpct::library_data_t::real_double; else if (type_string.compare("CUDA_C_64F") == 0) return dpct::library_data_t::complex_double; else if (type_string.compare("CUDA_R_8I") == 0) return dpct::library_data_t::real_int8; else if (type_string.compare("CUDA_C_8I") == 0) return dpct::library_data_t::complex_int8; else if (type_string.compare("CUDA_R_8U") == 0) return dpct::library_data_t::real_uint8; else if (type_string.compare("CUDA_C_8U") == 0) return dpct::library_data_t::complex_uint8; else if (type_string.compare("CUDA_R_32I") == 0) return dpct::library_data_t::real_int32; else if (type_string.compare("CUDA_C_32I") == 0) return dpct::library_data_t::complex_int32; else if (type_string.compare("CUDA_R_32U") == 0) return dpct::library_data_t::real_uint32; else if (type_string.compare("CUDA_C_32U") == 0) return dpct::library_data_t::complex_uint32; else throw std::runtime_error("Unknown CUDA datatype"); }
h
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_syr2_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | * y = | 7.0 8.0 | */ std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const std::vector<data_type> y = {7.0, 8.0}; const data_type alpha = 1.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:109: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:110: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); CUDA_CHECK( (stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()), 0)); /* step 3: compute */ /* DPCT1003:111: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::syr2( *cublasH, uplo, n, alpha, d_x, incx, d_y, incy, d_A, lda), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * A = | 71.0 85.0 | * | 3.0 100.0 | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:112: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_hpr2_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | * y = | 1.1 + 2.2j | 3.3 + 4.4j | */ std::vector<data_type> AP = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; const std::vector<data_type> y = {{1.1, 2.2}, {3.3, 4.4}}; const data_type alpha = {1.0, 1.0}; const int incx = 1; const int incy = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:78: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:79: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_AP = (data_type *)sycl::malloc_device( sizeof(data_type) * AP.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); CUDA_CHECK( (stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()), 0)); /* step 3: compute */ /* DPCT1003:80: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::hpr2( *cublasH, uplo, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_x, incx, (std::complex<double> *)d_y, incy, (std::complex<double> *)d_AP), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(AP.data(), d_AP, sizeof(data_type) * AP.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * AP = | 48.40 + 0.00j | 133.20 + 0.00j | * | 82.92 + 26.04j | 4.70 + 4.80j | */ printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_AP, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:81: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_hpr_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ std::vector<data_type> AP = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; const double alpha = 1.0; const int incx = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:82: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:83: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_AP = (data_type *)sycl::malloc_device( sizeof(data_type) * AP.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:84: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::hpr( *cublasH, uplo, n, alpha, (std::complex<double> *)d_x, incx, (std::complex<double> *)d_AP), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(AP.data(), d_AP, sizeof(data_type) * AP.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * AP = | 65.55 + 0.00j | 126.15 + 0.00j | * | 92.81 + 6.02j | 4.70 + 4.80j | */ printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_AP, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:85: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_trmv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:139: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:140: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:141: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::trmv( *cublasH, uplo, transa, diag, n, d_A, lda, d_x, incx), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * x = | 17.00 24.00 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:142: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_spr_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ std::vector<data_type> AP = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const data_type alpha = 1.0; const int incx = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:101: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:102: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_AP = (data_type *)sycl::malloc_device( sizeof(data_type) * AP.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:103: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::spr(*cublasH, uplo, n, alpha, d_x, incx, d_AP), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(AP.data(), d_AP, sizeof(data_type) * AP.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * AP = | 26.0 39.0 | * | 33.0 4.0 | */ printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_AP, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:104: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_spmv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> AP = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:93: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:94: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_AP = (data_type *)sycl::malloc_device( sizeof(data_type) * AP.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ CUBLAS_CHECK( (/* DPCT1003:95: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::spmv(*cublasH, uplo, n, alpha, d_AP, d_x, incx, beta, d_y, incy), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * y = | 23.00 33.00 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_AP, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:96: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_symv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:105: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:106: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ CUBLAS_CHECK( (/* DPCT1003:107: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::symv(*cublasH, uplo, n, alpha, d_A, lda, d_x, incx, beta, d_y, incy), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * y = | 23.00 29.00 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:108: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_tpmv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> AP = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:128: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:129: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:130: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:131: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_AP = (data_type *)sycl::malloc_device( sizeof(data_type) * AP.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:132: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::tpmv( *cublasH, uplo, transa, diag, n, d_AP, d_x, incx), 0)); /* step 4: copy data to host */ /* DPCT1003:133: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * x = | 23.00 12.00 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_AP, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:134: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_hemv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ const std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; std::vector<data_type> y(m); const data_type alpha = {1.0, 1.0}; const data_type beta = {0.0, 0.0}; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:49: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:50: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:51: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::hemv( *cublasH, uplo, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_A, lda, (std::complex<double> *)d_x, incx, std::complex<double>(beta.x(), beta.y()), (std::complex<double> *)d_y, incy), 0)); /* step 4: copy data to host */ /* DPCT1003:52: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * y = | -41.42 + 45.90j 19.42 + 102.42j | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ /* DPCT1003:53: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:54: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:55: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_ger_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | * y = | 7.0 8.0 | */ std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const std::vector<data_type> y = {7.0, 8.0}; const data_type alpha = 2.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:33: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:34: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* DPCT1003:35: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()), 0)); /* step 3: compute */ /* DPCT1003:36: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::ger( *cublasH, m, n, alpha, d_x, incx, d_y, incy, d_A, lda), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); /* DPCT1003:37: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * A = | 71.0 82.0 | * | 87.0 100.0 | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:38: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:39: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:40: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_spr2_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | * y = | 7.0 8.0 | */ std::vector<data_type> AP = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const std::vector<data_type> y = {7.0, 8.0}; const data_type alpha = 1.0; const int incx = 1; const int incy = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:97: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:98: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_AP = (data_type *)sycl::malloc_device( sizeof(data_type) * AP.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); CUDA_CHECK( (stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()), 0)); /* step 3: compute */ /* DPCT1003:99: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::ger(*cublasH, uplo, n, alpha, d_x, incx, d_y, incy, d_AP, lda), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(AP.data(), d_AP, sizeof(data_type) * AP.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * AP = | 36.0 43.0 | * | 3.0 4.0 | */ printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_AP, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:100: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_gbmv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; const int kl = 0; const int ku = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:0: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:3: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:4: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:5: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:6: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); /* DPCT1003:7: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); /* DPCT1003:8: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); /* DPCT1003:9: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:10: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ CUBLAS_CHECK((/* DPCT1003:11: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::gbmv( *cublasH, transa, m, n, kl, ku, alpha, d_A, lda, d_x, incx, beta, d_y, incy), 0)); /* step 4: copy data to host */ /* DPCT1003:12: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()), 0)); /* DPCT1003:13: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * y = | 27.0 24.0 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ /* DPCT1003:14: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:15: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:16: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:17: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:18: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:19: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_syr_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const data_type alpha = 1.0; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:113: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:114: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:115: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::syr(*cublasH, uplo, n, alpha, d_x, incx, d_A, lda), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * A = | 26.0 33.0 | * | 3.0 40.0 | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:116: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_trsv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:143: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:144: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:145: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::trsv( *cublasH, uplo, transa, diag, n, d_A, lda, d_x, incx), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * x = | 2.00 1.50 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:146: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_her2_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | * y = | 1.1 + 2.2j | 3.3 + 4.4j | */ std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; const std::vector<data_type> y = {{1.1, 2.2}, {3.3, 4.4}}; const data_type alpha = {1.0, 1.0}; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:56: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1025:57: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:58: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* DPCT1003:59: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()), 0)); /* step 3: compute */ /* DPCT1003:60: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::her2( *cublasH, uplo, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_x, incx, (std::complex<double> *)d_y, incy, (std::complex<double> *)d_A, lda), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); /* DPCT1003:61: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * A = | 48.40 + 0.00j | 81.72 + 24.84j | * | 3.50 + 3.60j | 135.60 + 0.00j | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:62: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:63: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_hbmv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 1; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ const std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; std::vector<data_type> y(m); const data_type alpha = {1.0, 1.0}; const data_type beta = {0.0, 0.0}; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:41: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:42: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:43: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:44: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); /* DPCT1003:45: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:46: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:47: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::hbmv( *cublasH, uplo, n, k, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_A, lda, (std::complex<double> *)d_x, incx, std::complex<double>(beta.x(), beta.y()), (std::complex<double> *)d_y, incy), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * y = | -44.06 + 73.02j 19.42 + 102.42j | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:48: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_hpmv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ const std::vector<data_type> AP = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; std::vector<data_type> y(m); const data_type alpha = {1.0, 1.0}; const data_type beta = {0.0, 0.0}; const int incx = 1; const int incy = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:74: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:75: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_AP = (data_type *)sycl::malloc_device( sizeof(data_type) * AP.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:76: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::hpmv( *cublasH, uplo, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_AP, (std::complex<double> *)d_x, incx, std::complex<double>(beta.x(), beta.y()), (std::complex<double> *)d_y, incy), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * y = | -61.58 + 63.42j 34.30 + 79.62j | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_AP, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:77: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_sbmv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 1; const int lda = m; /* * A = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:86: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:87: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ CUBLAS_CHECK( (/* DPCT1003:88: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::sbmv(*cublasH, uplo, n, k, alpha, d_A, lda, d_x, incx, beta, d_y, incy), 0)); /* step 4: copy data to host */ /* DPCT1003:89: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()), 0)); /* DPCT1003:90: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * y = | 33.00 39.00 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:91: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:92: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_her_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; const double alpha = 1.0; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:64: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:65: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:66: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:67: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); /* DPCT1003:68: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:69: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::her( *cublasH, uplo, n, alpha, (std::complex<double> *)d_x, incx, (std::complex<double> *)d_A, lda), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); /* DPCT1003:70: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * A = | 65.55 + 0.00j | 91.61 + 4.82j | * | 3.50 + 3.60j | 128.55 + 0.00j | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ /* DPCT1003:71: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:72: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:73: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_tbmv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 1; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:117: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:118: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:119: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:120: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:121: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::tbmv( *cublasH, uplo, transa, diag, n, k, d_A, lda, d_x, incx), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * x = | 27.00 24.00 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:122: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:123: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_tbsv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 1; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:124: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:125: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:126: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::tbsv( *cublasH, uplo, transa, diag, n, k, d_A, lda, d_x, incx), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * x = | 0.67 1.50 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:127: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_tpsv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> AP = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:135: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:136: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_AP = (data_type *)sycl::malloc_device( sizeof(data_type) * AP.size(), q_ct1), 0)); CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ /* DPCT1003:137: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::tpsv( *cublasH, uplo, transa, diag, n, d_AP, d_x, incx), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * x = | -4.00 3.00 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_AP, q_ct1), 0)); CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); /* DPCT1003:138: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-2/cublas_gemv_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:20: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:21: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:22: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:23: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:24: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); /* DPCT1003:25: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_x = (data_type *)sycl::malloc_device( sizeof(data_type) * x.size(), q_ct1), 0)); CUDA_CHECK((d_y = (data_type *)sycl::malloc_device( sizeof(data_type) * y.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()), 0)); /* step 3: compute */ CUBLAS_CHECK((/* DPCT1003:26: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::gemv(*cublasH, transa, m, n, alpha, d_A, lda, d_x, incx, beta, d_y, incy), 0)); /* step 4: copy data to host */ /* DPCT1003:27: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()), 0)); /* DPCT1003:28: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * y = | 17.00 39.00 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ /* DPCT1003:29: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:30: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_x, q_ct1), 0)); CUDA_CHECK((sycl::free(d_y, q_ct1), 0)); /* DPCT1003:31: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:32: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_asum_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const int incx = 1; data_type result = 0.0; data_type *d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:18: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:19: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* step 3: compute */ /* DPCT1034:20: Migrated API does not return error code. 0 is returned in the lambda. You may need to rewrite this code. */ CUBLAS_CHECK([&]() { double *res_temp_ptr_ct5 = &result; if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { res_temp_ptr_ct5 = sycl::malloc_shared<double>(1, dpct::get_default_queue()); } oneapi::mkl::blas::column_major::asum(*cublasH, A.size(), d_A, incx, res_temp_ptr_ct5); if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); result = *res_temp_ptr_ct5; sycl::free(res_temp_ptr_ct5, dpct::get_default_queue()); } return 0; }()); CUDA_CHECK((stream->wait(), 0)); /* * result = 10.00 */ printf("result\n"); std::printf("%0.2f\n", result); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:21: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_dot_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; const int incx = 1; const int incy = 1; data_type result = 0.0; data_type *d_A = nullptr; data_type *d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:59: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:60: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1034:61: Migrated API does not return error code. 0 is returned in the lambda. You may need to rewrite this code. */ CUBLAS_CHECK([&]() { double *res_temp_ptr_ct7 = &result; if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { res_temp_ptr_ct7 = sycl::malloc_shared<double>(1, dpct::get_default_queue()); } oneapi::mkl::blas::column_major::dot(*cublasH, A.size(), d_A, incx, d_B, incy, res_temp_ptr_ct7); if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); result = *res_temp_ptr_ct7; sycl::free(res_temp_ptr_ct7, dpct::get_default_queue()); } return 0; }()); CUDA_CHECK((stream->wait(), 0)); /* * result = 70.00 */ printf("Result\n"); printf("%0.2f\n", result); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:62: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_scal_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const data_type alpha = 2.2; const int incx = 1; data_type *d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:103: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:104: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:105: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:106: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); /* DPCT1003:107: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* step 3: compute */ /* DPCT1003:108: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::scal(*cublasH, A.size(), alpha, d_A, incx), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * A = | 2.2 4.4 6.6 8.8 | */ printf("A (scaled)\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:109: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:110: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_amin_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const int incx = 1; int result = 0.0; data_type *d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:14: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:15: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* step 3: compute */ /* DPCT1034:16: Migrated API does not return error code. 0 is returned in the lambda. You may need to rewrite this code. */ CUBLAS_CHECK([&]() { int64_t *res_temp_ptr_ct3 = sycl::malloc_shared<int64_t>(1, dpct::get_default_queue()); oneapi::mkl::blas::column_major::iamin(*cublasH, A.size(), d_A, incx, res_temp_ptr_ct3) .wait(); int res_temp_host_ct4 = (int)*res_temp_ptr_ct3; dpct::dpct_memcpy(&result, &res_temp_host_ct4, sizeof(int)); sycl::free(res_temp_ptr_ct3, dpct::get_default_queue()); return 0; }()); CUDA_CHECK((stream->wait(), 0)); /* * result = 1 */ printf("result\n"); std::printf("%d\n", result); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:17: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_amax_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const int incx = 1; int result = 0.0; data_type *d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:0: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:3: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:4: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:5: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:6: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); /* DPCT1003:7: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* step 3: compute */ /* DPCT1034:8: Migrated API does not return error code. 0 is returned in the lambda. You may need to rewrite this code. */ CUBLAS_CHECK([&]() { int64_t *res_temp_ptr_ct1 = sycl::malloc_shared<int64_t>(1, dpct::get_default_queue()); oneapi::mkl::blas::column_major::iamax(*cublasH, A.size(), d_A, incx, res_temp_ptr_ct1) .wait(); int res_temp_host_ct2 = (int)*res_temp_ptr_ct1; dpct::dpct_memcpy(&result, &res_temp_host_ct2, sizeof(int)); sycl::free(res_temp_ptr_ct1, dpct::get_default_queue()); return 0; }()); /* DPCT1003:9: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * result = 4 */ printf("result\n"); std::printf("%d\n", result); printf("=====\n"); /* free resources */ /* DPCT1003:10: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:11: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:12: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:13: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_rot_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; const data_type c = 2.1; const data_type s = 1.2; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:69: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:70: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:71: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::rot(*cublasH, A.size(), d_A, incx, d_B, incy, c, s), 0)); /* step 4: copy data to host */ /* DPCT1003:72: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * A = | 8.1 11.4 14.7 18.0 | * B = | 9.3 10.2 11.1 12.0 | */ printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ /* DPCT1003:73: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:74: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:75: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:76: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:77: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_nrm2_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const int incx = 1; data_type result = 0.0; data_type *d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:63: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:64: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* step 3: compute */ /* DPCT1034:65: Migrated API does not return error code. 0 is returned in the lambda. You may need to rewrite this code. */ CUBLAS_CHECK([&]() { double *res_temp_ptr_ct8 = &result; if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { res_temp_ptr_ct8 = sycl::malloc_shared<double>(1, dpct::get_default_queue()); } oneapi::mkl::blas::column_major::nrm2(*cublasH, A.size(), d_A, incx, res_temp_ptr_ct8); if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); result = *res_temp_ptr_ct8; sycl::free(res_temp_ptr_ct8, dpct::get_default_queue()); } return 0; }()); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * Result = 5.48 */ printf("Result\n"); printf("%0.2f\n", result); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:66: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:67: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:68: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_axpy_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; const data_type alpha = 2.1; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:22: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:23: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:24: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:25: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:26: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); /* DPCT1003:27: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:28: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:29: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::axpy( *cublasH, A.size(), alpha, d_A, incx, d_B, incy), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()), 0)); /* DPCT1003:30: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * B = | 7.10 10.20 13.30 16.40 | */ printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ /* DPCT1003:31: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:32: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:33: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:34: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:35: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_rotmg_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = 1.0 * B = 5.0 * X = 2.1 * Y = 1.2 */ data_type A = 1.0; data_type B = 5.0; data_type X = 2.1; data_type Y = 1.2; std::vector<data_type> param = {1.0, 5.0, 6.0, 7.0, 8.0}; // flag = param[0] data_type *d_A = nullptr; data_type *d_B = nullptr; printf("A\n"); std::printf("%0.2f\n", A); printf("=====\n"); printf("B\n"); std::printf("%0.2f\n", B); printf("=====\n"); printf("X\n"); std::printf("%0.2f\n", X); printf("=====\n"); printf("Y\n"); std::printf("%0.2f\n", Y); printf("=====\n"); printf("param\n"); print_vector(param.size(), param.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:97: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:98: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:99: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:100: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 3: compute */ /* DPCT1034:101: Migrated API does not return error code. 0 is returned in the lambda. You may need to rewrite this code. */ CUBLAS_CHECK([&]() { double *d1_ct13 = &A; double *d2_ct14 = &B; double *x1_ct15 = &X; double *param_ct16 = param.data(); if (sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::shared) { d1_ct13 = sycl::malloc_shared<double>(8, dpct::get_default_queue()); d2_ct14 = d1_ct13 + 1; x1_ct15 = d1_ct13 + 2; param_ct16 = d1_ct13 + 3; *d1_ct13 = A; *d2_ct14 = B; *x1_ct15 = X; } oneapi::mkl::blas::column_major::rotmg(*cublasH, d1_ct13, d2_ct14, x1_ct15, Y, param_ct16); if (sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); A = *d1_ct13; B = *d2_ct14; X = *x1_ct15; dpct::get_default_queue() .memcpy(param.data(), param_ct16, sizeof(double) * 5) .wait(); sycl::free(d1_ct13, dpct::get_default_queue()); } return 0; }()); CUDA_CHECK((stream->wait(), 0)); /* * A = 3.10 * B = 0.62 * X = 1.94 */ printf("A\n"); std::printf("%0.2f\n", A); printf("=====\n"); printf("B\n"); std::printf("%0.2f\n", B); printf("=====\n"); printf("X\n"); std::printf("%0.2f\n", X); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:102: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_rotg_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = 2.10 * B = 1.20 */ data_type A = 2.1; data_type B = 1.2; data_type c = 2.1; data_type s = 1.2; printf("A\n"); std::printf("%0.2f\n", A); printf("=====\n"); printf("B\n"); std::printf("%0.2f\n", B); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:78: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:79: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:80: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:81: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 3: compute */ /* DPCT1034:82: Migrated API does not return error code. 0 is returned in the lambda. You may need to rewrite this code. */ CUBLAS_CHECK([&]() { double *a_ct9 = &A; double *b_ct10 = &B; double *c_ct11 = &c; double *s_ct12 = &s; if (sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::shared) { a_ct9 = sycl::malloc_shared<double>(4, dpct::get_default_queue()); b_ct10 = a_ct9 + 1; c_ct11 = a_ct9 + 2; s_ct12 = a_ct9 + 3; *a_ct9 = A; *b_ct10 = B; *c_ct11 = c; *s_ct12 = s; } oneapi::mkl::blas::column_major::rotg(*cublasH, a_ct9, b_ct10, c_ct11, s_ct12); if (sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); A = *a_ct9; B = *b_ct10; c = *c_ct11; s = *s_ct12; sycl::free(a_ct9, dpct::get_default_queue()); } return 0; }()); /* DPCT1003:83: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * A = 2.42 * B = 0.50 */ printf("A\n"); std::printf("%0.2f\n", A); printf("=====\n"); printf("B\n"); std::printf("%0.2f\n", B); printf("=====\n"); /* free resources */ /* DPCT1003:84: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_swap_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:111: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:112: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:113: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::swap(*cublasH, A.size(), d_A, incx, d_B, incy), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * A = | 5.0 6.0 7.0 8.0 | * B = | 1.0 2.0 3.0 4.0 | */ printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:114: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_dotc_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | 3.5 + 3.6j | 4.7 + 4.8j | * B = | 5.1 + 5.2j | 6.3 + 6.4j | 7.5 + 7.6j | 8.7 + 8.8j | */ const std::vector<data_type> A = {{1.1, 1.2}, {2.3, 2.4}, {3.5, 3.6}, {4.7, 4.8}}; const std::vector<data_type> B = {{5.1, 5.2}, {6.3, 6.4}, {7.5, 7.6}, {8.7, 8.8}}; const int incx = 1; const int incy = 1; data_type result = {0.0, 0.0}; data_type *d_A = nullptr; data_type *d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:49: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:50: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:51: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:52: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:53: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1034:54: Migrated API does not return error code. 0 is returned in the lambda. You may need to rewrite this code. */ CUBLAS_CHECK([&]() { sycl::double2 *res_temp_ptr_ct6 = &result; if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { res_temp_ptr_ct6 = sycl::malloc_shared<sycl::double2>(1, dpct::get_default_queue()); } oneapi::mkl::blas::column_major::dotc( *cublasH, A.size(), (std::complex<double> *)d_A, incx, (std::complex<double> *)d_B, incy, (std::complex<double> *)res_temp_ptr_ct6); if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); result = *res_temp_ptr_ct6; sycl::free(res_temp_ptr_ct6, dpct::get_default_queue()); } return 0; }()); CUDA_CHECK((stream->wait(), 0)); /* * result = 178.44+-1.60j */ printf("Result\n"); printf("%0.2f+%0.2fj\n", result.x(), result.y()); printf("=====\n"); /* free resources */ /* DPCT1003:55: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:56: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:57: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:58: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_rotm_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; std::vector<data_type> param = {1.0, 5.0, 6.0, 7.0, 8.0}; // flag = param[0] const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); printf("param\n"); print_vector(param.size(), param.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:85: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1025:86: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:87: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); /* DPCT1003:88: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:89: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:90: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::rotm( *cublasH, A.size(), d_A, incx, d_B, incy, const_cast<double *>(param.data())), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()), 0)); /* DPCT1003:91: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * A = | 10.0 16.0 22.0 28.0 | * B = | 39.0 46.0 53.0 60.0 | */ printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ /* DPCT1003:92: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:93: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:94: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:95: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:96: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-1/cublas_copy_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 0.0 0.0 0.0 0.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B(A.size(), 0); const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:36: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1025:37: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:38: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:39: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); /* DPCT1003:40: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:41: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:42: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::copy(*cublasH, A.size(), d_A, incx, d_B, incy), 0)); /* step 4: copy data to host */ /* DPCT1003:43: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()), 0)); /* DPCT1003:44: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * B = | 1.0 2.0 3.0 4.0 | */ printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ /* DPCT1003:45: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:46: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:47: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:48: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_gemmStridedBatched_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; const int batch_count = 2; const long long int strideA = m * k; const long long int strideB = k * n; const long long int strideC = m * n; /* * A = | 1.0 | 2.0 | 5.0 | 6.0 | * | 3.0 | 4.0 | 7.0 | 8.0 | * * B = | 5.0 | 6.0 | 9.0 | 10.0 | * | 7.0 | 8.0 | 11.0 | 12.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0, 5.0, 7.0, 6.0, 8.0}; const std::vector<data_type> B = {5.0, 7.0, 6.0, 8.0, 9.0, 11.0, 10.0, 12.0}; std::vector<data_type> C(m * n * batch_count); const data_type alpha = 1.0; const data_type beta = 0.0; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::transpose transb = oneapi::mkl::transpose::nontrans; printf("A[0]\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("A[1]\n"); print_matrix(m, k, A.data() + (m * k), lda); printf("=====\n"); printf("B[0]\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); printf("B[1]\n"); print_matrix(k, n, B.data() + (k * n), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:58: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:59: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:60: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:61: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); /* DPCT1003:62: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:63: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::gemm_batch( *cublasH, transa, transb, m, n, k, alpha, d_A, lda, strideA, d_B, ldb, strideB, beta, d_C, ldc, strideC, batch_count), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 19.0 | 22.0 | 111.0 | 122.0 | * | 43.0 | 50.0 | 151.0 | 166.0 | */ printf("C[0]\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); printf("C[1]\n"); print_matrix(m, n, C.data() + (m * n), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:64: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:65: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:66: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:67: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:68: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_gemm3m_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::float2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * * B = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | */ const std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> B = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; std::vector<data_type> C(m * n); const data_type alpha = {1.0, 1.0}; const data_type beta = {0.0, 0.0}; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::transpose transb = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:0: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:3: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:4: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:5: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:6: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); /* DPCT1003:7: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); /* DPCT1003:8: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); /* DPCT1003:9: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:10: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:11: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::gemm( *cublasH, transa, transb, m, n, k, std::complex<float>(alpha.x(), alpha.y()), (std::complex<float> *)d_A, lda, (std::complex<float> *)d_B, ldb, std::complex<float>(beta.x(), beta.y()), (std::complex<float> *)d_C, ldc), 0)); /* step 4: copy data to host */ /* DPCT1003:12: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); /* DPCT1003:13: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * C = | -20.14 + 18.50j -28.78 + 26.66j | * | -43.18 + 40.58j -63.34 + 60.26j | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ /* DPCT1003:14: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); /* DPCT1003:15: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:16: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:17: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:18: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:19: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_trmm_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.0 | 2.0 | * | 3.0 | 4.0 | * * B = | 5.0 | 6.0 | * | 7.0 | 8.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; const std::vector<data_type> B = {5.0, 7.0, 6.0, 8.0}; std::vector<data_type> C(m * n); const data_type alpha = 1.0; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::side side = oneapi::mkl::side::left; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:117: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:118: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ CUBLAS_CHECK((dpct::trmm(*cublasH, side, uplo, transa, diag, m, n, &alpha, d_A, lda, d_B, ldb, d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 19.0 | 22.0 | * | 28.0 | 32.0 | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:119: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_syrkx_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.0 | 3.0 | * | 3.0 | 4.0 | * * B = | 5.0 | 7.0 | * | 7.0 | 8.0 | */ const std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> B = {5.0, 7.0, 7.0, 8.0}; std::vector<data_type> C(m * n); const data_type alpha = 1.0; const data_type beta = 0.0; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:114: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:115: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ CUBLAS_CHECK((dpct::syrk(*cublasH, uplo, transa, n, k, &alpha, d_A, lda, d_B, ldb, &beta, d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 26.0 | 31.0 | * | 0.0 | 53.0 | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:116: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_gemmBatched_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; const int batch_count = 2; /* * A = | 1.0 | 2.0 | 5.0 | 6.0 | * | 3.0 | 4.0 | 7.0 | 8.0 | * * B = | 5.0 | 6.0 | 9.0 | 10.0 | * | 7.0 | 8.0 | 11.0 | 12.0 | */ const std::vector<std::vector<data_type>> A_array = {{1.0 ,3.0, 2.0, 4.0}, {5.0, 7.0, 6.0, 8.0}}; const std::vector<std::vector<data_type>> B_array = {{5.0, 7.0, 6.0, 8.0}, {9.0, 11.0, 10.0, 12.0}}; std::vector<std::vector<data_type>> C_array(batch_count, std::vector<data_type>(m * n)); const data_type alpha = 1.0; const data_type beta = 0.0; data_type **d_A_array = nullptr; data_type **d_B_array = nullptr; data_type **d_C_array = nullptr; std::vector<data_type *> d_A(batch_count, nullptr); std::vector<data_type *> d_B(batch_count, nullptr); std::vector<data_type *> d_C(batch_count, nullptr); oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::transpose transb = oneapi::mkl::transpose::nontrans; printf("A[0]\n"); print_matrix(m, k, A_array[0].data(), lda); printf("=====\n"); printf("A[1]\n"); print_matrix(m, k, A_array[1].data(), lda); printf("=====\n"); printf("B[0]\n"); print_matrix(k, n, B_array[0].data(), ldb); printf("=====\n"); printf("B[1]\n"); print_matrix(k, n, B_array[1].data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:20: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:21: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:22: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:23: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ for (int i = 0; i < batch_count; i++) { CUDA_CHECK(((d_A[i]) = (value_type)sycl::malloc_device( sizeof(data_type) * A_array[i].size(), q_ct1), 0)); /* DPCT1003:24: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK(((d_B[i]) = (value_type)sycl::malloc_device( sizeof(data_type) * B_array[i].size(), q_ct1), 0)); /* DPCT1003:25: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK(((d_C[i]) = (value_type)sycl::malloc_device( sizeof(data_type) * C_array[i].size(), q_ct1), 0)); } /* DPCT1003:26: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A_array = (data_type **)sycl::malloc_device( sizeof(data_type *) * batch_count, q_ct1), 0)); /* DPCT1003:27: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_B_array = (data_type **)sycl::malloc_device( sizeof(data_type *) * batch_count, q_ct1), 0)); CUDA_CHECK((d_C_array = (data_type **)sycl::malloc_device( sizeof(data_type *) * batch_count, q_ct1), 0)); for (int i = 0; i < batch_count; i++) { /* DPCT1003:28: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->memcpy(d_A[i], A_array[i].data(), sizeof(data_type) * A_array[i].size()), 0)); CUDA_CHECK((stream->memcpy(d_B[i], B_array[i].data(), sizeof(data_type) * B_array[i].size()), 0)); } /* DPCT1003:29: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->memcpy(d_A_array, d_A.data(), sizeof(data_type *) * batch_count), 0)); /* DPCT1003:30: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->memcpy(d_B_array, d_B.data(), sizeof(data_type *) * batch_count), 0)); /* DPCT1003:31: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->memcpy(d_C_array, d_C.data(), sizeof(data_type *) * batch_count), 0)); /* step 3: compute */ /* DPCT1003:32: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (dpct::gemm_batch( *cublasH, transa, transb, m, n, k, &alpha, (const void **)d_A_array, dpct::library_data_t::real_double, lda, (const void **)d_B_array, dpct::library_data_t::real_double, ldb, &beta, (void **)d_C_array, dpct::library_data_t::real_double, ldc, batch_count, dpct::library_data_t::real_double), 0)); /* step 4: copy data to host */ for (int i = 0; i < batch_count; i++) { /* DPCT1003:33: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->memcpy(C_array[i].data(), d_C[i], sizeof(data_type) * C_array[i].size()), 0)); } /* DPCT1003:34: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * C = | 19.0 | 22.0 | 111.0 | 122.0 | * | 43.0 | 50.0 | 151.0 | 166.0 | */ printf("C[0]\n"); print_matrix(m, n, C_array[0].data(), ldc); printf("=====\n"); printf("C[1]\n"); print_matrix(m, n, C_array[1].data(), ldc); printf("=====\n"); /* free resources */ /* DPCT1003:35: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A_array, q_ct1), 0)); /* DPCT1003:36: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B_array, q_ct1), 0)); /* DPCT1003:37: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_C_array, q_ct1), 0)); for (int i = 0; i < batch_count; i++) { /* DPCT1003:38: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A[i], q_ct1), 0)); /* DPCT1003:39: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B[i], q_ct1), 0)); /* DPCT1003:40: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_C[i], q_ct1), 0)); } /* DPCT1003:41: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:42: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:43: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_her2k_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * * B = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | */ const std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> B = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; std::vector<data_type> C(m * n); const data_type alpha = {1.0, 1.0}; const double beta = 0.0; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:79: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:80: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ CUBLAS_CHECK( (/* DPCT1003:81: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::her2k( *cublasH, uplo, transa, n, k, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_A, lda, (std::complex<double> *)d_B, ldb, beta, (std::complex<double> *)d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 27.40 + 0.00j | 61.00 + 0.96j | * | 0.00 + 0.00j | 140.68 + 0.00j | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:82: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_hemm_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * * B = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | */ const std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> B = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; std::vector<data_type> C(m * n); const data_type alpha = {1.0, 1.0}; const data_type beta = {0.0, 0.0}; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::side side = oneapi::mkl::side::left; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:69: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:70: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:71: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:72: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:73: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ CUBLAS_CHECK( (/* DPCT1003:74: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::hemm( *cublasH, side, uplo, m, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_A, lda, (std::complex<double> *)d_B, ldb, std::complex<double>(beta.x(), beta.y()), (std::complex<double> *)d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); /* DPCT1003:75: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * C = | -17.38 + 18.62j | -23.14 + 26.78j | * | 4.82 + 38.90j | 10.58 + 55.70j | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:76: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:77: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:78: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_trsmBatched_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int batch_count = 2; /* * A = | 1.0 | 2.0 | 5.0 | 6.0 | * | 3.0 | 4.0 | 7.0 | 8.0 | * * B = | 5.0 | 6.0 | 9.0 | 10.0 | * | 7.0 | 8.0 | 11.0 | 12.0 | */ const std::vector<std::vector<data_type>> A_array = {{1.0, 3.0, 2.0, 4.0}, {5.0, 7.0, 6.0, 8.0}}; std::vector<std::vector<data_type>> B_array = {{5.0, 7.0, 6.0, 8.0}, {9.0, 11.0, 10.0, 12.0}}; const data_type alpha = 1.0; data_type **d_A_array = nullptr; data_type **d_B_array = nullptr; std::vector<data_type *> d_A(batch_count, nullptr); std::vector<data_type *> d_B(batch_count, nullptr); oneapi::mkl::side side = oneapi::mkl::side::left; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A[0]\n"); print_matrix(m, k, A_array[0].data(), lda); printf("=====\n"); printf("A[1]\n"); print_matrix(m, k, A_array[1].data(), lda); printf("=====\n"); printf("B[0] (in)\n"); print_matrix(k, n, B_array[0].data(), ldb); printf("=====\n"); printf("B[1] (in)\n"); print_matrix(k, n, B_array[1].data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:120: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1025:121: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:122: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ for (int i = 0; i < batch_count; i++) { CUDA_CHECK(((d_A[i]) = (value_type)sycl::malloc_device( sizeof(data_type) * A_array[i].size(), q_ct1), 0)); CUDA_CHECK(((d_B[i]) = (value_type)sycl::malloc_device( sizeof(data_type) * B_array[i].size(), q_ct1), 0)); } CUDA_CHECK((d_A_array = (data_type **)sycl::malloc_device( sizeof(data_type *) * batch_count, q_ct1), 0)); CUDA_CHECK((d_B_array = (data_type **)sycl::malloc_device( sizeof(data_type *) * batch_count, q_ct1), 0)); for (int i = 0; i < batch_count; i++) { /* DPCT1003:123: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->memcpy(d_A[i], A_array[i].data(), sizeof(data_type) * A_array[i].size()), 0)); /* DPCT1003:124: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->memcpy(d_B[i], B_array[i].data(), sizeof(data_type) * B_array[i].size()), 0)); } CUDA_CHECK((stream->memcpy(d_A_array, d_A.data(), sizeof(data_type *) * batch_count), 0)); CUDA_CHECK((stream->memcpy(d_B_array, d_B.data(), sizeof(data_type *) * batch_count), 0)); /* step 3: compute */ CUBLAS_CHECK( (dpct::trsm_batch(*cublasH, side, uplo, transa, diag, m, n, &alpha, (const void **)d_A_array, dpct::library_data_t::real_double, lda, (void **)d_B_array, dpct::library_data_t::real_double, ldb, batch_count, dpct::library_data_t::real_double), 0)); /* step 4: copy data to host */ for (int i = 0; i < batch_count; i++) { CUDA_CHECK((stream->memcpy(B_array[i].data(), d_B[i], sizeof(data_type) * B_array[i].size()), 0)); } /* DPCT1003:125: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * B = | 1.50 | 2.00 | 0.15 | 0.20 | * | 1.75 | 2.00 | 1.38 | 1.50 | */ printf("B[0] (out)\n"); print_matrix(k, n, B_array[0].data(), ldb); printf("=====\n"); printf("B[1] (out)\n"); print_matrix(k, n, B_array[1].data(), ldb); printf("=====\n"); /* free resources */ /* DPCT1003:126: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A_array, q_ct1), 0)); /* DPCT1003:127: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B_array, q_ct1), 0)); for (int i = 0; i < batch_count; i++) { /* DPCT1003:128: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A[i], q_ct1), 0)); /* DPCT1003:129: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_B[i], q_ct1), 0)); } /* DPCT1003:130: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:131: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:132: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_syrk_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldc = 2; /* * A = | 1.0 | 3.0 | * | 3.0 | 4.0 | */ const std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; std::vector<data_type> C(m * n); const data_type alpha = 1.0; const data_type beta = 0.0; data_type *d_A = nullptr; data_type *d_C = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::trans; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:106: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:107: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:108: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:109: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:110: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); /* DPCT1003:111: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* step 3: compute */ /* DPCT1003:112: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::syrk(*cublasH, uplo, transa, n, k, alpha, d_A, lda, beta, d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 10.0 | 15.0 | * | 0.0 | 25.0 | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:113: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_syr2k_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.0 | 3.0 | * | 3.0 | 4.0 | * * B = | 5.0 | 7.0 | * | 7.0 | 8.0 | */ const std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> B = {5.0, 7.0, 7.0, 8.0}; std::vector<data_type> C(m * n); const data_type alpha = 1.0; const data_type beta = 0.0; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:102: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:103: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ CUBLAS_CHECK((/* DPCT1003:104: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::syr2k( *cublasH, uplo, transa, n, k, alpha, d_A, lda, d_B, ldb, beta, d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 52.0 | 74.0 | * | 0.0 | 106.0 | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:105: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_herkx_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * * B = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | */ const std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> B = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; std::vector<data_type> C(m * n); const data_type alpha = {1.0, 1.0}; const double beta = 0.0; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:94: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:95: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:96: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((dpct::herk(*cublasH, uplo, transa, n, k, &alpha, d_A, lda, d_B, ldb, &beta, d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 13.70 + 0.00j | 30.02 + 30.98j | * | 0.00 + 0.00j | 70.34 + 0.00j | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:97: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_symm_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.0 | 3.0 | * | 3.0 | 4.0 | * * B = | 5.0 | 7.0 | * | 7.0 | 8.0 | */ const std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> B = {5.0, 7.0, 7.0, 8.0}; std::vector<data_type> C(m * n); const data_type alpha = 1.0; const data_type beta = 0.0; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::side side = oneapi::mkl::side::left; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:98: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:99: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ CUBLAS_CHECK((/* DPCT1003:100: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::symm(*cublasH, side, uplo, m, n, alpha, d_A, lda, d_B, ldb, beta, d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 26.0 | 31.0 | * | 43.0 | 53.0 | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:101: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_herk_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" #include <complex> using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldc = 2; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | */ const std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; std::vector<data_type> C(m * n); const double alpha = 1.0; const double beta = 0.0; data_type *d_A = nullptr; data_type *d_C = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:83: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:84: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:85: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:86: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:87: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); /* DPCT1003:88: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); /* DPCT1003:89: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* step 3: compute */ /* DPCT1003:90: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK( (oneapi::mkl::blas::column_major::herk( *cublasH, uplo, transa, n, k, alpha, (std::complex<double> *)d_A, lda, beta, (std::complex<double> *)d_C, ldc), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * C = | 13.70 + 0.00j | 30.50 + 0.48j | * | 0.00 + 0.00j | 70.34 + 0.00j | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:91: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:92: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:93: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_gemm_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.0 | 2.0 | * | 3.0 | 4.0 | * * B = | 5.0 | 6.0 | * | 7.0 | 8.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; std::vector<data_type> C(m * n); const data_type alpha = 1.0; const data_type beta = 0.0; data_type *d_A = nullptr; data_type *d_B = nullptr; data_type *d_C = nullptr; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::transpose transb = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B\n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:44: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:45: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:46: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:47: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:48: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK((d_C = (data_type *)sycl::malloc_device( sizeof(data_type) * C.size(), q_ct1), 0)); /* DPCT1003:49: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); /* DPCT1003:50: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ CUBLAS_CHECK((/* DPCT1003:51: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ oneapi::mkl::blas::column_major::gemm( *cublasH, transa, transb, m, n, k, alpha, d_A, lda, d_B, ldb, beta, d_C, ldc), 0)); /* step 4: copy data to host */ /* DPCT1003:52: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK( (stream->memcpy(C.data(), d_C, sizeof(data_type) * C.size()), 0)); /* DPCT1003:53: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((stream->wait(), 0)); /* * C = | 23.0 | 31.0 | * | 34.0 | 46.0 | */ printf("C\n"); print_matrix(m, n, C.data(), ldc); printf("=====\n"); /* free resources */ /* DPCT1003:54: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); CUDA_CHECK((sycl::free(d_C, q_ct1), 0)); /* DPCT1003:55: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); /* DPCT1003:56: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); /* DPCT1003:57: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/01_sycl_dpct_output/Level-3/cublas_trsm_example.dp.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <sycl/sycl.hpp> #include <dpct/dpct.hpp> #include <cstdio> #include <cstdlib> #include <vector> #include <oneapi/mkl.hpp> #include <dpct/blas_utils.hpp> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 2; const int lda = 2; const int ldb = 2; const int ldc = 2; /* * A = | 1.0 | 2.0 | * | 3.0 | 4.0 | * * B = | 5.0 | 6.0 | * | 7.0 | 8.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> B = {5.0, 7.0, 6.0, 8.0}; const data_type alpha = 1.0; data_type *d_A = nullptr; data_type *d_B = nullptr; oneapi::mkl::side side = oneapi::mkl::side::left; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, k, A.data(), lda); printf("=====\n"); printf("B (in) \n"); print_matrix(k, n, B.data(), ldb); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ /* DPCT1003:133: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = &q_ct1, 0)); /* DPCT1003:134: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ /* DPCT1025:135: The SYCL queue is created ignoring the flag and priority options. */ CUDA_CHECK((stream = dev_ct1.create_queue(), 0)); /* DPCT1003:136: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = stream, 0)); /* step 2: copy data to device */ /* DPCT1003:137: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUDA_CHECK((d_A = (data_type *)sycl::malloc_device( sizeof(data_type) * A.size(), q_ct1), 0)); CUDA_CHECK((d_B = (data_type *)sycl::malloc_device( sizeof(data_type) * B.size(), q_ct1), 0)); CUDA_CHECK( (stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()), 0)); CUDA_CHECK( (stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()), 0)); /* step 3: compute */ /* DPCT1003:138: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((oneapi::mkl::blas::column_major::trsm( *cublasH, side, uplo, transa, diag, m, n, alpha, d_A, lda, d_B, ldb), 0)); /* step 4: copy data to host */ CUDA_CHECK( (stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()), 0)); CUDA_CHECK((stream->wait(), 0)); /* * B = | 1.50 | 2.00 | * | 1.75 | 2.00 | */ printf("B (out)\n"); print_matrix(m, n, B.data(), ldc); printf("=====\n"); /* free resources */ CUDA_CHECK((sycl::free(d_A, q_ct1), 0)); CUDA_CHECK((sycl::free(d_B, q_ct1), 0)); /* DPCT1003:139: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code. */ CUBLAS_CHECK((cublasH = nullptr, 0)); CUDA_CHECK((dev_ct1.destroy_queue(stream), 0)); CUDA_CHECK((dev_ct1.reset(), 0)); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Common/cublas_utils.h
/* * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of NVIDIA CORPORATION nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once #include <cmath> #include <complex> #include <dpct/dpct.hpp> #include <dpct/lib_common_utils.hpp> #include <functional> #include <iostream> #include <random> #include <stdexcept> #include <string> #include <sycl/sycl.hpp> // CUDA API error checking #define CUDA_CHECK(err) \ do { \ int err_ = (err); \ if (err_ != 0) { \ std::printf("CUDA error %d at %s:%d\n", err_, __FILE__, __LINE__); \ throw std::runtime_error("CUDA error"); \ } \ } while (0) // cublas API error checking #define CUBLAS_CHECK(err) \ do { \ int err_ = (err); \ if (err_ != 0) { \ std::printf("cublas error %d at %s:%d\n", err_, __FILE__, __LINE__); \ throw std::runtime_error("cublas error"); \ } \ } while (0) // memory alignment #define ALIGN_TO(A, B) (((A + B - 1) / B) * B) // device memory pitch alignment static const size_t device_alignment = 32; // type traits template <typename T> struct traits; template <> struct traits<float> { // scalar type typedef float T; typedef T S; static constexpr T zero = 0.f; static constexpr dpct::library_data_t cuda_data_type = dpct::library_data_t::real_float; inline static S abs(T val) { return fabs(val); } template <typename RNG> inline static T rand(RNG &gen) { return (S)gen(); } inline static T add(T a, T b) { return a + b; } inline static T mul(T v, double f) { return v * f; } }; template <> struct traits<double> { // scalar type typedef double T; typedef T S; static constexpr T zero = 0.; static constexpr dpct::library_data_t cuda_data_type = dpct::library_data_t::real_double; inline static S abs(T val) { return fabs(val); } template <typename RNG> inline static T rand(RNG &gen) { return (S)gen(); } inline static T add(T a, T b) { return a + b; } inline static T mul(T v, double f) { return v * f; } }; template <> struct traits<sycl::float2> { // scalar type typedef float S; typedef sycl::float2 T; static constexpr T zero = {0.f, 0.f}; static constexpr dpct::library_data_t cuda_data_type = dpct::library_data_t::complex_float; inline static S abs(T val) { return dpct::cabs<float>(val); } template <typename RNG> inline static T rand(RNG &gen) { return sycl::float2((S)gen(), (S)gen()); } inline static T add(T a, T b) { return a + b; } inline static T add(T a, S b) { return a + sycl::float2(b, 0.f); } inline static T mul(T v, double f) { return sycl::float2(v.x() * f, v.y() * f); } }; template <> struct traits<sycl::double2> { // scalar type typedef double S; typedef sycl::double2 T; static constexpr T zero = {0., 0.}; static constexpr dpct::library_data_t cuda_data_type = dpct::library_data_t::complex_double; inline static S abs(T val) { return dpct::cabs<double>(val); } template <typename RNG> inline static T rand(RNG &gen) { return sycl::double2((S)gen(), (S)gen()); } inline static T add(T a, T b) { return a + b; } inline static T add(T a, S b) { return a + sycl::double2(b, 0.); } inline static T mul(T v, double f) { return sycl::double2(v.x() * f, v.y() * f); } }; template <typename T> void print_matrix(const int &m, const int &n, const T *A, const int &lda); template <> void print_matrix(const int &m, const int &n, const float *A, const int &lda) { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { std::printf("%0.2f ", A[j * lda + i]); } std::printf("\n"); } } template <> void print_matrix(const int &m, const int &n, const double *A, const int &lda) { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { std::printf("%0.2f ", A[j * lda + i]); } std::printf("\n"); } } template <> void print_matrix(const int &m, const int &n, const sycl::float2 *A, const int &lda) { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { std::printf("%0.2f + %0.2fj ", A[j * lda + i].x(), A[j * lda + i].y()); } std::printf("\n"); } } template <> void print_matrix(const int &m, const int &n, const sycl::double2 *A, const int &lda) { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { std::printf("%0.2f + %0.2fj ", A[j * lda + i].x(), A[j * lda + i].y()); } std::printf("\n"); } } template <typename T> void print_vector(const int &m, const T *A); template <> void print_vector(const int &m, const float *A) { for (int i = 0; i < m; i++) { std::printf("%0.2f ", A[i]); } std::printf("\n"); } template <> void print_vector(const int &m, const double *A) { for (int i = 0; i < m; i++) { std::printf("%0.2f ", A[i]); } std::printf("\n"); } template <> void print_vector(const int &m, const sycl::float2 *A) { for (int i = 0; i < m; i++) { std::printf("%0.2f + %0.2fj ", A[i].x(), A[i].y()); } std::printf("\n"); } template <> void print_vector(const int &m, const sycl::double2 *A) { for (int i = 0; i < m; i++) { std::printf("%0.2f + %0.2fj ", A[i].x(), A[i].y()); } std::printf("\n"); } template <typename T> void generate_random_matrix(int m, int n, T **A, int *lda) { std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<typename traits<T>::S> dis(-1.0, 1.0); auto rand_gen = std::bind(dis, gen); *lda = n; size_t matrix_mem_size = static_cast<size_t>(*lda * m * sizeof(T)); // suppress gcc 7 size warning if (matrix_mem_size <= PTRDIFF_MAX) *A = (T *)malloc(matrix_mem_size); else throw std::runtime_error("Memory allocation size is too large"); if (*A == NULL) throw std::runtime_error("Unable to allocate host matrix"); // random matrix and accumulate row sums for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { T *A_row = (*A) + *lda * i; A_row[j] = traits<T>::rand(rand_gen); } } } // Makes matrix A of size mxn and leading dimension lda diagonal dominant template <typename T> void make_diag_dominant_matrix(int m, int n, T *A, int lda) { for (int i = 0; i < std::min(m, n); ++i) { T *A_row = A + lda * i; auto row_sum = traits<typename traits<T>::S>::zero; for (int j = 0; j < n; ++j) { row_sum += traits<T>::abs(A_row[j]); } A_row[i] = traits<T>::add(A_row[i], row_sum); } } // Returns cudaDataType value as defined in library_types.h for the string // containing type name dpct::library_data_t get_cuda_library_type(std::string type_string) { if (type_string.compare("CUDA_R_16F") == 0) return dpct::library_data_t::real_half; else if (type_string.compare("CUDA_C_16F") == 0) return dpct::library_data_t::complex_half; else if (type_string.compare("CUDA_R_32F") == 0) return dpct::library_data_t::real_float; else if (type_string.compare("CUDA_C_32F") == 0) return dpct::library_data_t::complex_float; else if (type_string.compare("CUDA_R_64F") == 0) return dpct::library_data_t::real_double; else if (type_string.compare("CUDA_C_64F") == 0) return dpct::library_data_t::complex_double; else if (type_string.compare("CUDA_R_8I") == 0) return dpct::library_data_t::real_int8; else if (type_string.compare("CUDA_C_8I") == 0) return dpct::library_data_t::complex_int8; else if (type_string.compare("CUDA_R_8U") == 0) return dpct::library_data_t::real_uint8; else if (type_string.compare("CUDA_C_8U") == 0) return dpct::library_data_t::complex_uint8; else if (type_string.compare("CUDA_R_32I") == 0) return dpct::library_data_t::real_int32; else if (type_string.compare("CUDA_C_32I") == 0) return dpct::library_data_t::complex_int32; else if (type_string.compare("CUDA_R_32U") == 0) return dpct::library_data_t::real_uint32; else if (type_string.compare("CUDA_C_32U") == 0) return dpct::library_data_t::complex_uint32; else throw std::runtime_error("Unknown CUDA datatype"); }
h
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/spr2.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | * y = | 7.0 8.0 | */ std::vector<data_type> AP = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const std::vector<data_type> y = {7.0, 8.0}; const data_type alpha = 1.0; const int incx = 1; const int incy = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_AP = (data_type *)sycl::malloc_device(sizeof(data_type) * AP.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::spr2(*cublasH, uplo, n, alpha, d_x, incx, d_y, incy, d_AP); /* step 4: copy data to host */ stream->memcpy(AP.data(), d_AP, sizeof(data_type) * AP.size()); stream->wait(); /* * AP = | 71.0 99.0 | * | 85.0 4.0 | */ printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_AP, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/hpr2.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <complex> #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | * y = | 1.1 + 2.2j | 3.3 + 4.4j | */ std::vector<data_type> AP = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; const std::vector<data_type> y = {{1.1, 2.2}, {3.3, 4.4}}; const data_type alpha = {1.0, 1.0}; const int incx = 1; const int incy = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_AP = (data_type *)sycl::malloc_device(sizeof(data_type) * AP.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::hpr2( *cublasH, uplo, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_x, incx, (std::complex<double> *)d_y, incy, (std::complex<double> *)d_AP); /* step 4: copy data to host */ stream->memcpy(AP.data(), d_AP, sizeof(data_type) * AP.size()); stream->wait(); /* * AP = | 48.40 + 0.00j | 133.20 + 0.00j | * | 82.92 + 26.04j | 4.70 + 4.80j | */ printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_AP, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/syr.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const data_type alpha = 1.0; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::syr(*cublasH, uplo, n, alpha, d_x, incx, d_A, lda); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->wait(); /* * A = | 26.0 33.0 | * | 3.0 40.0 | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/tpsv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> AP = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_AP = (data_type *)sycl::malloc_device(sizeof(data_type) * AP.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::tpsv(*cublasH, uplo, transa, diag, n, d_AP, d_x, incx); /* step 4: copy data to host */ stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()); stream->wait(); /* * x = | -4.00 3.00 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ sycl::free(d_AP, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/sbmv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 1; const int lda = m; /* * A = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::sbmv(*cublasH, uplo, n, k, alpha, d_A, lda, d_x, incx, beta, d_y, incy); /* step 4: copy data to host */ stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()); stream->wait(); /* * y = | 33.00 39.00 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/hpr.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <complex> #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ std::vector<data_type> AP = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; const double alpha = 1.0; const int incx = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_AP = (data_type *)sycl::malloc_device(sizeof(data_type) * AP.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::hpr(*cublasH, uplo, n, alpha, (std::complex<double> *)d_x, incx, (std::complex<double> *)d_AP); /* step 4: copy data to host */ stream->memcpy(AP.data(), d_AP, sizeof(data_type) * AP.size()); stream->wait(); /* * AP = | 65.55 + 0.00j | 126.15 + 0.00j | * | 92.81 + 6.02j | 4.70 + 4.80j | */ printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_AP, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/gemv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::gemv(*cublasH, transa, m, n, alpha, d_A, lda, d_x, incx, beta, d_y, incy); /* step 4: copy data to host */ stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()); stream->wait(); /* * y = | 17.00 39.00 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/syr2.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | * y = | 7.0 8.0 | */ std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const std::vector<data_type> y = {7.0, 8.0}; const data_type alpha = 1.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::syr2(*cublasH, uplo, n, alpha, d_x, incx, d_y, incy, d_A, lda); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->wait(); /* * A = | 71.0 85.0 | * | 3.0 100.0 | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/her2.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <complex> #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | * y = | 1.1 + 2.2j | 3.3 + 4.4j | */ std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; const std::vector<data_type> y = {{1.1, 2.2}, {3.3, 4.4}}; const data_type alpha = {1.0, 1.0}; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::her2( *cublasH, uplo, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_x, incx, (std::complex<double> *)d_y, incy, (std::complex<double> *)d_A, lda); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->wait(); /* * A = | 48.40 + 0.00j | 81.72 + 24.84j | * | 3.50 + 3.60j | 135.60 + 0.00j | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/spmv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> AP = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_AP = (data_type *)sycl::malloc_device(sizeof(data_type) * AP.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::spmv(*cublasH, uplo, n, alpha, d_AP, d_x, incx, beta, d_y, incy); /* step 4: copy data to host */ stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()); stream->wait(); /* * y = | 23.00 33.00 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ sycl::free(d_AP, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/tbmv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 1; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::tbmv(*cublasH, uplo, transa, diag, n, k, d_A, lda, d_x, incx); /* step 4: copy data to host */ stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()); stream->wait(); /* * x = | 27.00 24.00 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/spr.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * AP = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ std::vector<data_type> AP = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const data_type alpha = 1.0; const int incx = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_AP = (data_type *)sycl::malloc_device(sizeof(data_type) * AP.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::spr(*cublasH, uplo, n, alpha, d_x, incx, d_AP); /* step 4: copy data to host */ stream->memcpy(AP.data(), d_AP, sizeof(data_type) * AP.size()); stream->wait(); /* * AP = | 26.0 39.0 | * | 33.0 4.0 | */ printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_AP, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/tpmv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> AP = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_AP = (data_type *)sycl::malloc_device(sizeof(data_type) * AP.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::tpmv(*cublasH, uplo, transa, diag, n, d_AP, d_x, incx); /* step 4: copy data to host */ stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()); stream->wait(); /* * x = | 23.00 12.00 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ sycl::free(d_AP, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/her.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <complex> #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ std::vector<data_type> A = {{1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; const double alpha = 1.0; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::her(*cublasH, uplo, n, alpha, (std::complex<double> *)d_x, incx, (std::complex<double> *)d_A, lda); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->wait(); /* * A = | 65.55 + 0.00j | 91.61 + 4.82j | * | 3.50 + 3.60j | 128.55 + 0.00j | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/ger.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | * y = | 7.0 8.0 | */ std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; const std::vector<data_type> y = {7.0, 8.0}; const data_type alpha = 2.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); stream->memcpy(d_y, y.data(), sizeof(data_type) * y.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::ger(*cublasH, m, n, alpha, d_x, incx, d_y, incy, d_A, lda); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->wait(); /* * A = | 71.0 82.0 | * | 87.0 100.0 | */ printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/trsv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::trsv(*cublasH, uplo, transa, diag, n, d_A, lda, d_x, incx); /* step 4: copy data to host */ stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()); stream->wait(); /* * x = | 2.00 1.50 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/hemv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <complex> #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ const std::vector<data_type> A = { {1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; std::vector<data_type> y(m); const data_type alpha = {1.0, 1.0}; const data_type beta = {0.0, 0.0}; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::hemv( *cublasH, uplo, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_A, lda, (std::complex<double> *)d_x, incx, std::complex<double>(beta.x(), beta.y()), (std::complex<double> *)d_y, incy); /* step 4: copy data to host */ stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()); stream->wait(); /* * y = | -41.42 + 45.90j 19.42 + 102.42j | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/gbmv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; const int kl = 0; const int ku = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::gbmv(*cublasH, transa, m, n, kl, ku, alpha, d_A, lda, d_x, incx, beta, d_y, incy); /* step 4: copy data to host */ stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()); stream->wait(); /* * y = | 27.0 24.0 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/hbmv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <complex> #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 1; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ const std::vector<data_type> A = { {1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; std::vector<data_type> y(m); const data_type alpha = {1.0, 1.0}; const data_type beta = {0.0, 0.0}; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::hbmv( *cublasH, uplo, n, k, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_A, lda, (std::complex<double> *)d_x, incx, std::complex<double>(beta.x(), beta.y()), (std::complex<double> *)d_y, incy); /* step 4: copy data to host */ stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()); stream->wait(); /* * y = | -44.06 + 73.02j 19.42 + 102.42j | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/trmv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::trmv(*cublasH, uplo, transa, diag, n, d_A, lda, d_x, incx); /* step 4: copy data to host */ stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()); stream->wait(); /* * x = | 17.00 24.00 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/symv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.0 3.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 3.0, 4.0}; const std::vector<data_type> x = {5.0, 6.0}; std::vector<data_type> y(m, 0); const data_type alpha = 1.0; const data_type beta = 0.0; const int incx = 1; const int incy = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::symv(*cublasH, uplo, n, alpha, d_A, lda, d_x, incx, beta, d_y, incy); /* step 4: copy data to host */ stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()); stream->wait(); /* * y = | 23.00 29.00 | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/tbsv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int k = 1; const int lda = m; /* * A = | 1.0 2.0 | * | 3.0 4.0 | * x = | 5.0 6.0 | */ const std::vector<data_type> A = {1.0, 3.0, 2.0, 4.0}; std::vector<data_type> x = {5.0, 6.0}; const int incx = 1; data_type *d_A = nullptr; data_type *d_x = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; oneapi::mkl::transpose transa = oneapi::mkl::transpose::nontrans; oneapi::mkl::diag diag = oneapi::mkl::diag::nonunit; printf("A\n"); print_matrix(m, n, A.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type *)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::tbsv(*cublasH, uplo, transa, diag, n, k, d_A, lda, d_x, incx); /* step 4: copy data to host */ stream->memcpy(x.data(), d_x, sizeof(data_type) * x.size()); stream->wait(); /* * x = | 0.67 1.50 | */ printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_x, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-2/hpmv.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <complex> #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = sycl::double2; int main(int argc, char *argv[]) try { dpct::device_ext &dev_ct1 = dpct::get_current_device(); sycl::queue &q_ct1 = dev_ct1.default_queue(); sycl::queue *cublasH = NULL; dpct::queue_ptr stream = &q_ct1; const int m = 2; const int n = 2; const int lda = m; /* * A = | 1.1 + 1.2j | 2.3 + 2.4j | * | 3.5 + 3.6j | 4.7 + 4.8j | * x = | 5.1 + 6.2j | 7.3 + 8.4j | */ const std::vector<data_type> AP = { {1.1, 1.2}, {3.5, 3.6}, {2.3, 2.4}, {4.7, 4.8}}; const std::vector<data_type> x = {{5.1, 6.2}, {7.3, 8.4}}; std::vector<data_type> y(m); const data_type alpha = {1.0, 1.0}; const data_type beta = {0.0, 0.0}; const int incx = 1; const int incy = 1; data_type *d_AP = nullptr; data_type *d_x = nullptr; data_type *d_y = nullptr; oneapi::mkl::uplo uplo = oneapi::mkl::uplo::upper; printf("AP\n"); print_matrix(m, n, AP.data(), lda); printf("=====\n"); printf("x\n"); print_vector(x.size(), x.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_AP = (data_type *)sycl::malloc_device(sizeof(data_type) * AP.size(), q_ct1); d_x = (data_type *)sycl::malloc_device(sizeof(data_type) * x.size(), q_ct1); d_y = (data_type *)sycl::malloc_device(sizeof(data_type) * y.size(), q_ct1); stream->memcpy(d_AP, AP.data(), sizeof(data_type) * AP.size()); stream->memcpy(d_x, x.data(), sizeof(data_type) * x.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::hpmv( *cublasH, uplo, n, std::complex<double>(alpha.x(), alpha.y()), (std::complex<double> *)d_AP, (std::complex<double> *)d_x, incx, std::complex<double>(beta.x(), beta.y()), (std::complex<double> *)d_y, incy); /* step 4: copy data to host */ stream->memcpy(y.data(), d_y, sizeof(data_type) * y.size()); stream->wait(); /* * y = | -61.58 + 63.42j 34.30 + 79.62j | */ printf("y\n"); print_vector(y.size(), y.data()); printf("=====\n"); /* free resources */ sycl::free(d_AP, q_ct1); sycl::free(d_x, q_ct1); sycl::free(d_y, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/nrm2.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const int incx = 1; data_type result = 0.0; data_type* d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); /* step 3: compute */ [&]() { double* res_temp_ptr_ct8 = &result; if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { res_temp_ptr_ct8 = sycl::malloc_shared<double>(1, dpct::get_default_queue()); } oneapi::mkl::blas::column_major::nrm2(*cublasH, A.size(), d_A, incx, res_temp_ptr_ct8); if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); result = *res_temp_ptr_ct8; sycl::free(res_temp_ptr_ct8, dpct::get_default_queue()); } return 0; }(); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->wait(); /* * Result = 5.48 */ printf("Result\n"); printf("%0.2f\n", result); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/copy.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 0.0 0.0 0.0 0.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B(A.size(), 0); const int incx = 1; const int incy = 1; data_type* d_A = nullptr; data_type* d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_B = (data_type*)sycl::malloc_device(sizeof(data_type) * B.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::copy(*cublasH, A.size(), d_A, incx, d_B, incy); /* step 4: copy data to host */ stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()); stream->wait(); /* * B = | 1.0 2.0 3.0 4.0 | */ printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_B, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/rot.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; const data_type c = 2.1; const data_type s = 1.2; const int incx = 1; const int incy = 1; data_type* d_A = nullptr; data_type* d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_B = (data_type*)sycl::malloc_device(sizeof(data_type) * B.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::rot(*cublasH, A.size(), d_A, incx, d_B, incy, c, s); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()); stream->wait(); /* * A = | 8.1 11.4 14.7 18.0 | * B = | 9.3 10.2 11.1 12.0 | */ printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_B, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/rotm.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; std::vector<data_type> param = {1.0, 5.0, 6.0, 7.0, 8.0}; // flag = param[0] const int incx = 1; const int incy = 1; data_type* d_A = nullptr; data_type* d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); printf("param\n"); print_vector(param.size(), param.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_B = (data_type*)sycl::malloc_device(sizeof(data_type) * B.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::rotm(*cublasH, A.size(), d_A, incx, d_B, incy, const_cast<double*>(param.data())); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()); stream->wait(); /* * A = | 10.0 16.0 22.0 28.0 | * B = | 39.0 46.0 53.0 60.0 | */ printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_B, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/amin.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const int incx = 1; int result = 0.0; data_type* d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); /* step 3: compute */ int64_t* res_temp_ptr_ct3 = sycl::malloc_shared<int64_t>(1, dpct::get_default_queue()); oneapi::mkl::blas::column_major::iamin(*cublasH, A.size(), d_A, incx, res_temp_ptr_ct3) .wait(); int res_temp_host_ct4 = A[(int)*res_temp_ptr_ct3]; dpct::dpct_memcpy(&result, &res_temp_host_ct4, sizeof(int)); sycl::free(res_temp_ptr_ct3, dpct::get_default_queue()); stream->wait(); /* * result = 1 */ printf("result\n"); std::printf("%d\n", result); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/rotg.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = 2.10 * B = 1.20 */ data_type A = 2.1; data_type B = 1.2; data_type c = 2.1; data_type s = 1.2; printf("A\n"); std::printf("%0.2f\n", A); printf("=====\n"); printf("B\n"); std::printf("%0.2f\n", B); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 3: compute */ [&]() { double* a_ct9 = &A; double* b_ct10 = &B; double* c_ct11 = &c; double* s_ct12 = &s; if (sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::shared) { a_ct9 = sycl::malloc_shared<double>(4, dpct::get_default_queue()); b_ct10 = a_ct9 + 1; c_ct11 = a_ct9 + 2; s_ct12 = a_ct9 + 3; *a_ct9 = A; *b_ct10 = B; *c_ct11 = c; *s_ct12 = s; } oneapi::mkl::blas::column_major::rotg(*cublasH, a_ct9, b_ct10, c_ct11, s_ct12); if (sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&A, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); A = *a_ct9; B = *b_ct10; c = *c_ct11; s = *s_ct12; sycl::free(a_ct9, dpct::get_default_queue()); } return 0; }(); stream->wait(); /* * A = 2.42 * B = 0.50 */ printf("A\n"); std::printf("%0.2f\n", A); printf("=====\n"); printf("B\n"); std::printf("%0.2f\n", B); printf("=====\n"); /* free resources */ cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/asum.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const int incx = 1; data_type result = 0.0; data_type* d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); /* step 3: compute */ [&]() { double* res_temp_ptr_ct5 = &result; if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { res_temp_ptr_ct5 = sycl::malloc_shared<double>(1, dpct::get_default_queue()); } oneapi::mkl::blas::column_major::asum(*cublasH, A.size(), d_A, incx, res_temp_ptr_ct5); if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); result = *res_temp_ptr_ct5; sycl::free(res_temp_ptr_ct5, dpct::get_default_queue()); } return 0; }(); stream->wait(); /* * result = 10.00 */ printf("result\n"); std::printf("%0.2f\n", result); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/scal.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | */ std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const data_type alpha = 2.2; const int incx = 1; data_type* d_A = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::scal(*cublasH, A.size(), alpha, d_A, incx); /* step 4: copy data to host */ stream->memcpy(A.data(), d_A, sizeof(data_type) * A.size()); stream->wait(); /* * A = | 2.2 4.4 6.6 8.8 | */ printf("A (scaled)\n"); print_vector(A.size(), A.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/axpy.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; const data_type alpha = 2.1; const int incx = 1; const int incy = 1; data_type* d_A = nullptr; data_type* d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_B = (data_type*)sycl::malloc_device(sizeof(data_type) * B.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()); /* step 3: compute */ oneapi::mkl::blas::column_major::axpy(*cublasH, A.size(), alpha, d_A, incx, d_B, incy); /* step 4: copy data to host */ stream->memcpy(B.data(), d_B, sizeof(data_type) * B.size()); stream->wait(); /* * B = | 7.10 10.20 13.30 16.40 | */ printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_B, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp
oneAPI-samples
data/projects/oneAPI-samples/Libraries/oneMKL/guided_cuBLAS_examples_SYCL_Migration/02_sycl_dpct_migrated/Level-1/dot.cpp
/* * Copyright 2020 NVIDIA Corporation. All rights reserved. * * NOTICE TO LICENSEE: * * This source code and/or documentation ("Licensed Deliverables") are * subject to NVIDIA intellectual property rights under U.S. and * international Copyright laws. * * These Licensed Deliverables contained herein is PROPRIETARY and * CONFIDENTIAL to NVIDIA and is being provided under the terms and * conditions of a form of NVIDIA software license agreement by and * between NVIDIA and Licensee ("License Agreement") or electronically * accepted by Licensee. Notwithstanding any terms or conditions to * the contrary in the License Agreement, reproduction or disclosure * of the Licensed Deliverables to any third party without the express * written consent of NVIDIA is prohibited. * * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THESE LICENSED DELIVERABLES. * * U.S. Government End Users. These Licensed Deliverables are a * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT * 1995), consisting of "commercial computer software" and "commercial * computer software documentation" as such terms are used in 48 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government * only as a commercial end item. Consistent with 48 C.F.R.12.212 and * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all * U.S. Government End Users acquire the Licensed Deliverables with * only those rights set forth herein. * * Any use of the Licensed Deliverables in individual and commercial * software must include, in the user documentation and internal * comments to the code, the above Disclaimer and U.S. Government End * Users Notice. */ #include <cstdio> #include <cstdlib> #include <dpct/dpct.hpp> #include <dpct/blas_utils.hpp> #include <oneapi/mkl.hpp> #include <sycl/sycl.hpp> #include <vector> #include "cublas_utils.h" using data_type = double; int main(int argc, char* argv[]) try { dpct::device_ext& dev_ct1 = dpct::get_current_device(); sycl::queue& q_ct1 = dev_ct1.default_queue(); sycl::queue* cublasH = NULL; dpct::queue_ptr stream = &q_ct1; /* * A = | 1.0 2.0 3.0 4.0 | * B = | 5.0 6.0 7.0 8.0 | */ const std::vector<data_type> A = {1.0, 2.0, 3.0, 4.0}; const std::vector<data_type> B = {5.0, 6.0, 7.0, 8.0}; const int incx = 1; const int incy = 1; data_type result = 0.0; data_type* d_A = nullptr; data_type* d_B = nullptr; printf("A\n"); print_vector(A.size(), A.data()); printf("=====\n"); printf("B\n"); print_vector(B.size(), B.data()); printf("=====\n"); /* step 1: create cublas handle, bind a stream */ cublasH = &q_ct1; stream = dev_ct1.create_queue(); cublasH = stream; /* step 2: copy data to device */ d_A = (data_type*)sycl::malloc_device(sizeof(data_type) * A.size(), q_ct1); d_B = (data_type*)sycl::malloc_device(sizeof(data_type) * B.size(), q_ct1); stream->memcpy(d_A, A.data(), sizeof(data_type) * A.size()); stream->memcpy(d_B, B.data(), sizeof(data_type) * B.size()); /* step 3: compute */ [&]() { double* res_temp_ptr_ct7 = &result; if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { res_temp_ptr_ct7 = sycl::malloc_shared<double>(1, dpct::get_default_queue()); } oneapi::mkl::blas::column_major::dot(*cublasH, A.size(), d_A, incx, d_B, incy, res_temp_ptr_ct7); if (sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::device && sycl::get_pointer_type(&result, cublasH->get_context()) != sycl::usm::alloc::shared) { cublasH->wait(); result = *res_temp_ptr_ct7; sycl::free(res_temp_ptr_ct7, dpct::get_default_queue()); } return 0; }(); stream->wait(); /* * result = 70.00 */ printf("Result\n"); printf("%0.2f\n", result); printf("=====\n"); /* free resources */ sycl::free(d_A, q_ct1); sycl::free(d_B, q_ct1); cublasH = nullptr; dev_ct1.destroy_queue(stream); dev_ct1.reset(); return EXIT_SUCCESS; } catch (sycl::exception const& exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl; std::exit(1); }
cpp